diff --git a/depthai-core b/depthai-core index d6883a576..7cd031a48 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit d6883a576de5f57d3354d7e04791f148ad544a55 +Subproject commit 7cd031a487f8c96264e2746638ca4d3d69f4747f diff --git a/docs/source/samples/calibration_flash.rst b/docs/source/samples/calibration_flash.rst new file mode 100644 index 000000000..fa8313b1d --- /dev/null +++ b/docs/source/samples/calibration_flash.rst @@ -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 `__ + + .. literalinclude:: ../../../examples/calibration_flash.py + :language: python + :linenos: + + .. tab:: C++ + + Also `available on GitHub `__ + + .. literalinclude:: ../../../depthai-core/examples/src/calibration_flash.cpp + :language: cpp + :linenos: + +.. include:: /includes/footer-short.rst diff --git a/docs/source/samples/calibration_flash_v5.rst b/docs/source/samples/calibration_flash_v5.rst new file mode 100644 index 000000000..165b55339 --- /dev/null +++ b/docs/source/samples/calibration_flash_v5.rst @@ -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 `__ + + .. literalinclude:: ../../../examples/calibration_flash_v5.py + :language: python + :linenos: + + .. tab:: C++ + + Also `available on GitHub `__ + + .. literalinclude:: ../../../depthai-core/examples/src/calibration_flash_v5.cpp + :language: cpp + :linenos: + +.. include:: /includes/footer-short.rst diff --git a/docs/source/samples/calibration_load.rst b/docs/source/samples/calibration_load.rst new file mode 100644 index 000000000..0d38e9516 --- /dev/null +++ b/docs/source/samples/calibration_load.rst @@ -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 `__ + + .. literalinclude:: ../../../examples/calibration_load.py + :language: python + :linenos: + + .. tab:: C++ + + Also `available on GitHub `__ + + .. literalinclude:: ../../../depthai-core/examples/src/calibration_load.cpp + :language: cpp + :linenos: + +.. include:: /includes/footer-short.rst diff --git a/docs/source/samples/calibration_reader.rst b/docs/source/samples/calibration_reader.rst new file mode 100644 index 000000000..6677dda7a --- /dev/null +++ b/docs/source/samples/calibration_reader.rst @@ -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 `__ + + .. literalinclude:: ../../../examples/calibration_reader.py + :language: python + :linenos: + + .. tab:: C++ + + Also `available on GitHub `__ + + .. literalinclude:: ../../../depthai-core/examples/src/calibration_reader.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 0ea110833..68cae2c2f 100644 --- a/docs/source/tutorials/code_samples.rst +++ b/docs/source/tutorials/code_samples.rst @@ -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 \ No newline at end of file +- :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 diff --git a/docs/source/tutorials/mixed_samples.rst b/docs/source/tutorials/mixed_samples.rst index 5168fb9ed..32507c39a 100644 --- a/docs/source/tutorials/mixed_samples.rst +++ b/docs/source/tutorials/mixed_samples.rst @@ -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 \ No newline at end of file +- :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 diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 6ba5720d1..114f7aa4e 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -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) \ No newline at end of file +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) \ No newline at end of file diff --git a/examples/calibration_flash.py b/examples/calibration_flash.py index 1cea1c3c7..a22abbd52 100755 --- a/examples/calibration_flash.py +++ b/examples/calibration_flash.py @@ -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!!') \ No newline at end of file + print('Calibration Flash Failed!!!') diff --git a/examples/calibration_flash_v5.py b/examples/calibration_flash_v5.py index 351901bcf..56777ebb4 100755 --- a/examples/calibration_flash_v5.py +++ b/examples/calibration_flash_v5.py @@ -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!!') \ No newline at end of file + print('Calibration Flash Failed!!!') diff --git a/examples/calibration_load.py b/examples/calibration_load.py index 624511a6b..7ef2653ad 100755 --- a/examples/calibration_load.py +++ b/examples/calibration_load.py @@ -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 \ No newline at end of file + break diff --git a/examples/calibration_reader.py b/examples/calibration_reader.py index d59f60bd7..14d069744 100755 --- a/examples/calibration_reader.py +++ b/examples/calibration_reader.py @@ -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)