From bbcede0b3e9fd849e672b3e2f84c436ff7509522 Mon Sep 17 00:00:00 2001 From: slashtechno <77907286+slashtechno@users.noreply.github.com> Date: Fri, 16 Feb 2024 12:45:31 -0600 Subject: [PATCH] Check if video source is valid --- wyzely_detect/__main__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/wyzely_detect/__main__.py b/wyzely_detect/__main__.py index 89005df..1e9a407 100644 --- a/wyzely_detect/__main__.py +++ b/wyzely_detect/__main__.py @@ -1,7 +1,6 @@ # import face_recognition from pathlib import Path import cv2 -import os from prettytable import PrettyTable @@ -85,7 +84,15 @@ def main(): pretty_table = PrettyTable(field_names=["Source Type", "Resolution"]) for source_type, sources in video_sources.items(): for source in sources: - # TODO: Add check to see if resolution is 0x0, and if it is, print a warning or just fail + if source.get(cv2.CAP_PROP_FRAME_WIDTH) == 0 or source.get(cv2.CAP_PROP_FRAME_HEIGHT) == 0: + message = "Capture for a source failed as resolution is 0x0.\n" + if source_type == "streams": + message += "Check if the stream URL is correct and if the stream is online." + else: + message += "Check if the capture device is connected, working, and not in use by another program." + print(message) + # Maybe use os.exit() instead? + exit(1) pretty_table.add_row( [source_type, f"{source.get(cv2.CAP_PROP_FRAME_WIDTH)}x{source.get(cv2.CAP_PROP_FRAME_HEIGHT)}"] )