From ab767c271932a477e49b85508b85a9893bdb8e12 Mon Sep 17 00:00:00 2001 From: Erik Date: Tue, 3 Aug 2021 00:25:31 +0200 Subject: [PATCH 1/7] Update image_manip.rst --- docs/source/components/nodes/image_manip.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/components/nodes/image_manip.rst b/docs/source/components/nodes/image_manip.rst index 8ac767535..58a56c4d0 100644 --- a/docs/source/components/nodes/image_manip.rst +++ b/docs/source/components/nodes/image_manip.rst @@ -71,6 +71,7 @@ Examples of functionality - :ref:`Mono & MobilenetSSD` - :ref:`RGB Encoding & Mono & MobilenetSSD` - :ref:`RGB Camera Control` +- `Rotating mono frames `__ Reference ######### From 449ae4975524c7f44b29b6a03f5394db0d97f554 Mon Sep 17 00:00:00 2001 From: Erol444 Date: Tue, 3 Aug 2021 20:44:38 +0200 Subject: [PATCH 2/7] Added ImageManip rotate example --- examples/image_manip_rotate.py | 57 ++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 examples/image_manip_rotate.py diff --git a/examples/image_manip_rotate.py b/examples/image_manip_rotate.py new file mode 100644 index 000000000..4a4cb5bfa --- /dev/null +++ b/examples/image_manip_rotate.py @@ -0,0 +1,57 @@ +import cv2 +import depthai as dai + +# Create pipeline +pipeline = dai.Pipeline() + +# Rotate color frames +camRgb = pipeline.createColorCamera() +camRgb.setPreviewSize(640, 400) +camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P) +camRgb.setInterleaved(False) + +manipRgb = pipeline.createImageManip() +manipRgb.setMaxOutputFrameSize(2000 * 1500 * 3) +rgbRr = dai.RotatedRect() +rgbRr.center.x, rgbRr.center.y = camRgb.getPreviewWidth() // 2, camRgb.getPreviewHeight() // 2 +rgbRr.size.width, rgbRr.size.height = camRgb.getPreviewHeight(), camRgb.getPreviewWidth() +rgbRr.angle = 90 +manipRgb.initialConfig.setCropRotatedRect(rgbRr, False) +camRgb.preview.link(manipRgb.inputImage) + +manipRgbOut = pipeline.createXLinkOut() +manipRgbOut.setStreamName("manip_rgb") +manipRgb.out.link(manipRgbOut.input) + +# Rotate mono frames +monoLeft = pipeline.createMonoCamera() +monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P) +monoLeft.setBoardSocket(dai.CameraBoardSocket.LEFT) + +manipLeft = pipeline.createImageManip() +rr = dai.RotatedRect() +rr.center.x, rr.center.y = monoLeft.getResolutionWidth() // 2, monoLeft.getResolutionHeight() // 2 +rr.size.width, rr.size.height = monoLeft.getResolutionHeight(), monoLeft.getResolutionWidth() +rr.angle = 90 +manipLeft.initialConfig.setCropRotatedRect(rr, False) +monoLeft.out.link(manipLeft.inputImage) + +manipLeftOut = pipeline.createXLinkOut() +manipLeftOut.setStreamName("manip_left") +manipLeft.out.link(manipLeftOut.input) + +with dai.Device(pipeline) as device: + qLeft = device.getOutputQueue(name="manip_left", maxSize=8, blocking=False) + qRgb = device.getOutputQueue(name="manip_rgb", maxSize=8, blocking=False) + + while True: + inLeft = qLeft.tryGet() + if inLeft is not None: + cv2.imshow('Left rotated', inLeft.getCvFrame()) + + inRgb = qRgb.tryGet() + if inRgb is not None: + cv2.imshow('Color rotated', inRgb.getCvFrame()) + + if cv2.waitKey(1) == ord('q'): + break \ No newline at end of file From ee3e19837694c75a0a4f652d2a5f1af6b15463af Mon Sep 17 00:00:00 2001 From: Erol444 Date: Tue, 3 Aug 2021 21:08:10 +0200 Subject: [PATCH 3/7] Added imageManip tiling example, updated depthai-core --- depthai-core | 2 +- examples/image_manip_rotate.py | 2 ++ examples/image_manip_tiling.py | 50 ++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 examples/image_manip_tiling.py diff --git a/depthai-core b/depthai-core index 7d76a830f..85b4a0802 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 7d76a830ffc51512adae455ec28b1150eabec513 +Subproject commit 85b4a08023fa0e38d11ee2dcf612e7b3318aec9e diff --git a/examples/image_manip_rotate.py b/examples/image_manip_rotate.py index 4a4cb5bfa..d71d17c95 100644 --- a/examples/image_manip_rotate.py +++ b/examples/image_manip_rotate.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + import cv2 import depthai as dai diff --git a/examples/image_manip_tiling.py b/examples/image_manip_tiling.py new file mode 100644 index 000000000..441dbb53d --- /dev/null +++ b/examples/image_manip_tiling.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 + +import cv2 +import depthai as dai + +# Create pipeline +pipeline = dai.Pipeline() + +camRgb = pipeline.createColorCamera() +camRgb.setPreviewSize(1000, 500) +camRgb.setInterleaved(False) +maxFrameSize = camRgb.getPreviewHeight() * camRgb.getPreviewHeight() * 3 + +# In this example we use 2 imageManips for splitting the original 1000x500 +# preview frame into 2 500x500 frames +manip1 = pipeline.createImageManip() +manip1.initialConfig.setCropRect(0, 0, 0.5, 1) +manip1.setMaxOutputFrameSize(maxFrameSize) +camRgb.preview.link(manip1.inputImage) + +manip2 = pipeline.createImageManip() +manip2.initialConfig.setCropRect(0.5, 0, 1, 1) +manip2.setMaxOutputFrameSize(maxFrameSize) +camRgb.preview.link(manip2.inputImage) + +xout1 = pipeline.createXLinkOut() +xout1.setStreamName('out1') +manip1.out.link(xout1.input) + +xout2 = pipeline.createXLinkOut() +xout2.setStreamName('out2') +manip2.out.link(xout2.input) + +# Connect to device and start pipeline +with dai.Device(pipeline) as device: + # Output queue will be used to get the rgb frames from the output defined above + q1 = device.getOutputQueue(name="out1", maxSize=4, blocking=False) + q2 = device.getOutputQueue(name="out2", maxSize=4, blocking=False) + + while True: + in1 = q1.tryGet() + if in1 is not None: + cv2.imshow("Tile 1", in1.getCvFrame()) + + in2 = q2.tryGet() + if in2 is not None: + cv2.imshow("Tile 2", in2.getCvFrame()) + + if cv2.waitKey(1) == ord('q'): + break From 83815928effb69532dfc4635fd913d2e1fbe8ada Mon Sep 17 00:00:00 2001 From: Erol444 Date: Tue, 3 Aug 2021 23:36:44 +0200 Subject: [PATCH 4/7] Added rst documentation for both imagemanip rotate and tiling --- docs/source/samples/image_manip_rotate.rst | 44 ++++++++++++++++++++++ docs/source/samples/image_manip_tiling.rst | 41 ++++++++++++++++++++ docs/source/tutorials/code_samples.rst | 2 + docs/source/tutorials/simple_samples.rst | 4 ++ examples/image_manip_rotate.py | 1 - 5 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 docs/source/samples/image_manip_rotate.rst create mode 100644 docs/source/samples/image_manip_tiling.rst diff --git a/docs/source/samples/image_manip_rotate.rst b/docs/source/samples/image_manip_rotate.rst new file mode 100644 index 000000000..af08d088c --- /dev/null +++ b/docs/source/samples/image_manip_rotate.rst @@ -0,0 +1,44 @@ +ImageManip Rotate +================= + +This example showcases how to rotate color and mono frames with the help of :ref:`ImageManip` node. +In the example, we are rotating by 90°. + +.. note:: + Due to HW warp constraint, input image (to be rotated) has to have **width value of multiples of 16.** + +Demos +#### + +.. image:: https://user-images.githubusercontent.com/18037362/128074634-d2baa78e-8f35-40fc-8661-321f3a3c3850.png + :alt: Rotated mono and color frames + +Here I have DepthAI device positioned vertically on my desk. + +Setup +##### + +.. include:: /includes/install_from_pypi.rst + +Source code +########### + +.. tabs:: + + .. tab:: Python + + Also `available on GitHub `__ + + .. literalinclude:: ../../../examples/image_manip_rotate.py + :language: python + :linenos: + + .. tab:: C++ + + Also `available on GitHub `__ + + .. literalinclude:: ../../../depthai-core/examples/src/image_manip_rotate.cpp + :language: cpp + :linenos: + +.. include:: /includes/footer-short.rst diff --git a/docs/source/samples/image_manip_tiling.rst b/docs/source/samples/image_manip_tiling.rst new file mode 100644 index 000000000..2b1efc75c --- /dev/null +++ b/docs/source/samples/image_manip_tiling.rst @@ -0,0 +1,41 @@ +ImageManip Tiling +================= + +Frame tiling could be useful for eg. feeding large frame into a :ref:`NeuralNetwork` whose input size isn't as large. In such case, +you can tile the large frame into multiple smaller ones and feed smaller frames to the :ref:`NeuralNetwork`. + +In this example we use 2 :ref:`ImageManip` for splitting the original :code:`1000x500` preview frame into two :code:`500x500` frames. + +Demo +#### + +.. image:: https://user-images.githubusercontent.com/18037362/128074673-045ed4b6-ac8c-4a76-83bb-0f3dc996f7a5.png + :alt: Tiling preview into 2 frames/tiles + +Setup +##### + +.. include:: /includes/install_from_pypi.rst + +Source code +########### + +.. tabs:: + + .. tab:: Python + + Also `available on GitHub `__ + + .. literalinclude:: ../../../examples/image_manip_tiling.py + :language: python + :linenos: + + .. tab:: C++ + + Also `available on GitHub `__ + + .. literalinclude:: ../../../depthai-core/examples/src/image_manip_tiling.cpp + :language: cpp + :linenos: + +.. include:: /includes/footer-short.rst diff --git a/docs/source/tutorials/code_samples.rst b/docs/source/tutorials/code_samples.rst index 8cb2bcd17..4abdbf8d6 100644 --- a/docs/source/tutorials/code_samples.rst +++ b/docs/source/tutorials/code_samples.rst @@ -30,6 +30,8 @@ Code samples are used for automated testing. They are also a great starting poin - :ref:`IMU Accelerometer & Gyroscope` - Accelerometer and gyroscope at 500hz rate - :ref:`IMU Rotation Vector` - Rotation vector at 400 hz rate - :ref:`Edge detector` - Edge detection on input frame +- :ref:`ImageManip tiling` - Using ImageManip for frame tiling +- :ref:`ImageManip rotate` - Using ImageManip to rotate color/mono frames .. rubric:: Complex diff --git a/docs/source/tutorials/simple_samples.rst b/docs/source/tutorials/simple_samples.rst index 80c87b185..723d0180c 100644 --- a/docs/source/tutorials/simple_samples.rst +++ b/docs/source/tutorials/simple_samples.rst @@ -22,6 +22,8 @@ Simple ../samples/imu_accelerometer_gyroscope.rst ../samples/imu_rotation_vector.rst ../samples/edge_detector.rst + ../samples/image_manip_tiling.rst + ../samples/image_manip_rotate.rst These samples are great starting point for the gen2 API. @@ -39,3 +41,5 @@ These samples are great starting point for the gen2 API. - :ref:`Mono & MobilenetSSD` - Runs MobileNetSSD on mono frames and displays detections on the frame - :ref:`Video & MobilenetSSD` - Runs MobileNetSSD on the video from the host - :ref:`Edge detector` - Edge detection on input frame +- :ref:`ImageManip Tiling` - Using ImageManip for frame tiling +- :ref:`ImageManip Rotate` - Using ImageManip to rotate color/mono frames diff --git a/examples/image_manip_rotate.py b/examples/image_manip_rotate.py index d71d17c95..2e5c15c7b 100644 --- a/examples/image_manip_rotate.py +++ b/examples/image_manip_rotate.py @@ -13,7 +13,6 @@ camRgb.setInterleaved(False) manipRgb = pipeline.createImageManip() -manipRgb.setMaxOutputFrameSize(2000 * 1500 * 3) rgbRr = dai.RotatedRect() rgbRr.center.x, rgbRr.center.y = camRgb.getPreviewWidth() // 2, camRgb.getPreviewHeight() // 2 rgbRr.size.width, rgbRr.size.height = camRgb.getPreviewHeight(), camRgb.getPreviewWidth() From eb82c4412ca2ca3cf131f9388b4b29d6979e8890 Mon Sep 17 00:00:00 2001 From: Erik Date: Sat, 7 Aug 2021 00:38:18 +0200 Subject: [PATCH 5/7] Update image_manip.rst --- docs/source/components/nodes/image_manip.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/source/components/nodes/image_manip.rst b/docs/source/components/nodes/image_manip.rst index 9382f0b98..d7d897992 100644 --- a/docs/source/components/nodes/image_manip.rst +++ b/docs/source/components/nodes/image_manip.rst @@ -87,7 +87,8 @@ Examples of functionality - :ref:`Mono & MobilenetSSD` - :ref:`RGB Encoding & Mono & MobilenetSSD` - :ref:`RGB Camera Control` -- `Rotating mono frames `__ +- :ref:`ImageManip tiling` - Using ImageManip for frame tiling +- :ref:`ImageManip rotate` - Using ImageManip to rotate color/mono frames Reference ######### From 620e7885c887f6d701fde6799de1eaefdd504e38 Mon Sep 17 00:00:00 2001 From: Erol444 Date: Wed, 11 Aug 2021 16:40:18 +0200 Subject: [PATCH 6/7] Fix compilation errors --- docs/source/samples/image_manip_rotate.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/samples/image_manip_rotate.rst b/docs/source/samples/image_manip_rotate.rst index af08d088c..adccbf01f 100644 --- a/docs/source/samples/image_manip_rotate.rst +++ b/docs/source/samples/image_manip_rotate.rst @@ -8,7 +8,7 @@ In the example, we are rotating by 90°. Due to HW warp constraint, input image (to be rotated) has to have **width value of multiples of 16.** Demos -#### +##### .. image:: https://user-images.githubusercontent.com/18037362/128074634-d2baa78e-8f35-40fc-8661-321f3a3c3850.png :alt: Rotated mono and color frames From c94f5e359bfba0af3173f65c454dc632c4cd7856 Mon Sep 17 00:00:00 2001 From: Erol444 Date: Wed, 11 Aug 2021 16:56:34 +0200 Subject: [PATCH 7/7] Removed helper scripts --- examples/bootloader.py | 11 ----------- examples/flash_pipeline.py | 30 ------------------------------ 2 files changed, 41 deletions(-) delete mode 100644 examples/bootloader.py delete mode 100644 examples/flash_pipeline.py diff --git a/examples/bootloader.py b/examples/bootloader.py deleted file mode 100644 index 36d5c4e78..000000000 --- a/examples/bootloader.py +++ /dev/null @@ -1,11 +0,0 @@ -import depthai as dai - -(found, deviceInfo) = dai.DeviceBootloader.getFirstAvailableDevice() -if not found: - raise RuntimeError("Device not found!") - -bootloader = dai.DeviceBootloader(deviceInfo) -progress = lambda p : print(f'Flashing progress: {p*100:.1f}%') -bootloader.flashBootloader(progress) - -print("Bootloader flashed successfully") diff --git a/examples/flash_pipeline.py b/examples/flash_pipeline.py deleted file mode 100644 index 10ccd8cf7..000000000 --- a/examples/flash_pipeline.py +++ /dev/null @@ -1,30 +0,0 @@ -import depthai as dai -import time - -enable_4k = True - -# Start defining a pipeline -pipeline = dai.Pipeline() - -# Define a source - color camera -cam_rgb = pipeline.createColorCamera() -cam_rgb.setBoardSocket(dai.CameraBoardSocket.RGB) -cam_rgb.setInterleaved(False) -cam_rgb.initialControl.setManualFocus(130) - -if enable_4k: - cam_rgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_4_K) - cam_rgb.setIspScale(1, 2) -else: - cam_rgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P) - -# Create an UVC (USB Video Class) output node. It needs 1920x1080, NV12 input -uvc = pipeline.createUVC() -cam_rgb.video.link(uvc.input) - -(found, deviceInfo) = dai.DeviceBootloader.getFirstAvailableDevice() -bootloader = dai.DeviceBootloader(deviceInfo) -progress = lambda p : print(f'Flashing progress: {p*100:.1f}%') -bootloader.flash(progress, pipeline) - -print("Pipeline flashed successfully") \ No newline at end of file