From 37d45469a5202d10289560e4be8e516217a1579c Mon Sep 17 00:00:00 2001 From: joaqo Date: Fri, 11 Sep 2020 11:55:54 -0300 Subject: [PATCH 1/4] Improve input checking to Video class --- norfair/video.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/norfair/video.py b/norfair/video.py index 50d54c79..a80ad208 100644 --- a/norfair/video.py +++ b/norfair/video.py @@ -37,12 +37,14 @@ def __init__( # Read Input Video if self.input_path is not None: + if "~" in self.input_path: + self._fail(f"[bold red]Error reading file:[/bold red] '{self.input_path}'\n[yellow]Using ~ as abbreviation for your home folder is not supported.[/yellow]") + if not os.path.isfile(self.input_path): + self._fail(f"[bold red]Error:[/bold red] File '{self.input_path}' does not exist.") self.video_capture = cv2.VideoCapture(self.input_path) total_frames = int(self.video_capture.get(cv2.CAP_PROP_FRAME_COUNT)) if total_frames == 0: - fail_msg = "[bold red]Error reading input video file:[/bold red] Make sure file exists and is a video file." - if "~" in self.input_path: - fail_msg += "\n[yellow]Using ~ as abbreviation for your home folder is not supported.[/yellow]" + fail_msg = "[bold red]Error:[/bold red] '{self.input_path}' is not a video file supported by OpenCV." self._fail(fail_msg) description = os.path.basename(self.input_path) else: From 64d792970728d71a490f5deb4ddf60dc68b4270a Mon Sep 17 00:00:00 2001 From: joaqo Date: Fri, 11 Sep 2020 12:12:14 -0300 Subject: [PATCH 2/4] Improve ~ in path handling in Video class --- norfair/video.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/norfair/video.py b/norfair/video.py index a80ad208..bf26e8d7 100644 --- a/norfair/video.py +++ b/norfair/video.py @@ -38,7 +38,7 @@ def __init__( # Read Input Video if self.input_path is not None: if "~" in self.input_path: - self._fail(f"[bold red]Error reading file:[/bold red] '{self.input_path}'\n[yellow]Using ~ as abbreviation for your home folder is not supported.[/yellow]") + self.input_path = os.path.expanduser(self.input_path) if not os.path.isfile(self.input_path): self._fail(f"[bold red]Error:[/bold red] File '{self.input_path}' does not exist.") self.video_capture = cv2.VideoCapture(self.input_path) From 642f052ffbba9a57a2350c6394d5826a003c1f7e Mon Sep 17 00:00:00 2001 From: joaqo Date: Fri, 11 Sep 2020 12:23:01 -0300 Subject: [PATCH 3/4] Improve error message in wrong file type in video --- norfair/video.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/norfair/video.py b/norfair/video.py index bf26e8d7..c4118dd3 100644 --- a/norfair/video.py +++ b/norfair/video.py @@ -44,8 +44,7 @@ def __init__( self.video_capture = cv2.VideoCapture(self.input_path) total_frames = int(self.video_capture.get(cv2.CAP_PROP_FRAME_COUNT)) if total_frames == 0: - fail_msg = "[bold red]Error:[/bold red] '{self.input_path}' is not a video file supported by OpenCV." - self._fail(fail_msg) + self._fail(f"[bold red]Error:[/bold red] '{self.input_path}' does not seem to be a video file supported by OpenCV. If the video file is not the problem, please check that your OpenCV installation is working correctly.") description = os.path.basename(self.input_path) else: self.video_capture = cv2.VideoCapture(self.camera) From de66e8f1ba536049f444b28d1146eefdd22cfe18 Mon Sep 17 00:00:00 2001 From: joaqo Date: Fri, 11 Sep 2020 12:26:37 -0300 Subject: [PATCH 4/4] Version bump to 0.1.7 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a6032aee..81841136 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "norfair" -version = "0.1.6" +version = "0.1.7" description = "Lightweight Python library for real-time 2D object tracking." license = "BSD-3-Clause" authors = ["Tryolabs "]