Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable CLI params in apps, tweak app setup and termination and disable UVC app with USB2 connections #618

Merged
merged 9 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions apps/uvc/main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/usr/bin/env python3
import os
import platform
import depthai as dai
import time
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")
Expand All @@ -28,8 +31,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")
VanDavv marked this conversation as resolved.
Show resolved Hide resolved
raise SystemExit(0)
VanDavv marked this conversation as resolved.
Show resolved Hide resolved
print("\nDevice started, please keep this process running")
print("and open an UVC viewer. Example on Linux:")
print(" guvcview -d /dev/video0")
Expand Down
21 changes: 15 additions & 6 deletions depthai_helpers/app_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -43,23 +48,27 @@ 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:
if os.name == 'nt':
subprocess.call(['taskkill', '/F', '/T', '/PID', str(pro.pid)])
else:
os.kill(pro.pid, signal.SIGTERM)

15 changes: 6 additions & 9 deletions depthai_helpers/arg_manager.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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"
Expand Down