Skip to content

Commit

Permalink
Merge pull request #513 from luxonis/gui
Browse files Browse the repository at this point in the history
Introduce QT GUI
  • Loading branch information
VanDavv committed Nov 15, 2021
2 parents ed53b42 + e5df395 commit 92c66ab
Show file tree
Hide file tree
Showing 23 changed files with 3,035 additions and 420 deletions.
1,090 changes: 738 additions & 352 deletions depthai_demo.py

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions depthai_helpers/arg_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,18 @@ def parseArgs():
"Example: -enc color right,10 left,10")
parser.add_argument('-encout', '--encodeOutput', type=Path, default=projectRoot, help="Path to directory where to store encoded files. Default: %(default)s")
parser.add_argument('-xls', '--xlinkChunkSize', type=int, help="Specify XLink chunk size")
parser.add_argument('-poeq', '--poeQuality', type=checkRange(1, 100), default=100, help="Specify PoE encoding video quality (1-100)")
parser.add_argument('-camo', '--cameraOrientation', type=_comaSeparated(default="AUTO", cast=orientationCast), nargs="+", default=[],
help=("Define cameras orientation (available: {}) \n"
"Format: camera_name,camera_orientation \n"
"Example: -camo color,ROTATE_180_DEG right,ROTATE_180_DEG left,ROTATE_180_DEG").format(', '.join(orientationChoices))
)
parser.add_argument("--cameraControlls", action="store_true", help="Show camera configuration options in GUI and control them using keyboard")
parser.add_argument("--cameraExposure", type=int, help="Specify camera saturation")
parser.add_argument("--cameraSensitivity", type=int, help="Specify camera sensitivity")
parser.add_argument("--cameraSaturation", type=checkRange(-10, 10), help="Specify image saturation")
parser.add_argument("--cameraContrast", type=checkRange(-10, 10), help="Specify image contrast")
parser.add_argument("--cameraBrightness", type=checkRange(-10, 10), help="Specify image brightness")
parser.add_argument("--cameraSharpness", type=checkRange(0, 4), help="Specify image sharpness")

parser.add_argument("--cameraExposure", type=_comaSeparated("all", int), nargs="+", help="Specify camera saturation")
parser.add_argument("--cameraSensitivity", type=_comaSeparated("all", int), nargs="+", help="Specify camera sensitivity")
parser.add_argument("--cameraSaturation", type=_comaSeparated("all", int), nargs="+", help="Specify image saturation")
parser.add_argument("--cameraContrast", type=_comaSeparated("all", int), nargs="+", help="Specify image contrast")
parser.add_argument("--cameraBrightness", type=_comaSeparated("all", int), nargs="+", help="Specify image brightness")
parser.add_argument("--cameraSharpness", type=_comaSeparated("all", int), nargs="+", help="Specify image sharpness")
parser.add_argument('--skipVersionCheck', action="store_true", help="Disable libraries version check")
return parser.parse_args()
43 changes: 27 additions & 16 deletions depthai_helpers/config_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
import cv2
import depthai as dai
import numpy as np

from depthai_helpers.cli_utils import cliPrint, PrintColors
from depthai_sdk.previews import Previews
Expand Down Expand Up @@ -84,8 +85,19 @@ def getModelDir(self):
if self.args.cnnModel is not None and (DEPTHAI_ZOO / self.args.cnnModel).exists():
return DEPTHAI_ZOO / self.args.cnnModel

def getAvailableZooModels(self):
def verify(path: Path):
return path.parent.name == path.stem

def convert(path: Path):
return path.stem

return list(map(convert, filter(verify, DEPTHAI_ZOO.rglob("**/*.json"))))

def getColorMap(self):
return getattr(cv2, "COLORMAP_{}".format(self.args.colorMap))
cvColorMap = cv2.applyColorMap(np.arange(256, dtype=np.uint8), getattr(cv2, "COLORMAP_{}".format(self.args.colorMap)))
cvColorMap[0] = [0, 0, 0]
return cvColorMap

def getRgbResolution(self):
if self.args.rgbResolution == 2160:
Expand All @@ -104,8 +116,6 @@ def getMonoResolution(self):
return dai.MonoCameraProperties.SensorResolution.THE_400_P

def getMedianFilter(self):
if self.args.subpixel:
return dai.MedianFilter.MEDIAN_OFF
if self.args.stereoMedianSize == 3:
return dai.MedianFilter.KERNEL_3x3
elif self.args.stereoMedianSize == 5:
Expand All @@ -127,22 +137,22 @@ def adjustPreviewToOptions(self):
if len(self.args.show) != 0:
return

if self.args.camera == "color" and Previews.color.name not in self.args.show:
self.args.show.append(Previews.color.name)
self.args.show.append(Previews.color.name)
if self.useNN:
self.args.show.append(Previews.nnInput.name)

if self.useDepth:
if self.lowBandwidth and Previews.disparityColor.name not in self.args.show:
if self.lowBandwidth:
self.args.show.append(Previews.disparity.name)
self.args.show.append(Previews.disparityColor.name)
elif not self.lowBandwidth and Previews.depth.name not in self.args.show:
else:
self.args.show.append(Previews.depth.name)
if self.args.camera == "left" and Previews.rectifiedLeft.name not in self.args.show:
self.args.show.append(Previews.rectifiedLeft.name)
if self.args.camera == "right" and Previews.rectifiedRight.name not in self.args.show:
self.args.show.append(Previews.rectifiedRight.name)
self.args.show.append(Previews.depthRaw.name)
self.args.show.append(Previews.rectifiedLeft.name)
self.args.show.append(Previews.rectifiedRight.name)
else:
if self.args.camera == "left" and Previews.left.name not in self.args.show:
self.args.show.append(Previews.left.name)
if self.args.camera == "right" and Previews.right.name not in self.args.show:
self.args.show.append(Previews.right.name)
self.args.show.append(Previews.left.name)
self.args.show.append(Previews.right.name)

def adjustParamsToDevice(self, device):
deviceInfo = device.getDeviceInfo()
Expand Down Expand Up @@ -174,13 +184,14 @@ def adjustParamsToDevice(self, device):
if deviceInfo.desc.protocol != dai.XLinkProtocol.X_LINK_USB_VSC:
print("Enabling low-bandwidth mode due to connection mode... (protocol: {})".format(deviceInfo.desc.protocol))
self.args.bandwidth = "low"
print("Setting PoE video quality to 50 to reduce latency...")
self.args.poeQuality = 50
elif device.getUsbSpeed() not in [dai.UsbSpeed.SUPER, dai.UsbSpeed.SUPER_PLUS]:
print("Enabling low-bandwidth mode due to low USB speed... (speed: {})".format(device.getUsbSpeed()))
self.args.bandwidth = "low"
else:
self.args.bandwidth = "high"


def linuxCheckApplyUsbRules(self):
if platform.system() == 'Linux':
ret = subprocess.call(['grep', '-irn', 'ATTRS{idVendor}=="03e7"', '/etc/udev/rules.d'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
Expand Down
2 changes: 1 addition & 1 deletion depthai_helpers/version_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def getVersion(module_name):
def checkRequirementsVersion():
daiVersionRequired = getVersionFromRequirements('depthai', Path(__file__).parent / Path('../requirements.txt'))
if daiVersionRequired is not None:
if depthai.__version__.endswith('+dev'):
if "dev" in depthai.__version__:
print('Depthai development version found, skipping check.')
elif daiVersionRequired != getVersion('depthai'):
raise SystemExit(f"\033[1;5;31mVersion mismatch\033[0m\033[91m between installed depthai lib and the required one by the script.\033[0m \n\
Expand Down
3 changes: 3 additions & 0 deletions depthai_sdk/src/depthai_sdk/managers/encoding_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ def printManual():
for name, file in self._encodingFiles.items():
print(cmd.format(self._encodingNodes[name].getFrameRate(), file.name, str(Path(file.name).with_suffix('.mp4'))))

for queue in self._encodingQueues.values():
queue.close()

for name, file in self._encodingFiles.items():
file.close()
try:
Expand Down
10 changes: 10 additions & 0 deletions depthai_sdk/src/depthai_sdk/managers/nnet_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def createNN(self, pipeline, nodes, blobPath, source="color", flipDetection=Fals
nodes.camRgb.preview.link(nodes.nn.input)
elif self.source == "host":
nodes.xinNn = pipeline.createXLinkIn()
self.nodes.xinRgbControl.setMaxDataSize(self.inputSize[0] * self.inputSize[1] * 3)
nodes.xinNn.setStreamName("nnIn")
nodes.xinNn.out.link(nodes.nn.input)
elif self.source in ("left", "right", "rectifiedLeft", "rectifiedRight"):
Expand Down Expand Up @@ -341,6 +342,15 @@ def createQueues(self, device):
self.inputQueue = device.getInputQueue("nnIn", maxSize=1, blocking=False)
self.outputQueue = device.getOutputQueue("nnOut", maxSize=1, blocking=False)

def closeQueues(self):
"""
Closes output queues created by :func:`createQueues`
"""
if self.source == "host" and self.inputQueue is not None:
self.inputQueue.close()
if self.outputQueue is not None:
self.outputQueue.close()

def sendInputFrame(self, frame, seqNum=None):
"""
Sends a frame into :attr:`inputQueue` object. Handles scaling down the frame, creating a proper :obj:`depthai.ImgFrame`
Expand Down
Loading

0 comments on commit 92c66ab

Please sign in to comment.