Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions docs/source/samples/calibration_flash.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Calibration Flash
=================

This example shows how to flash calibration data of version 6 (gen2 calibration data) to the device.

.. rubric:: Similiar samples:

- :ref:`Calibration Flash v5`
- :ref:`Calibration Reader`
- :ref:`Calibration Load`

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/calibration_flash.py>`__

.. literalinclude:: ../../../examples/calibration_flash.py
:language: python
:linenos:

.. tab:: C++

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

.. literalinclude:: ../../../depthai-core/examples/src/calibration_flash.cpp
:language: cpp
:linenos:

.. include:: /includes/footer-short.rst
38 changes: 38 additions & 0 deletions docs/source/samples/calibration_flash_v5.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Calibration Flash v5
====================

This example shows how to flash calibration data of version 5 (gen1 calibration data) to the device.

.. rubric:: Similiar samples:

- :ref:`Calibration Flash`
- :ref:`Calibration Reader`
- :ref:`Calibration Load`

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/calibration_flash_v5.py>`__

.. literalinclude:: ../../../examples/calibration_flash_v5.py
:language: python
:linenos:

.. tab:: C++

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

.. literalinclude:: ../../../depthai-core/examples/src/calibration_flash_v5.cpp
:language: cpp
:linenos:

.. include:: /includes/footer-short.rst
38 changes: 38 additions & 0 deletions docs/source/samples/calibration_load.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Calibration Load
================

This example shows how to load and use calibration data of version6 (gen2 calibration data) in a pipeline.

.. rubric:: Similiar samples:

- :ref:`Calibration Flash v5`
- :ref:`Calibration Flash`
- :ref:`Calibration Reader`

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/calibration_load.py>`__

.. literalinclude:: ../../../examples/calibration_load.py
:language: python
:linenos:

.. tab:: C++

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

.. literalinclude:: ../../../depthai-core/examples/src/calibration_load.cpp
:language: cpp
:linenos:

.. include:: /includes/footer-short.rst
38 changes: 38 additions & 0 deletions docs/source/samples/calibration_reader.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Calibration Reader
==================

This example shows how to read calibration data stored on device over XLink.

.. rubric:: Similiar samples:

- :ref:`Calibration Flash v5`
- :ref:`Calibration Flash`
- :ref:`Calibration Load`

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/calibration_reader.py>`__

.. literalinclude:: ../../../examples/calibration_reader.py
:language: python
:linenos:

.. tab:: C++

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

.. literalinclude:: ../../../depthai-core/examples/src/calibration_reader.cpp
:language: cpp
:linenos:

.. include:: /includes/footer-short.rst
6 changes: 5 additions & 1 deletion docs/source/tutorials/code_samples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@ Code samples are used for automated testing. They are also a great starting poin
- :ref:`System information` - Displays device system information (memory/cpu usage, temperature)
- :ref:`OpenCV support` - Demonstrates how to retrieve an image frame as an OpenCV frame
- :ref:`Device Queue Event` - Demonstrates how to use device queue events
- :ref:`Queue add callback` - Demonstrates how to use queue callbacks
- :ref:`Queue add callback` - Demonstrates how to use queue callbacks
- :ref:`Calibration Flash v5` - Demonstrates how to flash calibration data of version 5 (gen1 calibration data) to the device
- :ref:`Calibration Flash` - Demonstrates how to flash calibration data of version 6 (gen2 calibration data) to the device
- :ref:`Calibration Reader` - Demonstrates how to read calibration data stored on device over XLink
- :ref:`Calibration Load` - Demonstrates how to load and use calibration data of version6 (gen2 calibration data) in a pipeline
10 changes: 9 additions & 1 deletion docs/source/tutorials/mixed_samples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ Mixed
../samples/opencv_support.rst
../samples/device_queue_event.rst
../samples/queue_add_callback.rst
../samples/calibration_flash_v5.rst
../samples/calibration_flash.rst
../samples/calibration_reader.rst
../samples/calibration_load.rst

- :ref:`System information` - Displays device system information (memory/cpu usage, temperature)
- :ref:`OpenCV support` - Demonstrates how to retrieve an image frame as an OpenCV frame
- :ref:`Device Queue Event` - Demonstrates how to use device queue events
- :ref:`Queue add callback` - Demonstrates how to use queue callbacks
- :ref:`Queue add callback` - Demonstrates how to use queue callbacks
- :ref:`Calibration Flash v5` - Demonstrates how to flash calibration data of version 5 (gen1 calibration data) to the device
- :ref:`Calibration Flash` - Demonstrates how to flash calibration data of version 6 (gen2 calibration data) to the device
- :ref:`Calibration Reader` - Demonstrates how to read calibration data stored on device over XLink
- :ref:`Calibration Load` - Demonstrates how to load and use calibration data of version6 (gen2 calibration data) in a pipeline
6 changes: 5 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,8 @@ add_python_example(object_tracker_video object_tracker_video.py)
add_python_example(stereo_depth_from_host stereo_depth_from_host.py)
add_python_example(stereo_depth_video stereo_depth_video.py)
add_python_example(imu_gyroscope_accelerometer imu_gyroscope_accelerometer.py)
add_python_example(imu_rotation_vector imu_rotation_vector.py)
add_python_example(imu_rotation_vector imu_rotation_vector.py)
add_python_example(calibration_flash_v5 calibration_flash_v5.py)
add_python_example(calibration_flash calibration_flash.py)
add_python_example(calibration_load calibration_load.py)
add_python_example(calibration_reader calibration_reader.py)
17 changes: 9 additions & 8 deletions examples/calibration_flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@
import depthai as dai
import argparse


# Connect Device
calibJsonFile = str((Path(__file__).parent / Path('models/depthai_calib.json')).resolve().absolute())
calibBackupfile = str((Path(__file__).parent / Path('depthai_calib_backup.json')).resolve().absolute())
calibBackUpFile = str((Path(__file__).parent / Path('depthai_calib_backup.json')).resolve().absolute())

parser = argparse.ArgumentParser()
parser.add_argument('calibJsonFile', nargs='?', help="Path to V6 calibration file in json", default=calibJsonFile)
args = parser.parse_args()

# Connect device
with dai.Device() as device:

deviceCalib = device.readCalibration()
deviceCalib.eepromToJsonFile(calibBackupfile)
deviceCalib.eepromToJsonFile(calibBackUpFile)
print("Calibration Data on the device is backed up at:")
print(calibBackupfile)
calibData = dai.CalibrationHandler(args.calibJsonFile);
print(calibBackUpFile)
calibData = dai.CalibrationHandler(args.calibJsonFile)

status = device.flashCalibration(calibData)
if status:
print('Calibration write succesfull')
print('Calibration Flash Successful')
else:
print('Calibration Flash Failed!!')
print('Calibration Flash Failed!!!')
17 changes: 9 additions & 8 deletions examples/calibration_flash_v5.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@
import depthai as dai
import argparse


# Connect Device
boardConfigFile = str((Path(__file__).parent / Path('models/BW1098OBC.json')).resolve().absolute())
calibBinaryFile = str((Path(__file__).parent / Path('models/depthai_v5.calib')).resolve().absolute())
calibBackupfile = str((Path(__file__).parent / Path('depthai_calib_backup.json')).resolve().absolute())
calibBackUpFile = str((Path(__file__).parent / Path('depthai_calib_backup.json')).resolve().absolute())

parser = argparse.ArgumentParser()
parser.add_argument('boardConfigFile', nargs='?', help="Path to board config file", default=boardConfigFile)
parser.add_argument('calibBinaryFile', nargs='?', help="Path to version 5 .calib file", default=calibBinaryFile)
args = parser.parse_args()

# Connect device
with dai.Device() as device:

deviceCalib = device.readCalibration()
deviceCalib.eepromToJsonFile(calibBackupfile)
deviceCalib.eepromToJsonFile(calibBackUpFile)
print("Calibration Data on the device is backed up at:")
print(calibBackupfile)
calibData = dai.CalibrationHandler(args.calibBinaryFile, args.boardConfigFile);
print(calibBackUpFile)
calibData = dai.CalibrationHandler(args.calibBinaryFile, args.boardConfigFile)

status = device.flashCalibration(calibData)
if status:
print('Calibration write succesful')
print('Calibration Flash Successful')
else:
print('Calibration Flash Failed!!')
print('Calibration Flash Failed!!!')
62 changes: 31 additions & 31 deletions examples/calibration_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,50 @@
import numpy as np
import cv2

def createStereoPipeline():
p = dai.Pipeline()

monoLeft = p.createMonoCamera();
monoRight = p.createMonoCamera();
stereo = p.createStereoDepth();
xoutDepth = p.createXLinkOut();
xoutDepth.setStreamName("depth");

# MonoCamera
monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P);
monoLeft.setBoardSocket(dai.CameraBoardSocket.LEFT);
# monoLeft.setFps(5.0);
monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P);
monoRight.setBoardSocket(dai.CameraBoardSocket.RIGHT);
# monoRight.setFps(5.0);

monoLeft.out.link(stereo.left);
monoRight.out.link(stereo.right);
stereo.depth.link(xoutDepth.input);

return p;

# Connect Device
calibJsonFile = str((Path(__file__).parent / Path('models/depthai_calib.json')).resolve().absolute())

parser = argparse.ArgumentParser()
parser.add_argument('calibJsonFile', nargs='?', help="Path to V6 calibration file in json", default=calibJsonFile)
args = parser.parse_args()

calibData = dai.CalibrationHandler(args.calibJsonFile)

calibData = dai.CalibrationHandler(args.calibJsonFile);
pipeline = createStereoPipeline()
# Create pipeline
pipeline = dai.Pipeline()
pipeline.setCalibrationData(calibData)

with dai.Device() as device:
device.startPipeline(pipeline)
q = device.getOutputQueue(name="depth", maxSize=4, blocking=False)
# Define sources and output
monoLeft = pipeline.createMonoCamera()
monoRight = pipeline.createMonoCamera()
stereo = pipeline.createStereoDepth()
xoutDepth = pipeline.createXLinkOut()
xoutDepth.setStreamName("depth")

# MonoCamera
monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)
monoLeft.setBoardSocket(dai.CameraBoardSocket.LEFT)
# monoLeft.setFps(5.0)
monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)
monoRight.setBoardSocket(dai.CameraBoardSocket.RIGHT)
# monoRight.setFps(5.0)

# Linking
monoLeft.out.link(stereo.left)
monoRight.out.link(stereo.right)
stereo.depth.link(xoutDepth.input)

# Connect to device and start pipeline
with dai.Device(pipeline) as device:

depthQueue = device.getOutputQueue(name="depth", maxSize=4, blocking=False)

while True:
inDepth = q.get() # blocking call, will wait until a new data has arrived
# blocking call, will wait until a new data has arrived
inDepth = depthQueue.get()
frame = inDepth.getFrame()

# frame is ready to be shown
cv2.imshow("depth", frame)

if cv2.waitKey(1) == ord('q'):
break
break
30 changes: 15 additions & 15 deletions examples/calibration_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,28 @@
import time
import argparse


# Connect Device
with dai.Device() as device:
calibObj = device.readCalibration()
M_rgb, width, height = np.array(calibObj.getDefaultIntrinsics(dai.CameraBoardSocket.RGB))

calibData = device.readCalibration()
M_rgb, width, height = np.array(calibData.getDefaultIntrinsics(dai.CameraBoardSocket.RGB))
print("RGB Camera Default intrinsics...")
print(M_rgb)
print(width)
print(height)
M_left = np.array(calibObj.getCameraIntrinsics(dai.CameraBoardSocket.LEFT, 1280, 720))

M_left = np.array(calibData.getCameraIntrinsics(dai.CameraBoardSocket.LEFT, 1280, 720))
print("LEFT Camera resized intrinsics...")
print(M_left)
R1 = np.array(calibObj.getStereoLeftRectificationRotation())
R2 = np.array(calibObj.getStereoRightRectificationRotation())
M_right = np.array(calibObj.getCameraIntrinsics(calibObj.getStereoRightCameraId(), 1280, 720))
print(M_left)

R1 = np.array(calibData.getStereoLeftRectificationRotation())
R2 = np.array(calibData.getStereoRightRectificationRotation())
M_right = np.array(calibData.getCameraIntrinsics(calibData.getStereoRightCameraId(), 1280, 720))

H_left = np.matmul(np.matmul(M_right, R1), np.linalg.inv(M_left))
print("LEFT Camera stereo rectification matrix...")
print(H_left)
lr_extrinsics = np.array(calibObj.getCameraExtrinsics(dai.CameraBoardSocket.LEFT, dai.CameraBoardSocket.RIGHT))
print(H_left)

lr_extrinsics = np.array(calibData.getCameraExtrinsics(dai.CameraBoardSocket.LEFT, dai.CameraBoardSocket.RIGHT))
print("Transformation matrix of where left Camera is W.R.T right Camera's optical center")
print(lr_extrinsics)
print(lr_extrinsics)