diff --git a/apps/uvc/main.py b/apps/uvc/main.py index 291183021..4d0e50beb 100644 --- a/apps/uvc/main.py +++ b/apps/uvc/main.py @@ -1,12 +1,16 @@ #!/usr/bin/env python3 -import os import platform import depthai as dai import time +import sys +from depthai_helpers.arg_manager import parseArgs + +args = parseArgs() + if platform.machine() == 'aarch64': - print("This app is temporarily disabled on AARCH64 systems due to an issue with stream preview. We are working on resolving this issue") - raise SystemExit(0) + print("This app is temporarily disabled on AARCH64 systems due to an issue with stream preview. We are working on resolving this issue", file=sys.stderr) + raise SystemExit(1) enable_4k = True # Will downscale 4K -> 1080p @@ -28,8 +32,12 @@ uvc = pipeline.createUVC() cam_rgb.video.link(uvc.input) + # Pipeline defined, now the device is connected to -with dai.Device(pipeline) as device: +with dai.Device(pipeline, usb2Mode=args.usbSpeed == "usb2") as device: + if device.getDeviceInfo().desc.protocol == dai.XLinkProtocol.X_LINK_USB_VSC and device.getUsbSpeed() not in (dai.UsbSpeed.SUPER, dai.UsbSpeed.SUPER_PLUS): + print("This app is temporarily disabled with USB2 connection speed due to known issue. We're working on resolving it. In the meantime, please try again with a USB3 cable/port for the device connection", file=sys.stderr) + raise SystemExit(1) print("\nDevice started, please keep this process running") print("and open an UVC viewer. Example on Linux:") print(" guvcview -d /dev/video0") diff --git a/depthai_helpers/app_manager.py b/depthai_helpers/app_manager.py index 475393f7d..68ec3c90b 100644 --- a/depthai_helpers/app_manager.py +++ b/depthai_helpers/app_manager.py @@ -7,6 +7,11 @@ from pathlib import Path initEnv = os.environ.copy() +if "PYTHONPATH" in initEnv: + initEnv["PYTHONPATH"] += ":" + str(Path(__file__).parent.parent.absolute()) +else: + initEnv["PYTHONPATH"] = str(Path(__file__).parent.parent.absolute()) + def quoted(val): @@ -43,23 +48,31 @@ def createVenv(self, force=False): else: print("Creating venv...") try: - subprocess.check_call(' '.join([quoted(sys.executable), '-m', 'venv', str(self.venvPath)]), shell=True, env=initEnv, cwd=self.appPath) + subprocess.check_call(' '.join([quoted(sys.executable), '-m', 'venv', quoted(str(self.venvPath.absolute()))]), shell=True, env=initEnv, cwd=self.appPath) except: print(f"Error creating a new virtual environment using \"venv\" module! Please try to install \"python3.{sys.version_info[1]}-venv\" again", file=sys.stderr) sys.exit(1) print("Installing requirements...") subprocess.check_call(' '.join([quoted(self.appInterpreter), '-m', 'pip', 'install', '-U', 'pip']), env=initEnv, shell=True, cwd=self.appPath) - subprocess.check_call(' '.join([quoted(self.appInterpreter), '-m', 'pip', 'install', '--prefer-binary', '-r', str(self.appRequirements)]), env=initEnv, shell=True, cwd=self.appPath) + subprocess.check_call(' '.join([quoted(self.appInterpreter), '-m', 'pip', 'install', '--prefer-binary', '-r', quoted(str(self.appRequirements))]), env=initEnv, shell=True, cwd=self.appPath) def runApp(self, shouldRun = lambda: True): if os.name == 'nt': - pro = subprocess.Popen(' '.join([quoted(self.appInterpreter), str(self.appEntrypoint)]), env=initEnv, shell=True, cwd=self.appPath) + pro = subprocess.Popen(' '.join([quoted(self.appInterpreter), quoted(str(self.appEntrypoint))]), env=initEnv, shell=True, cwd=self.appPath) else: - pro = subprocess.Popen(' '.join([quoted(self.appInterpreter), str(self.appEntrypoint)]), env=initEnv, shell=True, cwd=self.appPath, preexec_fn=os.setsid) - while shouldRun(): + pro = subprocess.Popen(' '.join([quoted(self.appInterpreter), quoted(str(self.appEntrypoint))]), env=initEnv, shell=True, cwd=self.appPath, preexec_fn=os.setsid) + while shouldRun() and pro.poll() is None: try: time.sleep(1) except KeyboardInterrupt: break - os.killpg(os.getpgid(pro.pid), signal.SIGTERM) + if pro.poll() is not None: + try: + if os.name == 'nt': + subprocess.call(['taskkill', '/F', '/T', '/PID', str(pro.pid)]) + else: + os.kill(pro.pid, signal.SIGTERM) + except ProcessLookupError: + pass + diff --git a/depthai_helpers/arg_manager.py b/depthai_helpers/arg_manager.py index 19c6e6fb0..d295f0980 100644 --- a/depthai_helpers/arg_manager.py +++ b/depthai_helpers/arg_manager.py @@ -1,13 +1,6 @@ -import os import argparse from pathlib import Path -import cv2 import depthai as dai -try: - import argcomplete -except ImportError: - raise ImportError('\033[1;5;31m argcomplete module not found, run: python3 install_requirements.py \033[0m') -from depthai_sdk.previews import Previews def checkRange(minVal, maxVal): @@ -55,12 +48,16 @@ def orientationCast(arg): openvinoVersions = list(map(lambda name: name.replace("VERSION_", ""), filter(lambda name: name.startswith("VERSION_"), vars(dai.OpenVINO.Version)))) _streamChoices = ("nnInput", "color", "left", "right", "depth", "depthRaw", "disparity", "disparityColor", "rectifiedLeft", "rectifiedRight") -colorMaps = list(map(lambda name: name[len("COLORMAP_"):], filter(lambda name: name.startswith("COLORMAP_"), vars(cv2)))) +try: + import cv2 + colorMaps = list(map(lambda name: name[len("COLORMAP_"):], filter(lambda name: name.startswith("COLORMAP_"), vars(cv2)))) +except: + colorMaps = None projectRoot = Path(__file__).parent.parent def parseArgs(): parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter) - parser.add_argument('-cam', '--camera', choices=[Previews.left.name, Previews.right.name, Previews.color.name], default=Previews.color.name, help="Use one of DepthAI cameras for inference (conflicts with -vid)") + parser.add_argument('-cam', '--camera', choices=["left", "right", "color"], default="color", help="Use one of DepthAI cameras for inference (conflicts with -vid)") parser.add_argument('-vid', '--video', type=str, help="Path to video file (or YouTube link) to be used for inference (conflicts with -cam)") parser.add_argument('-dd', '--disableDepth', action="store_true", help="Disable depth information") parser.add_argument('-dnn', '--disableNeuralNetwork', action="store_true", help="Disable neural network inference") diff --git a/requirements.txt b/requirements.txt index 24774d94c..f1d69376f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ requests==2.26.0 pyrebase4==4.5 -argcomplete==1.12.1 --extra-index-url https://www.piwheels.org/simple opencv-python==4.5.4.58 ; platform_machine != "aarch64" and platform_machine != "armv6l" and platform_machine != "armv7l" and python_version == "3.10" opencv-python==4.5.1.48 ; platform_machine != "aarch64" and platform_machine != "armv6l" and platform_machine != "armv7l" and python_version != "3.10"