Skip to content

Commit

Permalink
Merge branch 'release_2.17.4.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
themarpe committed Sep 19, 2022
2 parents ee39813 + 2b35be1 commit 844490e
Show file tree
Hide file tree
Showing 17 changed files with 359 additions and 32 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ endif()

# Pybindings project
set(TARGET_NAME depthai)
project(depthai VERSION "1") # revision of bindings [depthai-core].[rev]
project(depthai VERSION "0") # revision of bindings [depthai-core].[rev]

# Set default build type depending on context
set(default_build_type "Release")
Expand Down
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
57 changes: 57 additions & 0 deletions docs/source/samples/host_side/device_information.rst
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
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ add_python_example(spatial_object_tracker ObjectTracker/spatial_object_tracker.p

## Script
add_python_example(script_camera_control Script/script_camera_control.py)
add_python_example(script_json_communication Script/script_json_communication.py)
add_python_example(script_get_device_info Script/script_get_device_info.py)

## SpatialDetection
add_python_example(spatial_tiny_yolo_v3 SpatialDetection/spatial_tiny_yolo.py yolo3)
Expand Down
30 changes: 30 additions & 0 deletions examples/Script/script_get_device_info.py
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))
3 changes: 1 addition & 2 deletions examples/Script/script_get_ip.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python3
import depthai as dai

# MAKE SURE U HAVE LATEST BOOTLOADER KTNXBAI
# Start defining a pipeline
pipeline = dai.Pipeline()

Expand All @@ -23,7 +22,7 @@ def get_ip_address(ifname):
ip = get_ip_address('re0') # '192.168.0.110'
node.warn(f'IP of the device: {ip}')
node.io['end'].send(Buffer())
node.io['end'].send(Buffer(32))
""")

xout = pipeline.create(dai.node.XLinkOut)
Expand Down
2 changes: 1 addition & 1 deletion examples/Script/script_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
data1 = r1.read()
node.warn(f'Public IP: {data1}')
node.io['end'].send(Buffer())
node.io['end'].send(Buffer(32))
""")

xout = pipeline.create(dai.node.XLinkOut)
Expand Down
91 changes: 91 additions & 0 deletions examples/SpatialDetection/spatial_calculator_multi_roi.py
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 modified examples/calibration/calibration_dump.py
100644 → 100755
Empty file.
Empty file modified examples/calibration/calibration_factory_reset.py
100644 → 100755
Empty file.
26 changes: 26 additions & 0 deletions examples/host_side/device_information.py
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}")
1 change: 1 addition & 0 deletions src/CalibrationHandlerBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void CalibrationHandlerBindings::bind(pybind11::module& m, void* pCallstack){

.def("setBoardInfo", py::overload_cast<std::string, std::string>(&CalibrationHandler::setBoardInfo), py::arg("boardName"), py::arg("boardRev"), DOC(dai, CalibrationHandler, setBoardInfo))
.def("setBoardInfo", py::overload_cast<std::string, std::string, std::string, std::string, std::string, std::string, uint64_t, uint32_t, std::string>(&CalibrationHandler::setBoardInfo), py::arg("productName"), py::arg("boardName"), py::arg("boardRev"), py::arg("boardConf"), py::arg("hardwareConf"), py::arg("batchName"), py::arg("batchTime"), py::arg("boardOptions"), py::arg("boardCustom") = "", DOC(dai, CalibrationHandler, setBoardInfo, 2))
.def("setProductName", &CalibrationHandler::setProductName, py::arg("productName"), DOC(dai, CalibrationHandler, setProductName))

.def("setCameraIntrinsics", py::overload_cast<CameraBoardSocket, std::vector<std::vector<float>>, Size2f>(&CalibrationHandler::setCameraIntrinsics), py::arg("cameraId"), py::arg("intrinsics"), py::arg("frameSize"), DOC(dai, CalibrationHandler, setCameraIntrinsics))
.def("setCameraIntrinsics", py::overload_cast<CameraBoardSocket, std::vector<std::vector<float>>, int, int>(&CalibrationHandler::setCameraIntrinsics), py::arg("cameraId"), py::arg("intrinsics"), py::arg("width"), py::arg("height"), DOC(dai, CalibrationHandler, setCameraIntrinsics, 2))
Expand Down
8 changes: 5 additions & 3 deletions src/DeviceBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ void DeviceBindings::bind(pybind11::module& m, void* pCallstack){
d.close();
})
.def("close", [](DeviceBase& d) { py::gil_scoped_release release; d.close(); }, "Closes the connection to device. Better alternative is the usage of context manager: `with depthai.Device(pipeline) as device:`")
.def("isClosed", [](DeviceBase& d) { py::gil_scoped_release release; d.isClosed(); }, DOC(dai, DeviceBase, isClosed))
.def("isClosed", [](DeviceBase& d) { py::gil_scoped_release release; return d.isClosed(); }, DOC(dai, DeviceBase, isClosed))

//dai::Device methods
//static
Expand Down Expand Up @@ -498,8 +498,8 @@ void DeviceBindings::bind(pybind11::module& m, void* pCallstack){
.def("flashCalibration", [](DeviceBase& d, CalibrationHandler calibrationDataHandler) { py::gil_scoped_release release; return d.flashCalibration(calibrationDataHandler); }, py::arg("calibrationDataHandler"), DOC(dai, DeviceBase, flashCalibration))
.def("setXLinkChunkSize", [](DeviceBase& d, int s) { py::gil_scoped_release release; d.setXLinkChunkSize(s); }, py::arg("sizeBytes"), DOC(dai, DeviceBase, setXLinkChunkSize))
.def("getXLinkChunkSize", [](DeviceBase& d) { py::gil_scoped_release release; return d.getXLinkChunkSize(); }, DOC(dai, DeviceBase, getXLinkChunkSize))
.def("setIrLaserDotProjectorBrightness", [](DeviceBase& d, float m, int mask) { py::gil_scoped_release release; d.setIrLaserDotProjectorBrightness(m, mask); }, py::arg("mA"), py::arg("mask") = -1, DOC(dai, DeviceBase, setIrLaserDotProjectorBrightness))
.def("setIrFloodLightBrightness", [](DeviceBase& d, float m, int mask) { py::gil_scoped_release release; d.setIrFloodLightBrightness(m, mask); }, py::arg("mA"), py::arg("mask") = -1, DOC(dai, DeviceBase, setIrFloodLightBrightness))
.def("setIrLaserDotProjectorBrightness", [](DeviceBase& d, float m, int mask) { py::gil_scoped_release release; return d.setIrLaserDotProjectorBrightness(m, mask); }, py::arg("mA"), py::arg("mask") = -1, DOC(dai, DeviceBase, setIrLaserDotProjectorBrightness))
.def("setIrFloodLightBrightness", [](DeviceBase& d, float m, int mask) { py::gil_scoped_release release; return d.setIrFloodLightBrightness(m, mask); }, py::arg("mA"), py::arg("mask") = -1, DOC(dai, DeviceBase, setIrFloodLightBrightness))
.def("getIrDrivers", [](DeviceBase& d) { py::gil_scoped_release release; return d.getIrDrivers(); }, DOC(dai, DeviceBase, getIrDrivers))
.def("isEepromAvailable", [](DeviceBase& d) { py::gil_scoped_release release; return d.isEepromAvailable(); }, DOC(dai, DeviceBase, isEepromAvailable))
.def("flashCalibration2", [](DeviceBase& d, CalibrationHandler ch) { py::gil_scoped_release release; return d.flashCalibration2(ch); }, DOC(dai, DeviceBase, flashCalibration2))
Expand All @@ -511,6 +511,8 @@ void DeviceBindings::bind(pybind11::module& m, void* pCallstack){
.def("readFactoryCalibrationOrDefault", [](DeviceBase& d) { py::gil_scoped_release release; return d.readFactoryCalibrationOrDefault(); }, DOC(dai, DeviceBase, readFactoryCalibrationOrDefault))
.def("readCalibrationRaw", [](DeviceBase& d) { py::gil_scoped_release release; return d.readCalibrationRaw(); }, DOC(dai, DeviceBase, readCalibrationRaw))
.def("readFactoryCalibrationRaw", [](DeviceBase& d) { py::gil_scoped_release release; return d.readFactoryCalibrationRaw(); }, DOC(dai, DeviceBase, readFactoryCalibrationRaw))
.def("flashEepromClear", [](DeviceBase& d) { py::gil_scoped_release release; d.flashEepromClear(); }, DOC(dai, DeviceBase, flashEepromClear))
.def("flashFactoryEepromClear", [](DeviceBase& d) { py::gil_scoped_release release; d.flashFactoryEepromClear(); }, DOC(dai, DeviceBase, flashFactoryEepromClear))
;


Expand Down
Loading

0 comments on commit 844490e

Please sign in to comment.