From 3d289c430845e4e351e580c8c6cdac5d319efd02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pi=C5=82atowski?= Date: Thu, 25 Mar 2021 19:26:10 +0100 Subject: [PATCH 1/8] update 08 example demo --- docs/source/samples/08_rgb_mobilenet.rst | 4 ++-- examples/README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/samples/08_rgb_mobilenet.rst b/docs/source/samples/08_rgb_mobilenet.rst index 6f2f924be..4292f638d 100644 --- a/docs/source/samples/08_rgb_mobilenet.rst +++ b/docs/source/samples/08_rgb_mobilenet.rst @@ -10,7 +10,7 @@ Demo .. raw:: html
- +
Setup @@ -18,7 +18,7 @@ Setup .. include:: /includes/install_from_pypi.rst -This example also requires MobilenetSDD blob (:code:`mobilenet.blob` file) to work - you can download it from +This example also requires MobilenetSDD blob (:code:`mobilenet-ssd_openvino_2021.2_6shave.blob` file) to work - you can download it from `here `__ Source code diff --git a/examples/README.md b/examples/README.md index bb290d34b..ab5d2164c 100644 --- a/examples/README.md +++ b/examples/README.md @@ -57,7 +57,7 @@ TEST_TIMEOUT=0 ctest -R "01_rgb_preview" --verbose ![example_7](https://user-images.githubusercontent.com/5244214/104040905-86209480-51d8-11eb-9e15-5fe94aba7b69.gif) ### 08_rgb_mobilenet.py -![example_8](https://user-images.githubusercontent.com/5244214/104040901-84ef6780-51d8-11eb-96e7-f54fa7853f1f.gif) +![example_8](https://user-images.githubusercontent.com/5244214/112524084-b58a7a80-8d9f-11eb-9389-e17b0ea40338.gif) ### 09_mono_mobilenet.py ![example_9](https://user-images.githubusercontent.com/5244214/104040898-8456d100-51d8-11eb-9498-e316b71d41e6.gif) From 749a2d1ff7968e92543302e9c7dbadfc0a362717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pi=C5=82atowski?= Date: Thu, 25 Mar 2021 21:24:04 +0100 Subject: [PATCH 2/8] Fix scaling issue --- examples/03_depth_preview.py | 6 +- examples/10_mono_depth_mobilenetssd.py | 37 ++++++- examples/11_rgb_encoding_mono_mobilenet.py | 27 +++-- .../12_rgb_encoding_mono_mobilenet_depth.py | 101 ++++++++++-------- examples/15_rgb_mobilenet_4k.py | 31 +++--- 5 files changed, 126 insertions(+), 76 deletions(-) diff --git a/examples/03_depth_preview.py b/examples/03_depth_preview.py index 59c064ff2..517761753 100755 --- a/examples/03_depth_preview.py +++ b/examples/03_depth_preview.py @@ -41,10 +41,8 @@ while True: inDepth = q.get() # blocking call, will wait until a new data has arrived - # data is originally represented as a flat 1D array, it needs to be converted into HxW form - frame = inDepth.getData().reshape((inDepth.getHeight(), inDepth.getWidth())).astype(np.uint8) - frame = np.ascontiguousarray(frame) - # frame is transformed, the color map will be applied to highlight the depth info + frame = inDepth.getFrame() + frame = cv2.normalize(frame, None, 0, 255, cv2.NORM_MINMAX) frame = cv2.applyColorMap(frame, cv2.COLORMAP_JET) # Uncomment one of these and comment the one given above diff --git a/examples/10_mono_depth_mobilenetssd.py b/examples/10_mono_depth_mobilenetssd.py index d9afbc355..a27e11adc 100755 --- a/examples/10_mono_depth_mobilenetssd.py +++ b/examples/10_mono_depth_mobilenetssd.py @@ -53,7 +53,7 @@ depthOut = pipeline.createXLinkOut() depthOut.setStreamName("depth") -stereo.depth.link(depthOut.input) +stereo.disparity.link(depthOut.input) xoutRight = pipeline.createXLinkOut() xoutRight.setStreamName("rectifiedRight") @@ -109,10 +109,37 @@ def displayFrame(name, frame): detections = inDet.detections if inDepth is not None: - depthFrame = inDepth.getFrame() - depthFrame = cv2.normalize(depthFrame, None, 255, 0, cv2.NORM_INF, cv2.CV_8UC1) - depthFrame = cv2.equalizeHist(depthFrame) - depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_HOT) + # depthFrame = inDepth.getFrame() + # data is originally represented as a flat 1D array, it needs to be converted into HxW form + depthFrame = inDepth.getData().reshape((inDepth.getHeight(), inDepth.getWidth())).astype(np.uint8) + depthFrame = np.ascontiguousarray(depthFrame) + # frame is transformed, the color map will be applied to highlight the depth info + depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_JET) + + # Uncomment one of these and comment the one given above + # to see visualisation in different color frames + + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_BONE) + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_AUTUMN) + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_WINTER) + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_RAINBOW) + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_OCEAN) + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_SUMMER) + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_SPRING) + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_COOL) + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_HSV) + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_HOT) + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_PINK) + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_PARULA) + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_MAGMA) + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_INFERNO) + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_PLASMA) + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_VIRIDIS) + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_CIVIDIS) + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_TWILIGHT) + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_TWILIGHT_SHIFTED) + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_TURBO) + # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_DEEPGREEN) if rightFrame is not None: displayFrame("rectified right", rightFrame) diff --git a/examples/11_rgb_encoding_mono_mobilenet.py b/examples/11_rgb_encoding_mono_mobilenet.py index aa2d091a1..bdd042998 100755 --- a/examples/11_rgb_encoding_mono_mobilenet.py +++ b/examples/11_rgb_encoding_mono_mobilenet.py @@ -74,21 +74,16 @@ frame = None frameManip = None detections = [] + offset_x = (camRight.getResolutionWidth() - camRight.getResolutionHeight()) // 2 def frameNorm(frame, bbox): normVals = np.full(len(bbox), frame.shape[0]) normVals[::2] = frame.shape[1] return (np.clip(np.array(bbox), 0, 1) * normVals).astype(int) - def displayFrame(name, frame): - for detection in detections: - bbox = frameNorm(frame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) - cv2.rectangle(frame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (255, 0, 0), 2) - cv2.putText(frame, labelMap[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) - cv2.putText(frame, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) - cv2.imshow(name, frame) - videoFile = open('video.h265', 'wb') + cv2.namedWindow("right", cv2.WINDOW_NORMAL) + cv2.namedWindow("manip", cv2.WINDOW_NORMAL) while True: inRight = qRight.tryGet() @@ -108,10 +103,22 @@ def displayFrame(name, frame): detections = inDet.detections if frame is not None: - displayFrame("right", frame) + cropped_frame = np.zeros((camRight.getResolutionHeight(), camRight.getResolutionHeight())) + for detection in detections: + bbox = frameNorm(cropped_frame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) + bbox[::2] += offset_x + cv2.rectangle(frame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (255, 0, 0), 2) + cv2.putText(frame, labelMap[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) + cv2.putText(frame, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) + cv2.imshow("right", frame) if frameManip is not None: - displayFrame("manip", frameManip) + for detection in detections: + bbox = frameNorm(frameManip, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) + cv2.rectangle(frameManip, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (255, 0, 0), 2) + cv2.putText(frameManip, labelMap[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) + cv2.putText(frameManip, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) + cv2.imshow("manip", frameManip) if cv2.waitKey(1) == ord('q'): break diff --git a/examples/12_rgb_encoding_mono_mobilenet_depth.py b/examples/12_rgb_encoding_mono_mobilenet_depth.py index 9272ceefa..4252252a6 100755 --- a/examples/12_rgb_encoding_mono_mobilenet_depth.py +++ b/examples/12_rgb_encoding_mono_mobilenet_depth.py @@ -6,12 +6,12 @@ import depthai as dai import numpy as np - # Get argument first nnPath = str((Path(__file__).parent / Path('models/mobilenet-ssd_openvino_2021.2_6shave.blob')).resolve().absolute()) if len(sys.argv) > 1: nnPath = sys.argv[1] + pipeline = dai.Pipeline() cam = pipeline.createColorCamera() @@ -25,22 +25,25 @@ videoOut = pipeline.createXLinkOut() videoOut.setStreamName('h265') videoEncoder.bitstream.link(videoOut.input) +camLeft = pipeline.createMonoCamera() +camLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P) +camLeft.setBoardSocket(dai.CameraBoardSocket.LEFT) -left = pipeline.createMonoCamera() -left.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P) -left.setBoardSocket(dai.CameraBoardSocket.LEFT) - -right = pipeline.createMonoCamera() -right.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P) -right.setBoardSocket(dai.CameraBoardSocket.RIGHT) +camRight = pipeline.createMonoCamera() +camRight.setBoardSocket(dai.CameraBoardSocket.RIGHT) +camRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P) depth = pipeline.createStereoDepth() depth.setConfidenceThreshold(200) # Note: the rectified streams are horizontally mirrored by default depth.setOutputRectified(True) depth.setRectifyEdgeFillColor(0) # Black, to better see the cutout -left.out.link(depth.left) -right.out.link(depth.right) +camLeft.out.link(depth.left) +camRight.out.link(depth.right) + +depthOut = pipeline.createXLinkOut() +depthOut.setStreamName("depth") +depth.disparity.link(depthOut.input) nn = pipeline.createMobileNetDetectionNetwork() nn.setConfidenceThreshold(0.5) @@ -48,14 +51,6 @@ nn.setNumInferenceThreads(2) nn.input.setBlocking(False) -depthOut = pipeline.createXLinkOut() -depthOut.setStreamName("depth") -depth.disparity.link(depthOut.input) - -xoutRight = pipeline.createXLinkOut() -xoutRight.setStreamName("rectRight") -depth.rectifiedRight.link(xoutRight.input) - manip = pipeline.createImageManip() manip.initialConfig.setResize(300, 300) # The NN model expects BGR input. By default ImageManip output type would be same as input (gray in this case) @@ -63,6 +58,10 @@ depth.rectifiedRight.link(manip.inputImage) manip.out.link(nn.input) +xoutRight = pipeline.createXLinkOut() +xoutRight.setStreamName("right") +camRight.out.link(xoutRight.input) + manipOut = pipeline.createXLinkOut() manipOut.setStreamName("manip") manip.out.link(manipOut.input) @@ -81,32 +80,29 @@ # Start pipeline device.startPipeline() - qRight = device.getOutputQueue(name="rectRight", maxSize=8, blocking=False) - qManip = device.getOutputQueue(name="manip", maxSize=8, blocking=False) - qDepth = device.getOutputQueue(name="depth", maxSize=8, blocking=False) - qDet = device.getOutputQueue(name="nn", maxSize=8, blocking=False) - qRgbEnc = device.getOutputQueue(name="h265", maxSize=30, blocking=True) + queue_size = 8 + qRight = device.getOutputQueue("right", queue_size) + qDepth = device.getOutputQueue("depth", queue_size) + qManip = device.getOutputQueue("manip", queue_size) + qDet = device.getOutputQueue("nn", queue_size) + qRgbEnc = device.getOutputQueue('h265', maxSize=30, blocking=True) - frameRight = None + frame = None frameManip = None frameDepth = None detections = [] - + offset_x = (camRight.getResolutionWidth() - camRight.getResolutionHeight()) // 2 + cropped_frame = np.zeros((camRight.getResolutionHeight(), camRight.getResolutionHeight())) def frameNorm(frame, bbox): normVals = np.full(len(bbox), frame.shape[0]) normVals[::2] = frame.shape[1] return (np.clip(np.array(bbox), 0, 1) * normVals).astype(int) - def displayFrame(name, frame): - for detection in detections: - bbox = frameNorm(frame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) - cv2.rectangle(frame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (255, 0, 0), 2) - cv2.putText(frame, labelMap[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) - cv2.putText(frame, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) - cv2.imshow(name, frame) - videoFile = open('video.h265', 'wb') + cv2.namedWindow("right", cv2.WINDOW_NORMAL) + cv2.namedWindow("manip", cv2.WINDOW_NORMAL) + cv2.namedWindow("depth", cv2.WINDOW_NORMAL) while True: inRight = qRight.tryGet() @@ -118,27 +114,44 @@ def displayFrame(name, frame): qRgbEnc.get().getData().tofile(videoFile) if inRight is not None: - frameRight = inRight.getCvFrame() + frame = cv2.flip(inRight.getCvFrame(), 1) if inManip is not None: frameManip = inManip.getCvFrame() - if inDet is not None: - detections = inDet.detections - if inDepth is not None: - frameDepth = inDepth.getData().reshape((inDepth.getHeight(), inDepth.getWidth())).astype(np.uint8) - frameDepth = np.ascontiguousarray(frameDepth) + frameDepth = cv2.flip(inDepth.getFrame(), 1) + frameDepth = cv2.normalize(frameDepth, None, 0, 255, cv2.NORM_MINMAX) frameDepth = cv2.applyColorMap(frameDepth, cv2.COLORMAP_JET) - if frameRight is not None: - displayFrame("rectifRight", frameRight) + if inDet is not None: + detections = inDet.detections - if frameManip is not None: - displayFrame("manip", frameManip) + if frame is not None: + for detection in detections: + bbox = frameNorm(cropped_frame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) + bbox[::2] += offset_x + cv2.rectangle(frame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (255, 0, 0), 2) + cv2.putText(frame, labelMap[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) + cv2.putText(frame, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) + cv2.imshow("right", frame) if frameDepth is not None: - displayFrame("depth", frameDepth) + for detection in detections: + bbox = frameNorm(cropped_frame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) + bbox[::2] += offset_x + cv2.rectangle(frameDepth, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (255, 0, 0), 2) + cv2.putText(frameDepth, labelMap[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) + cv2.putText(frameDepth, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) + cv2.imshow("depth", frameDepth) + + if frameManip is not None: + for detection in detections: + bbox = frameNorm(frameManip, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) + cv2.rectangle(frameManip, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (255, 0, 0), 2) + cv2.putText(frameManip, labelMap[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) + cv2.putText(frameManip, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) + cv2.imshow("manip", frameManip) if cv2.waitKey(1) == ord('q'): break diff --git a/examples/15_rgb_mobilenet_4k.py b/examples/15_rgb_mobilenet_4k.py index 4459339db..dab41ad34 100755 --- a/examples/15_rgb_mobilenet_4k.py +++ b/examples/15_rgb_mobilenet_4k.py @@ -52,9 +52,9 @@ device.startPipeline() # Output queues will be used to get the frames and nn data from the outputs defined above - qVideo = device.getOutputQueue(name="video", maxSize=4, blocking=False) - qPreview = device.getOutputQueue(name="preview", maxSize=4, blocking=False) - qDet = device.getOutputQueue(name="nn", maxSize=4, blocking=False) + qVideo = device.getOutputQueue(name="video", maxSize=1, blocking=False) + qPreview = device.getOutputQueue(name="preview", maxSize=1, blocking=False) + qDet = device.getOutputQueue(name="nn", maxSize=1, blocking=False) previewFrame = None videoFrame = None @@ -66,14 +66,8 @@ def frameNorm(frame, bbox): normVals[::2] = frame.shape[1] return (np.clip(np.array(bbox), 0, 1) * normVals).astype(int) - def displayFrame(name, frame): - for detection in detections: - bbox = frameNorm(frame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) - cv2.rectangle(frame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (255, 0, 0), 2) - cv2.putText(frame, labelMap[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) - cv2.putText(frame, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) - cv2.imshow(name, frame) - + offset_x = (camRgb.getResolutionWidth() - camRgb.getResolutionHeight()) // 2 + cropped_frame = np.zeros((camRgb.getResolutionHeight(), camRgb.getResolutionHeight())) cv2.namedWindow("video", cv2.WINDOW_NORMAL) cv2.resizeWindow("video", 1280, 720) print("Resize video window with mouse drag!") @@ -94,10 +88,21 @@ def displayFrame(name, frame): detections = inDet.detections if videoFrame is not None: - displayFrame("video", videoFrame) + for detection in detections: + bbox = frameNorm(cropped_frame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) + bbox[::2] += offset_x + cv2.rectangle(videoFrame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (255, 0, 0), 2) + cv2.putText(videoFrame, labelMap[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) + cv2.putText(videoFrame, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) + cv2.imshow("video", videoFrame) if previewFrame is not None: - displayFrame("preview", previewFrame) + for detection in detections: + bbox = frameNorm(previewFrame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) + cv2.rectangle(previewFrame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (255, 0, 0), 2) + cv2.putText(previewFrame, labelMap[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) + cv2.putText(previewFrame, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) + cv2.imshow("preview", previewFrame) if cv2.waitKey(1) == ord('q'): break From ce6429184943ef18a3ec1386812fcb5dba095c51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pi=C5=82atowski?= Date: Fri, 26 Mar 2021 11:19:06 +0100 Subject: [PATCH 3/8] Review updates --- examples/10_mono_depth_mobilenetssd.py | 34 +++++++++---------- examples/11_rgb_encoding_mono_mobilenet.py | 8 ++--- .../12_rgb_encoding_mono_mobilenet_depth.py | 12 +++---- examples/15_rgb_mobilenet_4k.py | 31 +++++++---------- examples/28_camera_video_example.py | 2 ++ 5 files changed, 42 insertions(+), 45 deletions(-) diff --git a/examples/10_mono_depth_mobilenetssd.py b/examples/10_mono_depth_mobilenetssd.py index a27e11adc..eac21f9fb 100755 --- a/examples/10_mono_depth_mobilenetssd.py +++ b/examples/10_mono_depth_mobilenetssd.py @@ -26,8 +26,7 @@ # Create a node that will produce the depth map (using disparity output as it's easier to visualize depth this way) stereo = pipeline.createStereoDepth() -stereo.setOutputRectified(True) # The rectified streams are horizontally mirrored by default -stereo.setOutputDepth(True) +stereo.setOutputRectified(True) # The rectified streams are horizontally mirrored by default stereo.setConfidenceThreshold(255) stereo.setRectifyEdgeFillColor(0) # Black, to better see the cutout from rectification (black stripe on the edges) @@ -80,6 +79,8 @@ rightFrame = None depthFrame = None detections = [] + offsetX = (right.getResolutionWidth() - right.getResolutionHeight()) // 2 + croppedFrame = np.zeros((right.getResolutionHeight(), right.getResolutionHeight())) # nn data, being the bounding box locations, are in <0..1> range - they need to be normalized with frame width/height def frameNorm(frame, bbox): @@ -87,15 +88,6 @@ def frameNorm(frame, bbox): normVals[::2] = frame.shape[1] return (np.clip(np.array(bbox), 0, 1) * normVals).astype(int) - def displayFrame(name, frame): - for detection in detections: - bbox = frameNorm(frame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) - cv2.rectangle(frame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (255, 0, 0), 2) - cv2.putText(frame, labelMap[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) - cv2.putText(frame, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) - cv2.imshow(name, frame) - - while True: # instead of get (blocking) used tryGet (nonblocking) which will return the available data or None otherwise inRight = qRight.tryGet() @@ -109,10 +101,7 @@ def displayFrame(name, frame): detections = inDet.detections if inDepth is not None: - # depthFrame = inDepth.getFrame() - # data is originally represented as a flat 1D array, it needs to be converted into HxW form - depthFrame = inDepth.getData().reshape((inDepth.getHeight(), inDepth.getWidth())).astype(np.uint8) - depthFrame = np.ascontiguousarray(depthFrame) + depthFrame = cv2.flip(inDepth.getFrame(), 1) # frame is transformed, the color map will be applied to highlight the depth info depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_JET) @@ -142,10 +131,21 @@ def displayFrame(name, frame): # depthFrame = cv2.applyColorMap(depthFrame, cv2.COLORMAP_DEEPGREEN) if rightFrame is not None: - displayFrame("rectified right", rightFrame) + for detection in detections: + bbox = frameNorm(rightFrame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) + cv2.rectangle(rightFrame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (255, 0, 0), 2) + cv2.putText(rightFrame, labelMap[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) + cv2.putText(rightFrame, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) + cv2.imshow("rectified right", rightFrame) if depthFrame is not None: - displayFrame("depth", depthFrame) + for detection in detections: + bbox = frameNorm(croppedFrame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) + bbox[::2] += offsetX + cv2.rectangle(depthFrame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (255, 0, 0), 2) + cv2.putText(depthFrame, labelMap[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) + cv2.putText(depthFrame, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) + cv2.imshow("depth", depthFrame) if cv2.waitKey(1) == ord('q'): break diff --git a/examples/11_rgb_encoding_mono_mobilenet.py b/examples/11_rgb_encoding_mono_mobilenet.py index bdd042998..1d8234b41 100755 --- a/examples/11_rgb_encoding_mono_mobilenet.py +++ b/examples/11_rgb_encoding_mono_mobilenet.py @@ -74,7 +74,7 @@ frame = None frameManip = None detections = [] - offset_x = (camRight.getResolutionWidth() - camRight.getResolutionHeight()) // 2 + offsetX = (camRight.getResolutionWidth() - camRight.getResolutionHeight()) // 2 def frameNorm(frame, bbox): normVals = np.full(len(bbox), frame.shape[0]) @@ -103,10 +103,10 @@ def frameNorm(frame, bbox): detections = inDet.detections if frame is not None: - cropped_frame = np.zeros((camRight.getResolutionHeight(), camRight.getResolutionHeight())) + croppedFrame = np.zeros((camRight.getResolutionHeight(), camRight.getResolutionHeight())) for detection in detections: - bbox = frameNorm(cropped_frame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) - bbox[::2] += offset_x + bbox = frameNorm(croppedFrame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) + bbox[::2] += offsetX cv2.rectangle(frame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (255, 0, 0), 2) cv2.putText(frame, labelMap[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) cv2.putText(frame, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) diff --git a/examples/12_rgb_encoding_mono_mobilenet_depth.py b/examples/12_rgb_encoding_mono_mobilenet_depth.py index 4252252a6..b1cff44f1 100755 --- a/examples/12_rgb_encoding_mono_mobilenet_depth.py +++ b/examples/12_rgb_encoding_mono_mobilenet_depth.py @@ -91,8 +91,8 @@ frameManip = None frameDepth = None detections = [] - offset_x = (camRight.getResolutionWidth() - camRight.getResolutionHeight()) // 2 - cropped_frame = np.zeros((camRight.getResolutionHeight(), camRight.getResolutionHeight())) + offsetX = (camRight.getResolutionWidth() - camRight.getResolutionHeight()) // 2 + croppedFrame = np.zeros((camRight.getResolutionHeight(), camRight.getResolutionHeight())) def frameNorm(frame, bbox): normVals = np.full(len(bbox), frame.shape[0]) @@ -129,8 +129,8 @@ def frameNorm(frame, bbox): if frame is not None: for detection in detections: - bbox = frameNorm(cropped_frame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) - bbox[::2] += offset_x + bbox = frameNorm(croppedFrame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) + bbox[::2] += offsetX cv2.rectangle(frame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (255, 0, 0), 2) cv2.putText(frame, labelMap[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) cv2.putText(frame, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) @@ -138,8 +138,8 @@ def frameNorm(frame, bbox): if frameDepth is not None: for detection in detections: - bbox = frameNorm(cropped_frame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) - bbox[::2] += offset_x + bbox = frameNorm(croppedFrame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) + bbox[::2] += offsetX cv2.rectangle(frameDepth, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (255, 0, 0), 2) cv2.putText(frameDepth, labelMap[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) cv2.putText(frameDepth, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) diff --git a/examples/15_rgb_mobilenet_4k.py b/examples/15_rgb_mobilenet_4k.py index dab41ad34..4459339db 100755 --- a/examples/15_rgb_mobilenet_4k.py +++ b/examples/15_rgb_mobilenet_4k.py @@ -52,9 +52,9 @@ device.startPipeline() # Output queues will be used to get the frames and nn data from the outputs defined above - qVideo = device.getOutputQueue(name="video", maxSize=1, blocking=False) - qPreview = device.getOutputQueue(name="preview", maxSize=1, blocking=False) - qDet = device.getOutputQueue(name="nn", maxSize=1, blocking=False) + qVideo = device.getOutputQueue(name="video", maxSize=4, blocking=False) + qPreview = device.getOutputQueue(name="preview", maxSize=4, blocking=False) + qDet = device.getOutputQueue(name="nn", maxSize=4, blocking=False) previewFrame = None videoFrame = None @@ -66,8 +66,14 @@ def frameNorm(frame, bbox): normVals[::2] = frame.shape[1] return (np.clip(np.array(bbox), 0, 1) * normVals).astype(int) - offset_x = (camRgb.getResolutionWidth() - camRgb.getResolutionHeight()) // 2 - cropped_frame = np.zeros((camRgb.getResolutionHeight(), camRgb.getResolutionHeight())) + def displayFrame(name, frame): + for detection in detections: + bbox = frameNorm(frame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) + cv2.rectangle(frame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (255, 0, 0), 2) + cv2.putText(frame, labelMap[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) + cv2.putText(frame, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) + cv2.imshow(name, frame) + cv2.namedWindow("video", cv2.WINDOW_NORMAL) cv2.resizeWindow("video", 1280, 720) print("Resize video window with mouse drag!") @@ -88,21 +94,10 @@ def frameNorm(frame, bbox): detections = inDet.detections if videoFrame is not None: - for detection in detections: - bbox = frameNorm(cropped_frame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) - bbox[::2] += offset_x - cv2.rectangle(videoFrame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (255, 0, 0), 2) - cv2.putText(videoFrame, labelMap[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) - cv2.putText(videoFrame, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) - cv2.imshow("video", videoFrame) + displayFrame("video", videoFrame) if previewFrame is not None: - for detection in detections: - bbox = frameNorm(previewFrame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) - cv2.rectangle(previewFrame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (255, 0, 0), 2) - cv2.putText(previewFrame, labelMap[detection.label], (bbox[0] + 10, bbox[1] + 20), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) - cv2.putText(previewFrame, f"{int(detection.confidence * 100)}%", (bbox[0] + 10, bbox[1] + 40), cv2.FONT_HERSHEY_TRIPLEX, 0.5, 255) - cv2.imshow("preview", previewFrame) + displayFrame("preview", previewFrame) if cv2.waitKey(1) == ord('q'): break diff --git a/examples/28_camera_video_example.py b/examples/28_camera_video_example.py index 34c4c3513..e7c949853 100644 --- a/examples/28_camera_video_example.py +++ b/examples/28_camera_video_example.py @@ -16,6 +16,8 @@ # Create output xoutVideo = pipeline.createXLinkOut() xoutVideo.setStreamName("video") +xoutVideo.input.setBlocking(False) +xoutVideo.input.setQueueSize(1) colorCam.video.link(xoutVideo.input) From 22c85b656bd6fd7ab0d9250d38bd0605bde346e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pi=C5=82atowski?= Date: Fri, 26 Mar 2021 11:32:14 +0100 Subject: [PATCH 4/8] move croppedFrame --- examples/11_rgb_encoding_mono_mobilenet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/11_rgb_encoding_mono_mobilenet.py b/examples/11_rgb_encoding_mono_mobilenet.py index 1d8234b41..98d75b31d 100755 --- a/examples/11_rgb_encoding_mono_mobilenet.py +++ b/examples/11_rgb_encoding_mono_mobilenet.py @@ -75,6 +75,7 @@ frameManip = None detections = [] offsetX = (camRight.getResolutionWidth() - camRight.getResolutionHeight()) // 2 + croppedFrame = np.zeros((camRight.getResolutionHeight(), camRight.getResolutionHeight())) def frameNorm(frame, bbox): normVals = np.full(len(bbox), frame.shape[0]) @@ -103,7 +104,6 @@ def frameNorm(frame, bbox): detections = inDet.detections if frame is not None: - croppedFrame = np.zeros((camRight.getResolutionHeight(), camRight.getResolutionHeight())) for detection in detections: bbox = frameNorm(croppedFrame, (detection.xmin, detection.ymin, detection.xmax, detection.ymax)) bbox[::2] += offsetX From 056c662b0a2f424b555f73198d870759d11e6b84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pi=C5=82atowski?= Date: Fri, 26 Mar 2021 21:28:09 +0100 Subject: [PATCH 5/8] update demo videos --- docs/source/samples/09_mono_mobilenet.rst | 2 +- .../samples/10_mono_depth_mobilenetssd.rst | 6 ++-- .../11_rgb_encoding_mono_mobilenet.rst | 2 +- .../12_rgb_encoding_mono_mobilenet_depth.rst | 4 +-- docs/source/samples/15_rgb_mobilenet_4k.rst | 2 +- docs/source/samples/17_video_mobilenet.rst | 4 +-- .../samples/18_rgb_encoding_mobilenet.rst | 2 +- .../21_mobilenet_decoding_on_device.rst | 33 +------------------ .../22_1_tiny_yolo_v3_decoding_on_device.rst | 6 ++++ .../22_2_tiny_yolo_v4_decoding_on_device.rst | 6 ++++ docs/source/samples/24_opencv_support.rst | 11 ++++++- .../source/samples/26_1_spatial_mobilenet.rst | 6 ++++ .../samples/26_2_spatial_mobilenet_mono.rst | 8 ++++- .../source/samples/26_3_spatial_tiny_yolo.rst | 8 ++++- .../samples/28_camera_video_example.rst | 9 +++++ .../12_rgb_encoding_mono_mobilenet_depth.py | 3 +- examples/26_1_spatial_mobilenet.py | 2 +- examples/26_2_spatial_mobilenet_mono.py | 2 +- examples/26_3_spatial_tiny_yolo.py | 2 +- 19 files changed, 67 insertions(+), 51 deletions(-) diff --git a/docs/source/samples/09_mono_mobilenet.rst b/docs/source/samples/09_mono_mobilenet.rst index 9cb99f9c5..f08954948 100644 --- a/docs/source/samples/09_mono_mobilenet.rst +++ b/docs/source/samples/09_mono_mobilenet.rst @@ -10,7 +10,7 @@ Demo .. raw:: html
- +
Setup diff --git a/docs/source/samples/10_mono_depth_mobilenetssd.rst b/docs/source/samples/10_mono_depth_mobilenetssd.rst index da36998b5..9c0f749bd 100644 --- a/docs/source/samples/10_mono_depth_mobilenetssd.rst +++ b/docs/source/samples/10_mono_depth_mobilenetssd.rst @@ -1,5 +1,5 @@ -10 - Mono & MobilenetSSD & Encoding -=================================== +10 - Mono & MobilenetSSD & Depth +================================ This example shows how to run MobileNetv2SSD on the left grayscale camera in parallel with running the disparity depth results, displaying both the depth map and the right grayscale stream, with the @@ -11,7 +11,7 @@ Demo .. raw:: html
- +
Setup diff --git a/docs/source/samples/11_rgb_encoding_mono_mobilenet.rst b/docs/source/samples/11_rgb_encoding_mono_mobilenet.rst index 925c15386..3f1862bb1 100644 --- a/docs/source/samples/11_rgb_encoding_mono_mobilenet.rst +++ b/docs/source/samples/11_rgb_encoding_mono_mobilenet.rst @@ -18,7 +18,7 @@ Demo .. raw:: html
- +
Setup diff --git a/docs/source/samples/12_rgb_encoding_mono_mobilenet_depth.rst b/docs/source/samples/12_rgb_encoding_mono_mobilenet_depth.rst index cca2e8a76..7053567da 100644 --- a/docs/source/samples/12_rgb_encoding_mono_mobilenet_depth.rst +++ b/docs/source/samples/12_rgb_encoding_mono_mobilenet_depth.rst @@ -1,5 +1,5 @@ 12 - RGB Encoding & Mono with MobilenetSSD & Depth -================================================ +================================================== This example shows how to configure the depthai video encoder in h.265 format to encode the RGB camera input at Full-HD resolution at 30FPS, and transfers the encoded video over XLINK to the host, @@ -20,7 +20,7 @@ Demo .. raw:: html
- +
Setup diff --git a/docs/source/samples/15_rgb_mobilenet_4k.rst b/docs/source/samples/15_rgb_mobilenet_4k.rst index 7639a1a7a..a1e652a4b 100644 --- a/docs/source/samples/15_rgb_mobilenet_4k.rst +++ b/docs/source/samples/15_rgb_mobilenet_4k.rst @@ -11,7 +11,7 @@ Demo .. raw:: html
- +
diff --git a/docs/source/samples/17_video_mobilenet.rst b/docs/source/samples/17_video_mobilenet.rst index 4b51a2e4f..e84bda816 100644 --- a/docs/source/samples/17_video_mobilenet.rst +++ b/docs/source/samples/17_video_mobilenet.rst @@ -12,7 +12,7 @@ Demo .. raw:: html
- +
@@ -23,7 +23,7 @@ Setup This example also requires MobilenetSDD blob (:code:`mobilenet.blob` file) and prerecorded video (:code:`construction_vest.mp4` file) to work - you can download them -here: `mobilenet.blob `__ +here: `mobilenet.blob `__ and `construction_vest.mp4 `__ Source code diff --git a/docs/source/samples/18_rgb_encoding_mobilenet.rst b/docs/source/samples/18_rgb_encoding_mobilenet.rst index 86e6e25d3..e44e5caa3 100644 --- a/docs/source/samples/18_rgb_encoding_mobilenet.rst +++ b/docs/source/samples/18_rgb_encoding_mobilenet.rst @@ -18,7 +18,7 @@ Demo .. raw:: html
- +
Setup diff --git a/docs/source/samples/21_mobilenet_decoding_on_device.rst b/docs/source/samples/21_mobilenet_decoding_on_device.rst index 291dcb0f5..fe1925e09 100644 --- a/docs/source/samples/21_mobilenet_decoding_on_device.rst +++ b/docs/source/samples/21_mobilenet_decoding_on_device.rst @@ -1,32 +1 @@ -21 - RGB & MobilenetSSD decoding on device -========================================== - -This example shows how to run MobileNetv2SSD on the RGB input frame, and how to display both the RGB -preview and the metadata results from the MobileNetv2SSD on the preview. It's similar to example '08_rgb_mobilenet' except -decoding is done on Myriad instead on the host. - - -setConfidenceThreshold - confidence threshold above which objects are detected - -Demo -#### - - -Setup -##### - -.. include:: /includes/install_from_pypi.rst - -This example also requires MobilenetSDD blob (:code:`mobilenet.blob` file) to work - you can download it from -`here `__ - -Source code -########### - -Also `available on GitHub `__ - -.. literalinclude:: ../../../examples/21_mobilenet_device_side_decoding.py - :language: python - :linenos: - -.. include:: /includes/footer-short.rst +This example was moved to :ref:`08 - RGB & MobilenetSSD` \ No newline at end of file diff --git a/docs/source/samples/22_1_tiny_yolo_v3_decoding_on_device.rst b/docs/source/samples/22_1_tiny_yolo_v3_decoding_on_device.rst index b8609f35e..835a002d5 100644 --- a/docs/source/samples/22_1_tiny_yolo_v3_decoding_on_device.rst +++ b/docs/source/samples/22_1_tiny_yolo_v3_decoding_on_device.rst @@ -15,6 +15,12 @@ setConfidenceThreshold - confidence threshold above which objects are detected Demo #### +.. raw:: html + +
+ +
+ Setup ##### diff --git a/docs/source/samples/22_2_tiny_yolo_v4_decoding_on_device.rst b/docs/source/samples/22_2_tiny_yolo_v4_decoding_on_device.rst index 88c9672fe..8e5b53aa6 100644 --- a/docs/source/samples/22_2_tiny_yolo_v4_decoding_on_device.rst +++ b/docs/source/samples/22_2_tiny_yolo_v4_decoding_on_device.rst @@ -15,6 +15,12 @@ setConfidenceThreshold - confidence threshold above which objects are detected Demo #### +.. raw:: html + +
+ +
+ Setup ##### diff --git a/docs/source/samples/24_opencv_support.rst b/docs/source/samples/24_opencv_support.rst index 427f7cc44..f0088618c 100644 --- a/docs/source/samples/24_opencv_support.rst +++ b/docs/source/samples/24_opencv_support.rst @@ -1,10 +1,19 @@ 24 - OpenCV support -========================= +=================== This example shows API which exposes both numpy and OpenCV compatible image types for eaiser usage. It uses ColorCamera node to retrieve both BGR interleaved 'preview' and NV12 encoded 'video' frames. Both are displayed using functions `getFrame` and `getCvFrame`. +Demo +#### + +.. raw:: html + +
+ +
+ Setup ##### diff --git a/docs/source/samples/26_1_spatial_mobilenet.rst b/docs/source/samples/26_1_spatial_mobilenet.rst index a3b891729..c5ca5ff3e 100644 --- a/docs/source/samples/26_1_spatial_mobilenet.rst +++ b/docs/source/samples/26_1_spatial_mobilenet.rst @@ -11,6 +11,12 @@ setConfidenceThreshold - confidence threshold above which objects are detected Demo #### +.. raw:: html + +
+ +
+ Setup ##### diff --git a/docs/source/samples/26_2_spatial_mobilenet_mono.rst b/docs/source/samples/26_2_spatial_mobilenet_mono.rst index 54f3e2a24..786b99a88 100644 --- a/docs/source/samples/26_2_spatial_mobilenet_mono.rst +++ b/docs/source/samples/26_2_spatial_mobilenet_mono.rst @@ -1,4 +1,4 @@ -26.2 - MONO & MobilenetSSD with spatial data +26.2 - Mono & MobilenetSSD with spatial data ============================================ This example shows how to run MobileNetv2SSD on the rectified right input frame, and @@ -11,6 +11,12 @@ setConfidenceThreshold - confidence threshold above which objects are detected Demo #### +.. raw:: html + +
+ +
+ Setup ##### diff --git a/docs/source/samples/26_3_spatial_tiny_yolo.rst b/docs/source/samples/26_3_spatial_tiny_yolo.rst index 065030516..7c462ece6 100644 --- a/docs/source/samples/26_3_spatial_tiny_yolo.rst +++ b/docs/source/samples/26_3_spatial_tiny_yolo.rst @@ -1,4 +1,4 @@ -26.1 - RGB & TinyYolo with spatial data +26.3 - RGB & TinyYolo with spatial data =========================================== This example shows how to run TinyYoloV3 and v4 on the RGB input frame, and how to display both the RGB @@ -17,6 +17,12 @@ setConfidenceThreshold - confidence threshold above which objects are detected Demo #### +.. raw:: html + +
+ +
+ Setup ##### diff --git a/docs/source/samples/28_camera_video_example.rst b/docs/source/samples/28_camera_video_example.rst index 2eb08a02d..725d55223 100644 --- a/docs/source/samples/28_camera_video_example.rst +++ b/docs/source/samples/28_camera_video_example.rst @@ -4,6 +4,15 @@ This example shows how to use high resolution video at low latency. Compared to :ref:`01 - RGB Preview`, this demo outputs NV12 frames whereas preview frames are BGR and are not suited for larger resoulution (eg. 2000x1000). Preview is more suitable for either NN or visualization purposes. +Demo +#### + +.. raw:: html + +
+ +
+ Setup ##### diff --git a/examples/12_rgb_encoding_mono_mobilenet_depth.py b/examples/12_rgb_encoding_mono_mobilenet_depth.py index b1cff44f1..9c9761fc7 100755 --- a/examples/12_rgb_encoding_mono_mobilenet_depth.py +++ b/examples/12_rgb_encoding_mono_mobilenet_depth.py @@ -34,7 +34,7 @@ camRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P) depth = pipeline.createStereoDepth() -depth.setConfidenceThreshold(200) +depth.setConfidenceThreshold(255) # Note: the rectified streams are horizontally mirrored by default depth.setOutputRectified(True) depth.setRectifyEdgeFillColor(0) # Black, to better see the cutout @@ -121,7 +121,6 @@ def frameNorm(frame, bbox): if inDepth is not None: frameDepth = cv2.flip(inDepth.getFrame(), 1) - frameDepth = cv2.normalize(frameDepth, None, 0, 255, cv2.NORM_MINMAX) frameDepth = cv2.applyColorMap(frameDepth, cv2.COLORMAP_JET) if inDet is not None: diff --git a/examples/26_1_spatial_mobilenet.py b/examples/26_1_spatial_mobilenet.py index 4891db133..e0f522b11 100755 --- a/examples/26_1_spatial_mobilenet.py +++ b/examples/26_1_spatial_mobilenet.py @@ -19,7 +19,7 @@ syncNN = True # Get argument first -nnBlobPath = str((Path(__file__).parent / Path('models/mobilenet.blob')).resolve().absolute()) +nnBlobPath = str((Path(__file__).parent / Path('models/mobilenet-ssd_openvino_2021.2_6shave.blob')).resolve().absolute()) if len(sys.argv) > 1: nnBlobPath = sys.argv[1] diff --git a/examples/26_2_spatial_mobilenet_mono.py b/examples/26_2_spatial_mobilenet_mono.py index f333c0562..7e17bc2a0 100755 --- a/examples/26_2_spatial_mobilenet_mono.py +++ b/examples/26_2_spatial_mobilenet_mono.py @@ -22,7 +22,7 @@ flipRectified = True # Get argument first -nnPath = str((Path(__file__).parent / Path('models/mobilenet.blob')).resolve().absolute()) +nnPath = str((Path(__file__).parent / Path('models/mobilenet-ssd_openvino_2021.2_6shave.blob')).resolve().absolute()) if len(sys.argv) > 1: nnPath = sys.argv[1] diff --git a/examples/26_3_spatial_tiny_yolo.py b/examples/26_3_spatial_tiny_yolo.py index 04adcbb93..0047d9f56 100755 --- a/examples/26_3_spatial_tiny_yolo.py +++ b/examples/26_3_spatial_tiny_yolo.py @@ -32,7 +32,7 @@ syncNN = True # Get argument first -nnBlobPath = str((Path(__file__).parent / Path('models/mobilenet.blob')).resolve().absolute()) +nnBlobPath = str((Path(__file__).parent / Path('models/tiny-yolo-v4_openvino_2021.2_6shave.blob')).resolve().absolute()) if len(sys.argv) > 1: nnBlobPath = sys.argv[1] From ee129b7d0610022f079064db48c2cf99342ec4fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pi=C5=82atowski?= Date: Mon, 29 Mar 2021 14:54:01 +0200 Subject: [PATCH 6/8] update gifs --- docs/source/samples/25_system_information.rst | 37 +++++++++++++++ examples/README.md | 47 +++++++++++++++++-- 2 files changed, 79 insertions(+), 5 deletions(-) diff --git a/docs/source/samples/25_system_information.rst b/docs/source/samples/25_system_information.rst index 9c5c0c3cc..776c0b21e 100644 --- a/docs/source/samples/25_system_information.rst +++ b/docs/source/samples/25_system_information.rst @@ -3,6 +3,43 @@ This example shows how to get system information (memory usage, cpu usage and temperature) from the board. +Demo +#### + +Example script output + +.. code-block:: + + Drr used / total - 0.13 / 414.80 MiB + Cmx used / total - 2.24 / 2.50 MiB + LeonCss heap used / total - 4.17 / 46.41 MiB + LeonMss heap used / total - 2.87 / 27.58 MiB + Chip temperature - average: 38.59, css: 39.81, mss: 37.71, upa0: 38.65, upa1: 38.18 + Cpu usage - Leon OS: 7.08%, Leon RT: 1.48 % + ---------------------------------------- + Drr used / total - 0.13 / 414.80 MiB + Cmx used / total - 2.24 / 2.50 MiB + LeonCss heap used / total - 4.17 / 46.41 MiB + LeonMss heap used / total - 2.87 / 27.58 MiB + Chip temperature - average: 38.59, css: 39.58, mss: 37.94, upa0: 38.18, upa1: 38.65 + Cpu usage - Leon OS: 1.55%, Leon RT: 0.30 % + ---------------------------------------- + Drr used / total - 0.13 / 414.80 MiB + Cmx used / total - 2.24 / 2.50 MiB + LeonCss heap used / total - 4.17 / 46.41 MiB + LeonMss heap used / total - 2.87 / 27.58 MiB + Chip temperature - average: 38.94, css: 40.04, mss: 38.18, upa0: 39.35, upa1: 38.18 + Cpu usage - Leon OS: 0.56%, Leon RT: 0.06 % + ---------------------------------------- + Drr used / total - 0.13 / 414.80 MiB + Cmx used / total - 2.24 / 2.50 MiB + LeonCss heap used / total - 4.17 / 46.41 MiB + LeonMss heap used / total - 2.87 / 27.58 MiB + Chip temperature - average: 39.46, css: 40.28, mss: 38.88, upa0: 39.81, upa1: 38.88 + Cpu usage - Leon OS: 0.51%, Leon RT: 0.06 % + ---------------------------------------- + + Setup ##### diff --git a/examples/README.md b/examples/README.md index ab5d2164c..aaed656c2 100644 --- a/examples/README.md +++ b/examples/README.md @@ -57,28 +57,65 @@ TEST_TIMEOUT=0 ctest -R "01_rgb_preview" --verbose ![example_7](https://user-images.githubusercontent.com/5244214/104040905-86209480-51d8-11eb-9e15-5fe94aba7b69.gif) ### 08_rgb_mobilenet.py -![example_8](https://user-images.githubusercontent.com/5244214/112524084-b58a7a80-8d9f-11eb-9389-e17b0ea40338.gif) +![example_8](https://user-images.githubusercontent.com/5244214/112838840-cb4cb800-909d-11eb-8264-83d3c1e5f348.gif) ### 09_mono_mobilenet.py -![example_9](https://user-images.githubusercontent.com/5244214/104040898-8456d100-51d8-11eb-9498-e316b71d41e6.gif) +![example_9](https://user-images.githubusercontent.com/5244214/112838832-ca1b8b00-909d-11eb-8ea1-eafeb98c3266.gif) ### 10_mono_depth_mobilenetssd.py **NOTE** For clearness, a `disparity` output is used instead of `depth`, as disparity is better to visualize -![example_10](https://user-images.githubusercontent.com/5244214/104056108-35b53100-51f0-11eb-9677-63e5fb5bcb83.gif) +![example_10](https://user-images.githubusercontent.com/5244214/112838828-c8ea5e00-909d-11eb-912a-ce3995a68bfd.gif) ### 11_rgb_encoding_mono_mobilenet.py -![example_11](https://user-images.githubusercontent.com/5244214/104740909-cb007a00-5748-11eb-8250-c07ee6bf980a.gif) +![example_11](https://user-images.githubusercontent.com/5244214/112838821-c851c780-909d-11eb-86d4-d7a6b6d0aebe.gif) ### 12_rgb_encoding_mono_mobilenet_depth.py **NOTE** For clearness, a `disparity` output is used instead of `depth`, as disparity is better to visualize -![example_12](https://user-images.githubusercontent.com/5244214/104741001-e9667580-5748-11eb-92d3-39dd726b0992.gif) +![example_12](https://user-images.githubusercontent.com/5244214/112838818-c7209a80-909d-11eb-8f50-81c023c59e9b.gif) ### 13_encoding_max_limit.py ![example_13](https://user-images.githubusercontent.com/5244214/104741072-0307bd00-5749-11eb-97f3-9422c8b0d8da.gif) ### 14_color_camera_control.py ![example_14](https://user-images.githubusercontent.com/5244214/104741150-187ce700-5749-11eb-8bd5-3d4f37d2d22a.gif) + +### 15_rgb_mobilenet_4k.py +![15](https://user-images.githubusercontent.com/5244214/112838812-c556d700-909d-11eb-8194-83602530c9af.gif) + +### 16_device_queue_event.py +![16](https://user-images.githubusercontent.com/5244214/112838810-c425aa00-909d-11eb-9962-550533f13268.gif) + +### 17_video_mobilenet.py +![17](https://user-images.githubusercontent.com/5244214/112838807-c38d1380-909d-11eb-9c89-878eaa20e4ed.gif) + +### 18_rgb_encoding_mobilenet.py +![18](https://user-images.githubusercontent.com/5244214/112838805-c25be680-909d-11eb-8db2-2d0ce61aebe0.gif) + +### 22_1_tiny_yolo_v3_device_side_decoding.py +![22_1](https://user-images.githubusercontent.com/5244214/112838798-c12ab980-909d-11eb-8e6c-5aa3d623c7e9.gif) + +### 22_2_tiny_yolo_v4_device_side_decoding.py +![22_2](https://user-images.githubusercontent.com/5244214/112838790-bff98c80-909d-11eb-8b85-7c4dbd9a0e62.gif) + +### 23_autoexposure_roi.py +![23](https://user-images.githubusercontent.com/5244214/112838784-be2fc900-909d-11eb-8067-291636ae9950.gif) + +### 24_opencv_support.py +![24](https://user-images.githubusercontent.com/5244214/112838789-bf60f600-909d-11eb-9fb5-203dbec774f8.gif) + +### 26_1_spatial_mobilenet.py +![26_1](https://user-images.githubusercontent.com/5244214/112838781-bcfe9c00-909d-11eb-9d12-a9834f545271.gif) + +### 26_2_spatial_mobilenet_mono.py +![26_2](https://user-images.githubusercontent.com/5244214/112838777-bbcd6f00-909d-11eb-9b1e-d93159c3d88f.gif) + +### 26_3_spatial_tiny_yolo.py +![26_3](https://user-images.githubusercontent.com/5244214/112838772-ba9c4200-909d-11eb-9678-0703df46b529.gif) + +### 28_camera_video_example.py +![28](https://user-images.githubusercontent.com/5244214/112838767-b8d27e80-909d-11eb-92f0-5af20c4326b7.gif) + From b89196f6341cce242c98291e2571ee0d123593bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pi=C5=82atowski?= Date: Mon, 5 Apr 2021 23:06:08 +0200 Subject: [PATCH 7/8] rename queueSize --- examples/12_rgb_encoding_mono_mobilenet_depth.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/12_rgb_encoding_mono_mobilenet_depth.py b/examples/12_rgb_encoding_mono_mobilenet_depth.py index d5709ea7d..57f713a57 100755 --- a/examples/12_rgb_encoding_mono_mobilenet_depth.py +++ b/examples/12_rgb_encoding_mono_mobilenet_depth.py @@ -80,11 +80,11 @@ # Start pipeline device.startPipeline() - queue_size = 8 - qRight = device.getOutputQueue("right", queue_size) - qDepth = device.getOutputQueue("depth", queue_size) - qManip = device.getOutputQueue("manip", queue_size) - qDet = device.getOutputQueue("nn", queue_size) + queueSize = 8 + qRight = device.getOutputQueue("right", queueSize) + qDepth = device.getOutputQueue("depth", queueSize) + qManip = device.getOutputQueue("manip", queueSize) + qDet = device.getOutputQueue("nn", queueSize) qRgbEnc = device.getOutputQueue('h265', maxSize=30, blocking=True) frame = None From a78957c61e8abd6be12e6b8d1cc1e12212d031a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Pi=C5=82atowski?= Date: Mon, 5 Apr 2021 23:16:19 +0200 Subject: [PATCH 8/8] remove 21 from toctree --- docs/source/index.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/source/index.rst b/docs/source/index.rst index 2d51b886a..a99402d98 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -92,7 +92,6 @@ Now, pick a tutorial or code sample and start utilizing Gen2 capabilities samples/16_device_queue_event.rst samples/17_video_mobilenet.rst samples/18_rgb_encoding_mobilenet.rst - samples/21_mobilenet_decoding_on_device.rst samples/22_1_tiny_yolo_v3_decoding_on_device.rst samples/22_2_tiny_yolo_v4_decoding_on_device.rst samples/23_autoexposure_roi.rst