Skip to content

Commit cef618c

Browse files
authored
Merge pull request #1242 from luxonis/v3_develop
Adding support for RVC4
2 parents 1185303 + 6bc315e commit cef618c

4 files changed

Lines changed: 101 additions & 26 deletions

File tree

calibrate.py

Lines changed: 97 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
11
#!/usr/bin/env python3
2+
from datetime import datetime, timedelta
3+
from argparse import ArgumentParser
4+
from collections import deque
5+
from pathlib import Path
6+
import itertools
7+
import traceback
28
import argparse
9+
310
import json
4-
from pydoc import render_doc
511
import shutil
6-
import traceback
7-
from argparse import ArgumentParser
8-
from pathlib import Path
12+
913
import time
10-
from datetime import datetime, timedelta
11-
from collections import deque
12-
from scipy.spatial.transform import Rotation
13-
import traceback
14-
import itertools
1514
import math
1615

1716
import cv2
18-
from cv2 import resize
17+
import sys
18+
import os
19+
20+
def check_opencv_version(REQUIRED_VERSION = "4.5.5"):
21+
installed = cv2.__version__
22+
if installed != REQUIRED_VERSION:
23+
print(f"[ERROR] OpenCV version mismatch!")
24+
print(f"Installed: {installed}")
25+
print(f"Required : {REQUIRED_VERSION}")
26+
print("Please re-run:")
27+
print(" pip install -r calib_requirements.txt")
28+
sys.exit(1)
29+
else:
30+
print(f"[OK] OpenCV version {installed} is correct.")
31+
32+
check_opencv_version()
33+
1934
import depthai as dai
2035
import numpy as np
21-
import copy
36+
from packaging import version
37+
import sys
2238

2339
import depthai_calibration.calibration_utils as calibUtils
2440

@@ -166,6 +182,8 @@ def parse_args():
166182
help="Enable the display of polynoms.")
167183
parser.add_argument('-dbg', '--debugProcessingMode', default=False, action="store_true",
168184
help="Enable processing of images without using the camera.")
185+
parser.add_argument('-v3', '--useDepthaiV3', default=True, action="store_true",
186+
help="Use depthai v3.")
169187
options = parser.parse_args()
170188
# Set some extra defaults, `-brd` would override them
171189
if options.defaultBoard is not None:
@@ -351,6 +369,7 @@ class Main:
351369

352370
def __init__(self):
353371
self.args = parse_args()
372+
self.args.useDepthaiV3 = version.parse(dai.__version__) >= version.parse("3.0.0")
354373
self.traceLevel= self.args.traceLevel
355374
self.output_scale_factor = self.args.outputScaleFactor
356375
self.aruco_dictionary = cv2.aruco.Dictionary_get(
@@ -462,14 +481,25 @@ def mouse_event_callback(self, event, x, y, flags, param):
462481
self.mouseTrigger = True
463482

464483
def startPipeline(self):
465-
pipeline = self.create_pipeline()
466-
self.device.startPipeline(pipeline)
467-
468-
self.camera_queue = {}
469-
for config_cam in self.board_config['cameras']:
470-
cam = self.board_config['cameras'][config_cam]
471-
if cam["name"] not in self.args.disableCamera:
472-
self.camera_queue[cam['name']] = self.device.getOutputQueue(cam['name'], 1, False)
484+
if version.parse(dai.__version__) < version.parse("3.0.0"):
485+
if str(self.device.getDeviceInfo().platform) != "XLinkPlatform.X_LINK_MYRIAD_X":
486+
sys.exit(
487+
f"ERROR: RVC4 device detected, but DepthAI version {dai.__version__} is installed.\n"
488+
"RVC4 is NOT supported on DepthAI 2.x.\n\n"
489+
"Please upgrade to the latest DepthAI:\n"
490+
" pip install depthai --upgrade --force-reinstall\n"
491+
)
492+
pipeline = self.create_pipeline()
493+
self.device.startPipeline(pipeline)
494+
self.camera_queue = {}
495+
for config_cam in self.board_config['cameras']:
496+
cam = self.board_config['cameras'][config_cam]
497+
if cam["name"] not in self.args.disableCamera:
498+
self.camera_queue[cam['name']] = self.device.getOutputQueue(cam['name'], 1, False)
499+
else:
500+
pipeline = self.create_pipeline_v3()
501+
pipeline.start()
502+
self.pipeline = pipeline
473503

474504
def is_markers_found(self, frame):
475505
marker_corners, _, _ = cv2.aruco.detectMarkers(
@@ -579,6 +609,42 @@ def create_pipeline(self):
579609

580610
return pipeline
581611

612+
def create_pipeline_v3(self):
613+
pipeline = dai.Pipeline(self.device)
614+
self.camera_queue = {}
615+
fps = self.args.framerate
616+
sync = pipeline.create(dai.node.Sync)
617+
sync.setSyncThreshold(timedelta(milliseconds=50))
618+
for cam_id in self.board_config['cameras']:
619+
cam_info = self.board_config['cameras'][cam_id]
620+
if cam_info["name"] not in self.args.disableCamera:
621+
if cam_info['type'] == 'mono':
622+
cam_node = pipeline.create(dai.node.Camera, fps = fps).build(stringToCam[cam_id])
623+
cam_output = cam_node.requestFullResolutionOutput(type=dai.ImgFrame.Type.NV12)
624+
cam_output.link(sync.inputs[cam_info["name"]])
625+
self.camera_queue[cam_info['name']] = cam_output
626+
sensorName = cam_info['sensorName']
627+
print(f'Sensor name for {cam_info["name"]} is {sensorName}')
628+
else:
629+
cam_node = pipeline.create(dai.node.Camera, fps = fps).build(stringToCam[cam_id])
630+
self.camera_queue[cam_info['name']] = cam_node.requestFullResolutionOutput(type=dai.ImgFrame.Type.NV12).link(sync.inputs[cam_info["name"]])
631+
if cam_info['sensorName'] == "OV9*82":
632+
cam_node.initialControl.setSharpness(0)
633+
cam_node.initialControl.setLumaDenoise(0)
634+
cam_node.initialControl.setChromaDenoise(4)
635+
636+
if cam_info['hasAutofocus']:
637+
if self.args.rgbLensPosition:
638+
cam_node.initialControl.setManualFocus(int(self.args.rgbLensPosition[stringToCam[cam_id].name.lower()]))
639+
else:
640+
cam_node.initialControl.setManualFocusRaw(int(135 / 255))
641+
642+
self.control_queue = cam_node.inputControl.createInputQueue()
643+
sensorName = cam_info['sensorName']
644+
print(f'Sensor name for {cam_info["name"]} is {sensorName}')
645+
#cam_node.initialControl.setAntiBandingMode(antibandingOpts[self.args.antibanding])
646+
self.sync_queue = sync.out.createOutputQueue()
647+
return pipeline
582648

583649
def parse_frame(self, frame, stream_name):
584650
if not self.is_markers_found(frame):
@@ -717,14 +783,19 @@ def capture_images_sync(self):
717783
sync_trys = 0
718784
while not finished:
719785
currImageList = {}
786+
if self.args.useDepthaiV3:
787+
msg_group = self.sync_queue.get()
720788
for key in self.camera_queue.keys():
721-
frameMsg = self.camera_queue[key].get()
789+
if self.args.useDepthaiV3:
790+
frameMsg = msg_group[key]
791+
else:
792+
frameMsg = self.camera_queue[key].get()
722793

723794
#print(f'Timestamp of {key} is {frameMsg.getTimestamp()}')
724795

725796
syncCollector.add_msg(key, frameMsg)
726797
color_frame = None
727-
if frameMsg.getType() in [dai.RawImgFrame.Type.RAW8, dai.RawImgFrame.Type.GRAY8] :
798+
if not self.args.useDepthaiV3 and frameMsg.getType() in [dai.RawImgFrame.Type.RAW8, dai.RawImgFrame.Type.GRAY8] :
728799
color_frame = cv2.cvtColor(frameMsg.getCvFrame(), cv2.COLOR_GRAY2BGR)
729800
else:
730801
color_frame = frameMsg.getCvFrame()
@@ -1082,7 +1153,10 @@ def calibrate(self):
10821153
print(f'EEPROM VERSION being flashed is -> {eeepromData.version}')
10831154
eeepromData.version = 7
10841155
print(f'EEPROM VERSION being flashed is -> {eeepromData.version}')
1085-
mx_serial_id = self.device.getDeviceInfo().getMxId()
1156+
if not self.args.useDepthaiV3:
1157+
mx_serial_id = self.device.getDeviceInfo().getMxId()
1158+
else:
1159+
mx_serial_id = self.device.getDeviceId()
10861160
date_time_string = datetime.now().strftime("_%m_%d_%y_%H_%M")
10871161
file_name = mx_serial_id + date_time_string
10881162
calib_dest_path = dest_path + '/' + file_name + '.json'
@@ -1091,7 +1165,7 @@ def calibrate(self):
10911165
Path(self.args.saveCalibPath).parent.mkdir(parents=True, exist_ok=True)
10921166
calibration_handler.eepromToJsonFile(self.args.saveCalibPath)
10931167
# try:
1094-
self.device.flashCalibration2(calibration_handler)
1168+
self.device.flashCalibration(calibration_handler)
10951169
is_write_succesful = True
10961170
# except RuntimeError as e:
10971171
# is_write_succesful = False

depthai_calibration

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ opencv-contrib-python==4.5.5.62 # Last successful RPi build, also covers M1 with
55
--extra-index-url https://artifacts.luxonis.com/artifactory/luxonis-depthai-data-local/wheels/
66
pyqt5>5,<5.15.6 ; platform_machine != "armv6l" and platform_machine != "armv7l" and platform_machine != "aarch64" and platform_machine != "arm64"
77
--extra-index-url https://artifacts.luxonis.com/artifactory/luxonis-python-snapshot-local/
8-
depthai==2.30.0.0
8+
depthai
9+
numpy>=1.26.4,<2.0.0 # For RPi Buster (last successful build) and macOS M1 (first build). But allow for higher versions, to support Python3.11 (not available in 1.21.4 yet)
910
Qt.py
1011
scipy
1112
matplotlib

resources/depthai_boards

Submodule depthai_boards updated 64 files

0 commit comments

Comments
 (0)