-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release_2.17.4.0' into main
- Loading branch information
Showing
17 changed files
with
359 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule depthai-core
updated
26 files
42 changes: 42 additions & 0 deletions
42
docs/source/samples/SpatialDetection/spatial_calculator_multi_roi.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Spatial Calculator Multi-ROI | ||
============================ | ||
|
||
This example shows how one can use multiple ROIs with a single :ref:`SpatailLocationCalculator` node. A similar logic could be used as a simple depth line | ||
scanning camera for mobile robots. | ||
|
||
.. rubric:: Similar samples: | ||
|
||
- :ref:`Spatial location calculator` | ||
|
||
Demo | ||
#### | ||
|
||
.. image:: https://user-images.githubusercontent.com/18037362/190861621-b57fd1e3-5a3d-4d79-b1a7-d17a0b78c63e.gif | ||
|
||
Setup | ||
##### | ||
|
||
.. include:: /includes/install_from_pypi.rst | ||
|
||
Source code | ||
########### | ||
|
||
.. tabs:: | ||
|
||
.. tab:: Python | ||
|
||
Also `available on GitHub <https://github.com/luxonis/depthai-python/blob/main/examples/SpatialDetection/spatial_calculator_multi_roi.py>`__ | ||
|
||
.. literalinclude:: ../../../../examples/SpatialDetection/spatial_calculator_multi_roi.py | ||
:language: python | ||
:linenos: | ||
|
||
.. tab:: C++ | ||
|
||
Also `available on GitHub <https://github.com/luxonis/depthai-core/blob/main/examples/SpatialDetection/spatial_calculator_multi_roi.cpp>`__ | ||
|
||
.. literalinclude:: ../../../../depthai-core/examples/SpatialDetection/spatial_calculator_multi_roi.cpp | ||
:language: cpp | ||
:linenos: | ||
|
||
.. include:: /includes/footer-short.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
Device information | ||
================== | ||
|
||
This example shows how you can query device information. | ||
|
||
The first part of the code queries all available devices without actually booting any device. For each found device, it prints the following information: | ||
|
||
- **Device name**: Either IP, in case of OAK PoE cameras, or USB path in case of OAK USB cameras | ||
- **MxId**: Unique Mx (chip) identification code | ||
- **State**: State of the device. Note that OAK PoE cameras have bootloader flashed which initializes the network stack | ||
|
||
Afterwards, the example boots into the first found device and prints available camera sensors, and reads calibration and eeprom data which stores product and | ||
board names. | ||
|
||
Demo | ||
#### | ||
|
||
.. code-block:: | ||
Searching for all available devices... | ||
Found device '1.3', MxId: '18443010D116631200', State: 'UNBOOTED' | ||
Found device '192.168.33.201', MxId: '184430102163DB0F00', State: 'BOOTLOADER' | ||
Found device '192.168.33.192', MxId: '1844301011F4C51200', State: 'BOOTLOADER' | ||
Booting the first available camera (1.3)... | ||
Available camera sensors: {<CameraBoardSocket.RIGHT: 2>: 'OV9282', <CameraBoardSocket.RGB: 0>: 'IMX378', <CameraBoardSocket.LEFT: 1>: 'OV9282'} | ||
Product name: OAK-D Pro AF, board name DM9098 | ||
Setup | ||
##### | ||
|
||
.. include:: /includes/install_from_pypi.rst | ||
|
||
Source code | ||
########### | ||
|
||
.. tabs:: | ||
|
||
.. tab:: Python | ||
|
||
Also `available on GitHub <https://github.com/luxonis/depthai-python/blob/main/examples/host_side/device_information.py>`__ | ||
|
||
.. literalinclude:: ../../../../examples/host_side/device_information.py | ||
:language: python | ||
:linenos: | ||
|
||
.. tab:: C++ | ||
|
||
Also `available on GitHub <https://github.com/luxonis/depthai-core/blob/main/examples/host_side/device_information.cpp>`__ | ||
|
||
.. literalinclude:: ../../../../depthai-core/examples/host_side/device_information.cpp | ||
:language: cpp | ||
:linenos: | ||
|
||
.. include:: /includes/footer-short.rst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python3 | ||
import depthai as dai | ||
import json | ||
|
||
# Start defining a pipeline | ||
pipeline = dai.Pipeline() | ||
|
||
# Script node | ||
script = pipeline.create(dai.node.Script) | ||
script.setScript(""" | ||
import json | ||
data = json.dumps({ | ||
'deviceId': __device_id__, | ||
'fwVersion': __version__ | ||
}).encode('utf-8') | ||
b = Buffer(len(data)) | ||
b.setData(data) | ||
node.io['info'].send(b) | ||
""") | ||
|
||
xout = pipeline.create(dai.node.XLinkOut) | ||
xout.setStreamName('info') | ||
script.outputs['info'].link(xout.input) | ||
|
||
# Connect to device with pipeline | ||
with dai.Device(pipeline) as device: | ||
msg = device.getOutputQueue("info").get() # Wait for the "end" msg | ||
data = json.loads(msg.getData().tobytes().decode('utf-8')) | ||
print(json.dumps(data, indent=4)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import cv2 | ||
import depthai as dai | ||
import math | ||
|
||
# Create pipeline | ||
pipeline = dai.Pipeline() | ||
|
||
# Define sources and outputs | ||
monoLeft = pipeline.create(dai.node.MonoCamera) | ||
monoRight = pipeline.create(dai.node.MonoCamera) | ||
stereo = pipeline.create(dai.node.StereoDepth) | ||
spatialLocationCalculator = pipeline.create(dai.node.SpatialLocationCalculator) | ||
|
||
xoutDepth = pipeline.create(dai.node.XLinkOut) | ||
xoutSpatialData = pipeline.create(dai.node.XLinkOut) | ||
xinSpatialCalcConfig = pipeline.create(dai.node.XLinkIn) | ||
|
||
xoutDepth.setStreamName("depth") | ||
xoutSpatialData.setStreamName("spatialData") | ||
xinSpatialCalcConfig.setStreamName("spatialCalcConfig") | ||
|
||
# Properties | ||
monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P) | ||
monoLeft.setBoardSocket(dai.CameraBoardSocket.LEFT) | ||
monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P) | ||
monoRight.setBoardSocket(dai.CameraBoardSocket.RIGHT) | ||
|
||
stereo.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_DENSITY) | ||
stereo.setLeftRightCheck(True) | ||
stereo.setExtendedDisparity(True) | ||
spatialLocationCalculator.inputConfig.setWaitForMessage(False) | ||
|
||
# Create 10 ROIs | ||
for i in range(10): | ||
config = dai.SpatialLocationCalculatorConfigData() | ||
config.depthThresholds.lowerThreshold = 200 | ||
config.depthThresholds.upperThreshold = 10000 | ||
config.roi = dai.Rect(dai.Point2f(i*0.1, 0.45), dai.Point2f((i+1)*0.1, 0.55)) | ||
spatialLocationCalculator.initialConfig.addROI(config) | ||
|
||
# Linking | ||
monoLeft.out.link(stereo.left) | ||
monoRight.out.link(stereo.right) | ||
|
||
spatialLocationCalculator.passthroughDepth.link(xoutDepth.input) | ||
stereo.depth.link(spatialLocationCalculator.inputDepth) | ||
|
||
spatialLocationCalculator.out.link(xoutSpatialData.input) | ||
xinSpatialCalcConfig.out.link(spatialLocationCalculator.inputConfig) | ||
|
||
# Connect to device and start pipeline | ||
with dai.Device(pipeline) as device: | ||
device.setIrLaserDotProjectorBrightness(1000) | ||
|
||
# Output queue will be used to get the depth frames from the outputs defined above | ||
depthQueue = device.getOutputQueue(name="depth", maxSize=4, blocking=False) | ||
spatialCalcQueue = device.getOutputQueue(name="spatialData", maxSize=4, blocking=False) | ||
color = (0,200,40) | ||
fontType = cv2.FONT_HERSHEY_TRIPLEX | ||
|
||
while True: | ||
inDepth = depthQueue.get() # Blocking call, will wait until a new data has arrived | ||
|
||
depthFrame = inDepth.getFrame() # depthFrame values are in millimeters | ||
|
||
depthFrameColor = cv2.normalize(depthFrame, None, 255, 0, cv2.NORM_INF, cv2.CV_8UC1) | ||
depthFrameColor = cv2.equalizeHist(depthFrameColor) | ||
depthFrameColor = cv2.applyColorMap(depthFrameColor, cv2.COLORMAP_HOT) | ||
|
||
spatialData = spatialCalcQueue.get().getSpatialLocations() | ||
for depthData in spatialData: | ||
roi = depthData.config.roi | ||
roi = roi.denormalize(width=depthFrameColor.shape[1], height=depthFrameColor.shape[0]) | ||
|
||
xmin = int(roi.topLeft().x) | ||
ymin = int(roi.topLeft().y) | ||
xmax = int(roi.bottomRight().x) | ||
ymax = int(roi.bottomRight().y) | ||
|
||
coords = depthData.spatialCoordinates | ||
distance = math.sqrt(coords.x ** 2 + coords.y ** 2 + coords.z ** 2) | ||
|
||
cv2.rectangle(depthFrameColor, (xmin, ymin), (xmax, ymax), color, thickness=2) | ||
cv2.putText(depthFrameColor, "{:.1f}m".format(distance/1000), (xmin + 10, ymin + 20), fontType, 0.6, color) | ||
# Show the frame | ||
cv2.imshow("depth", depthFrameColor) | ||
|
||
if cv2.waitKey(1) == ord('q'): | ||
break |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import depthai as dai | ||
from typing import List | ||
|
||
print('Searching for all available devices...\n') | ||
# Query all available devices (USB and POE OAK cameras) | ||
infos: List[dai.DeviceInfo] = dai.DeviceBootloader.getAllAvailableDevices() | ||
|
||
if len(infos) == 0: | ||
print("Couldn't find any available devices.") | ||
exit(-1) | ||
|
||
|
||
for info in infos: | ||
# Converts enum eg. 'XLinkDeviceState.X_LINK_UNBOOTED' to 'UNBOOTED' | ||
state = str(info.state).split('X_LINK_')[1] | ||
|
||
print(f"Found device '{info.name}', MxId: '{info.mxid}', State: '{state}'") | ||
|
||
|
||
# Connect to a specific device. We will just take the first one | ||
print(f"\nBooting the first available camera ({infos[0].name})...") | ||
with dai.Device(dai.Pipeline(), infos[0], usb2Mode=False) as device: | ||
print("Available camera sensors: ", device.getCameraSensorNames()) | ||
calib = device.readCalibration() | ||
eeprom = calib.getEepromData() | ||
print(f"Product name: {eeprom.productName}, board name {eeprom.boardName}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.