Skip to content

Commit 600e6a1

Browse files
committed
Update depthai-core
1 parent 8d6a6d3 commit 600e6a1

File tree

6 files changed

+36
-36
lines changed

6 files changed

+36
-36
lines changed

docs/source/samples/NeuralNetwork/concat_multi_input.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
Multi-Input Frame Concationation
22
================================
33

4-
Example concatenates all 3 inputs with a simple custom NN created with PyTorch (`link here <https://github.com/luxonis/depthai-experiments/blob/master/gen2-custom-models/generate_model/pytorch_concat.py>`__, `tutorial here <https://docs.luxonis.com/en/latest/pages/tutorials/creating-custom-nn-models/>`__).
5-
It uses multiple input :ref:`NeuralNetwork` feature and links all 3 camera streams directly to the NN node.
4+
Example concatenates all 3 inputs with a simple custom model created with PyTorch (`link here <https://github.com/luxonis/depthai-experiments/blob/master/gen2-custom-models/generate_model/pytorch_concat.py>`__,
5+
`tutorial here <https://docs.luxonis.com/en/latest/pages/tutorials/creating-custom-nn-models/>`__).
6+
It uses :ref:`NeuralNetwork`'s multiple input feature and links all 3 camera streams directly to the NeuralNetwork node.
67

78
Demo
89
####
@@ -31,7 +32,7 @@ Source code
3132

3233
Also `available on GitHub <https://github.com/luxonis/depthai-core/blob/main/examples/src/concat_multiple_input.cpp>`__
3334

34-
.. literalinclude:: ../../../../depthai-core/examples/src/concat_multi_input.cpp
35+
.. literalinclude:: ../../../../depthai-core/examples/NeuralNetwork/concat_multi_input.cpp
3536
:language: cpp
3637
:linenos:
3738

docs/source/samples/NeuralNetwork/normalization_multi_input.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
Multi-Input Frame Normalization
2-
===============================
1+
Frame Normalization
2+
===================
33

4-
This example shows how you can normalize a frame before sending it to another NN. Many neural network models
4+
This example shows how you can normalize a frame before sending it to another neural network. Many neural network models
55
require frames with RGB values (pixels) in range between :code:`-0.5` to :code:`0.5`. :ref:`ColorCamera`'s preview outputs
6-
values between :code:`0` and :code:`255`. Simple custom NN, created with PyTorch (`link here <https://github.com/luxonis/depthai-experiments/blob/master/gen2-custom-models/generate_model/pytorch_normalize.py>`__, `tutorial here <https://docs.luxonis.com/en/latest/pages/tutorials/creating-custom-nn-models/>`__),
7-
allows users to specify mean and scale factors that will apply for all frame values (pixels).
6+
values between :code:`0` and :code:`255`. Simple custom model, created with PyTorch (`link here <https://github.com/luxonis/depthai-experiments/blob/master/gen2-custom-models/generate_model/pytorch_normalize.py>`__, `tutorial here <https://docs.luxonis.com/en/latest/pages/tutorials/creating-custom-nn-models/>`__),
7+
allows users to specify mean and scale factors that will be applied to all frame values (pixels).
88

99
.. math::
1010
1111
output = (input - mean) / scale
1212
13-
.. image:: /_static/images/examples/normalize)model.png
13+
.. image:: /_static/images/examples/normalize_model.png
1414

1515
On the host, values are converted back to :code:`0`-:code:`255`, so they can be displayed by OpenCV.
1616

1717
.. note::
18-
This is just a demo, for normalization you should look into OpenVINO's `model optimizer <https://docs.openvinotoolkit.org/latest/openvino_docs_MO_DG_prepare_model_convert_model_Converting_Model_General.html>`__ arguments :code:`--mean_values` and :code:`--scale_values`.
18+
This is just a demo, for normalization you should use OpenVINO's `model optimizer <https://docs.openvinotoolkit.org/latest/openvino_docs_MO_DG_prepare_model_convert_model_Converting_Model_General.html>`__ arguments :code:`--mean_values` and :code:`--scale_values`.
1919

2020
Setup
2121
#####
@@ -39,7 +39,7 @@ Source code
3939

4040
Also `available on GitHub <https://github.com/luxonis/depthai-core/blob/main/examples/src/normalization_multiple_input.cpp>`__
4141

42-
.. literalinclude:: ../../../../depthai-core/examples/src/normalization_multi_input.cpp
42+
.. literalinclude:: ../../../../depthai-core/examples/NeuralNetwork/normalization_multi_input.cpp
4343
:language: cpp
4444
:linenos:
4545

docs/source/tutorials/code_samples.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Code Samples
1616
../samples/mixed/*
1717
../samples/MobileNet/*
1818
../samples/MonoCamera/*
19+
../samples/NeuralNetwork/*
1920
../samples/ObjectTracker/*
2021
../samples/Script/*
2122
../samples/SpatialDetection/*
@@ -95,6 +96,11 @@ are presented with code.
9596
- :ref:`Mono Camera Control` - Demonstrates how to control the mono camera (crop, exposure, sensitivity) from the host
9697
- :ref:`Mono Full Resolution Saver` - Saves mono (720P) images to the host (:code:`.png`)
9798

99+
.. rubric:: NeuralNetwork
100+
101+
- :ref:`Multi-Input Frame Concat <Multi-Input Frame Concationation>` - Concat mono/rgb streams on the device with a custom model
102+
- :ref:`Frame Normalization` - Normalize the frame on the device with a custom model
103+
98104
.. rubric:: ObjectTracker
99105

100106
- :ref:`Object tracker on video` - Performs object tracking from the video

examples/NeuralNetwork/concat_multi_input.py

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,26 @@
2424
camRgb.setInterleaved(False)
2525
camRgb.setColorOrder(dai.ColorCameraProperties.ColorOrder.BGR)
2626

27-
left = p.create(dai.node.MonoCamera)
28-
left.setBoardSocket(dai.CameraBoardSocket.LEFT)
29-
left.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
30-
31-
# ImageManip for cropping (face detection NN requires input image of 300x300) and to change frame type
32-
manipLeft = p.create(dai.node.ImageManip)
33-
manipLeft.initialConfig.setResize(300, 300)
34-
manipLeft.initialConfig.setFrameType(dai.RawImgFrame.Type.BGR888p)
35-
left.out.link(manipLeft.inputImage)
36-
37-
right = p.create(dai.node.MonoCamera)
38-
right.setBoardSocket(dai.CameraBoardSocket.RIGHT)
39-
right.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
40-
41-
# ImageManip for cropping (face detection NN requires input image of 300x300) and to change frame type
42-
manipRight = p.create(dai.node.ImageManip)
43-
manipRight.initialConfig.setResize(300, 300)
44-
manipRight.initialConfig.setFrameType(dai.RawImgFrame.Type.BGR888p)
45-
right.out.link(manipRight.inputImage)
27+
def create_mono(p, socket):
28+
mono = p.create(dai.node.MonoCamera)
29+
mono.setBoardSocket(socket)
30+
mono.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
31+
32+
# ImageManip for cropping (face detection NN requires input image of 300x300) and to change frame type
33+
manip = p.create(dai.node.ImageManip)
34+
manip.initialConfig.setResize(300, 300)
35+
manip.initialConfig.setFrameType(dai.RawImgFrame.Type.BGR888p)
36+
mono.out.link(manip.inputImage)
37+
return manip.out
4638

4739
# NN that detects faces in the image
4840
nn = p.createNeuralNetwork()
4941
nn.setBlobPath(nnPath)
5042
nn.setNumInferenceThreads(2)
5143

52-
manipLeft.out.link(nn.inputs['img1'])
5344
camRgb.preview.link(nn.inputs['img2'])
54-
manipRight.out.link(nn.inputs['img3'])
45+
create_mono(p, dai.CameraBoardSocket.LEFT).link(nn.inputs['img1'])
46+
create_mono(p, dai.CameraBoardSocket.RIGHT).link(nn.inputs['img3'])
5547

5648
# Send bouding box from the NN to the host via XLink
5749
nn_xout = p.createXLinkOut()

examples/NeuralNetwork/normalization_multi_input.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
script = p.create(dai.node.Script)
3333
script.setScript("""
34-
# Run script only once
34+
# Run script only once. We could also send these values from host.
3535
# Model formula:
3636
# output = (input - mean) / scale
3737
@@ -68,10 +68,11 @@
6868
shape = (3, SHAPE, SHAPE)
6969
while True:
7070
inNn = np.array(qNn.get().getData())
71-
# Get back the frame. It's currently normalized to -1.0 - 1.0
71+
# Get back the frame. It's currently normalized to -0.5 - 0.5
7272
frame = inNn.view(np.float16).reshape(shape).transpose(1, 2, 0)
73-
# To get original frame back (0-255), we add multiply all frame values (pixels) by 255 and then add 127.5 to them.
73+
# To get original frame back (0-255), we add multiply all frame values (pixels) by 255 and then add 127.5 to them
7474
frame = (frame * 255.0 + 127.5).astype(np.uint8)
75+
# Show the initial frame
7576
cv2.imshow("Original frame", frame)
7677

7778
if cv2.waitKey(1) == ord('q'):

0 commit comments

Comments
 (0)