Skip to content

Commit

Permalink
Merge resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
asahtik committed Oct 30, 2023
2 parents b177b9d + aba784e commit 0eb95f1
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 20 deletions.
17 changes: 13 additions & 4 deletions examples/StereoDepth/stereo_depth_from_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
parser.add_argument("-e", "--evaluate", help="Evaluate the disparity calculation.", default=None)
parser.add_argument("-dumpdispcost", "--dumpdisparitycostvalues", action="store_true", help="Dumps the disparity cost values for each disparity range. 96 byte for each pixel.")
parser.add_argument("--download", action="store_true", help="Downloads the 2014 Middlebury dataset.")
parser.add_argument("--calibration", help="Path to calibration file", default=None)
parser.add_argument("--rectify", action="store_true", help="Enable rectified streams")
parser.add_argument("--swapLR", action="store_true", help="Swap left and right cameras.")
args = parser.parse_args()

if args.evaluate is not None and args.dataset is not None:
Expand Down Expand Up @@ -603,8 +606,12 @@ def __init__(self, config):
stereo.setRuntimeModeSwitch(True)

# Linking
monoLeft.out.link(stereo.left)
monoRight.out.link(stereo.right)
if(args.swapLR):
monoLeft.out.link(stereo.right)
monoRight.out.link(stereo.left)
else:
monoLeft.out.link(stereo.left)
monoRight.out.link(stereo.right)
xinStereoDepthConfig.out.link(stereo.inputConfig)
stereo.syncedLeft.link(xoutLeft.input)
stereo.syncedRight.link(xoutRight.input)
Expand All @@ -630,9 +637,11 @@ def __init__(self, config):
StereoConfigHandler.registerWindow("Stereo control panel")

# stereo.setPostProcessingHardwareResources(3, 3)

if(args.calibration):
calibrationHandler = dai.CalibrationHandler(args.calibration)
pipeline.setCalibrationData(calibrationHandler)
stereo.setInputResolution(width, height)
stereo.setRectification(False)
stereo.setRectification(args.rectify)
baseline = 75
fov = 71.86
focal = width / (2 * math.tan(fov / 2 / 180 * math.pi))
Expand Down
2 changes: 1 addition & 1 deletion examples/install_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def hasWhitespace(string):
if sys.version_info[0] == 3 and sys.version_info[1] == 9:
DEPENDENCIES.append('opencv-python!=4.5.4.58')
else:
DEPENDENCIES.append('opencv-contrib-python==4.5.5.62') # same as in depthai requirementx.txt
DEPENDENCIES.append('opencv-python')



Expand Down
23 changes: 23 additions & 0 deletions src/pipeline/datatype/CameraControlBindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ void bind_cameracontrol(pybind11::module& m, void* pCallstack){
py::enum_<RawCameraControl::AutoFocusMode> rawCameraControlAutoFocusMode(rawCameraControl, "AutoFocusMode", DOC(dai, RawCameraControl, AutoFocusMode));
py::enum_<RawCameraControl::AutoWhiteBalanceMode> rawCameraControlAutoWhiteBalanceMode(rawCameraControl, "AutoWhiteBalanceMode", DOC(dai, RawCameraControl, AutoWhiteBalanceMode));
py::enum_<RawCameraControl::SceneMode> rawCameraControlSceneMode(rawCameraControl, "SceneMode", DOC(dai, RawCameraControl, SceneMode));
py::enum_<RawCameraControl::ControlMode> rawCameraControlControlMode(rawCameraControl, "ControlMode", DOC(dai, RawCameraControl, ControlMode));
py::enum_<RawCameraControl::CaptureIntent> rawCameraControlCaptureIntent(rawCameraControl, "CaptureIntent", DOC(dai, RawCameraControl, CaptureIntent));
py::enum_<RawCameraControl::AntiBandingMode> rawCameraControlAntiBandingMode(rawCameraControl, "AntiBandingMode", DOC(dai, RawCameraControl, AntiBandingMode));
py::enum_<RawCameraControl::EffectMode> rawCameraControlEffectMode(rawCameraControl, "EffectMode", DOC(dai, RawCameraControl, EffectMode));
py::enum_<RawCameraControl::FrameSyncMode> rawCameraControlFrameSyncMode(rawCameraControl, "FrameSyncMode", DOC(dai, RawCameraControl, FrameSyncMode));
Expand Down Expand Up @@ -125,6 +127,23 @@ std::vector<const char *> camCtrlAttr;
.value("BARCODE", RawCameraControl::SceneMode::BARCODE)
;

camCtrlAttr.push_back("ControlMode");
rawCameraControlControlMode
.value("OFF", RawCameraControl::ControlMode::OFF)
.value("AUTO", RawCameraControl::ControlMode::AUTO)
.value("USE_SCENE_MODE", RawCameraControl::ControlMode::USE_SCENE_MODE)
;

camCtrlAttr.push_back("CaptureIntent");
rawCameraControlCaptureIntent
.value("CUSTOM", RawCameraControl::CaptureIntent::CUSTOM)
.value("PREVIEW", RawCameraControl::CaptureIntent::PREVIEW)
.value("STILL_CAPTURE", RawCameraControl::CaptureIntent::STILL_CAPTURE)
.value("VIDEO_RECORD", RawCameraControl::CaptureIntent::VIDEO_RECORD)
.value("VIDEO_SNAPSHOT", RawCameraControl::CaptureIntent::VIDEO_SNAPSHOT)
.value("ZERO_SHUTTER_LAG", RawCameraControl::CaptureIntent::ZERO_SHUTTER_LAG)
;

camCtrlAttr.push_back("AntiBandingMode");
rawCameraControlAntiBandingMode
.value("OFF", RawCameraControl::AntiBandingMode::OFF)
Expand Down Expand Up @@ -163,6 +182,8 @@ std::vector<const char *> camCtrlAttr;
.def_readwrite("awbMode", &RawCameraControl::awbMode)
.def_readwrite("sceneMode", &RawCameraControl::sceneMode)
.def_readwrite("antiBandingMode", &RawCameraControl::antiBandingMode)
.def_readwrite("captureIntent", &RawCameraControl::captureIntent)
.def_readwrite("controlMode", &RawCameraControl::controlMode)
.def_readwrite("effectMode", &RawCameraControl::effectMode)
.def_readwrite("aeLockMode", &RawCameraControl::aeLockMode)
.def_readwrite("awbLockMode", &RawCameraControl::awbLockMode)
Expand Down Expand Up @@ -214,6 +235,8 @@ std::vector<const char *> camCtrlAttr;
.def("setChromaDenoise", &CameraControl::setChromaDenoise, py::arg("value"), DOC(dai, CameraControl, setChromaDenoise))
.def("setSceneMode", &CameraControl::setSceneMode, py::arg("mode"), DOC(dai, CameraControl, setSceneMode))
.def("setEffectMode", &CameraControl::setEffectMode, py::arg("mode"), DOC(dai, CameraControl, setEffectMode))
.def("setControlMode", &CameraControl::setControlMode, py::arg("mode"), DOC(dai, CameraControl, setControlMode))
.def("setCaptureIntent", &CameraControl::setCaptureIntent, py::arg("mode"), DOC(dai, CameraControl, setCaptureIntent))
.def("set", &CameraControl::set, py::arg("config"), DOC(dai, CameraControl, set))
// getters
.def("getCaptureStill", &CameraControl::getCaptureStill, DOC(dai, CameraControl, getCaptureStill))
Expand Down
72 changes: 58 additions & 14 deletions utilities/cam_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
'0' - Select control: sharpness
'[' - Select control: luma denoise
']' - Select control: chroma denoise
'\' - Select control: scene mode
';' - Select control: control mode
''' - Select control: capture intent
'a' 'd' - Increase/decrease dot projector intensity
'w' 's' - Increase/decrease flood LED intensity
Expand Down Expand Up @@ -93,6 +96,8 @@ def socket_type_pair(arg):
help="ToF median filter kernel size")
parser.add_argument('-rgbprev', '--rgb-preview', action='store_true',
help="Show RGB `preview` stream instead of full size `isp`")
parser.add_argument('-show', '--show-meta', action='store_true',
help="List frame metadata (seqno, timestamp, exp, iso etc). Can also toggle with `\`")

parser.add_argument('-d', '--device', default="", type=str,
help="Optional MX ID of the device to connect to.")
Expand Down Expand Up @@ -189,6 +194,22 @@ def update(self, timestamp=None):
def get(self):
return self.fps

class Cycle:
def __init__(self, enum_type, start_item=None):
self.items = [item for name, item in vars(enum_type).items() if name.isupper()]
# If start_item is provided, set the index to its position. Otherwise, default to 0
self.index = self.items.index(start_item) if start_item else 0

def step(self, n):
self.index = (self.index + n) % len(self.items)
return self.items[self.index]

def next(self):
return self.step(1)

def prev(self):
return self.step(-1)

# Start defining a pipeline
pipeline = dai.Pipeline()
# Uncomment to get better throughput
Expand Down Expand Up @@ -354,12 +375,12 @@ def exit_cleanly(signum, frame):
dotIntensity = 0
floodIntensity = 0

awb_mode = cycle([item for name, item in vars(
dai.CameraControl.AutoWhiteBalanceMode).items() if name.isupper()])
anti_banding_mode = cycle([item for name, item in vars(
dai.CameraControl.AntiBandingMode).items() if name.isupper()])
effect_mode = cycle([item for name, item in vars(
dai.CameraControl.EffectMode).items() if name.isupper()])
awb_mode = Cycle(dai.CameraControl.AutoWhiteBalanceMode)
anti_banding_mode = Cycle(dai.CameraControl.AntiBandingMode)
effect_mode = Cycle(dai.CameraControl.EffectMode)
scene_mode = Cycle(dai.CameraControl.SceneMode)
control_mode = Cycle(dai.CameraControl.ControlMode)
capture_intent = Cycle(dai.CameraControl.CaptureIntent)

ae_comp = 0
ae_lock = False
Expand All @@ -371,7 +392,7 @@ def exit_cleanly(signum, frame):
luma_denoise = 0
chroma_denoise = 0
control = 'none'
show = False
show = args.show_meta

jet_custom = cv2.applyColorMap(np.arange(256, dtype=np.uint8), cv2.COLORMAP_JET)
jet_custom[0] = [0, 0, 0]
Expand Down Expand Up @@ -402,7 +423,7 @@ def exit_cleanly(signum, frame):
frame = cv2.normalize(frame, frame, alpha=255, beta=0, norm_type=cv2.NORM_MINMAX, dtype=cv2.CV_8U)
frame = cv2.applyColorMap(frame, jet_custom)
if show:
txt = f"[{c:5}, {pkt.getSequenceNum():4}] "
txt = f"[{c:5}, {pkt.getSequenceNum():4}, {pkt.getTimestamp().total_seconds():.6f}] "
txt += f"Exp: {pkt.getExposureTime().total_seconds()*1000:6.3f} ms, "
txt += f"ISO: {pkt.getSensitivity():4}, "
txt += f"Lens pos: {pkt.getLensPosition():3}, "
Expand All @@ -415,10 +436,11 @@ def exit_cleanly(signum, frame):
if capture:
capture_file_info = ('capture_' + c + '_' + cam_name[cam_socket_opts[cam_skt].name]
+ '_' + str(width) + 'x' + str(height)
+ '_' + capture_time
+ '_exp_' + str(int(pkt.getExposureTime().total_seconds()*1e6))
+ '_iso_' + str(pkt.getSensitivity())
+ '_lens_' + str(pkt.getLensPosition())
+ '_' + capture_time
+ '_' + str(pkt.getColorTemperature()) + 'K'
+ '_' + str(pkt.getSequenceNum())
)
capture_list.remove(c)
Expand Down Expand Up @@ -535,22 +557,26 @@ def exit_cleanly(signum, frame):
if dotIntensity < 0:
dotIntensity = 0
device.setIrLaserDotProjectorBrightness(dotIntensity)
print(f'IR Dot intensity:', dotIntensity)
elif key == ord('d'):
dotIntensity = dotIntensity + DOT_STEP
if dotIntensity > DOT_MAX:
dotIntensity = DOT_MAX
device.setIrLaserDotProjectorBrightness(dotIntensity)
print(f'IR Dot intensity:', dotIntensity)
elif key == ord('w'):
floodIntensity = floodIntensity + FLOOD_STEP
if floodIntensity > FLOOD_MAX:
floodIntensity = FLOOD_MAX
device.setIrFloodLightBrightness(floodIntensity)
print(f'IR Flood intensity:', floodIntensity)
elif key == ord('s'):
floodIntensity = floodIntensity - FLOOD_STEP
if floodIntensity < 0:
floodIntensity = 0
device.setIrFloodLightBrightness(floodIntensity)
elif key >= 0 and chr(key) in '34567890[]p':
print(f'IR Flood intensity:', floodIntensity)
elif key >= 0 and chr(key) in '34567890[]p\\;\'':
if key == ord('3'):
control = 'awb_mode'
elif key == ord('4'):
Expand All @@ -567,6 +593,12 @@ def exit_cleanly(signum, frame):
control = 'saturation'
elif key == ord('0'):
control = 'sharpness'
elif key == ord('\\'):
control = 'scene_mode'
elif key == ord(';'):
control = 'control_mode'
elif key == ord('\''):
control = 'capture_intent'
elif key == ord('['):
control = 'luma_denoise'
elif key == ord(']'):
Expand All @@ -582,23 +614,35 @@ def exit_cleanly(signum, frame):
change = 1
ctrl = dai.CameraControl()
if control == 'none':
print("Please select a control first using keys 3..9 0 [ ]")
print("Please select a control first using keys 3..9 0 [ ] \\ ; \'")
elif control == 'ae_comp':
ae_comp = clamp(ae_comp + change, -9, 9)
print("Auto exposure compensation:", ae_comp)
ctrl.setAutoExposureCompensation(ae_comp)
elif control == 'anti_banding_mode':
abm = next(anti_banding_mode)
abm = anti_banding_mode.step(change)
print("Anti-banding mode:", abm)
ctrl.setAntiBandingMode(abm)
elif control == 'awb_mode':
awb = next(awb_mode)
awb = awb_mode.step(change)
print("Auto white balance mode:", awb)
ctrl.setAutoWhiteBalanceMode(awb)
elif control == 'effect_mode':
eff = next(effect_mode)
eff = effect_mode.step(change)
print("Effect mode:", eff)
ctrl.setEffectMode(eff)
elif control == 'scene_mode':
sc = scene_mode.step(change)
print("Scene mode:", sc)
ctrl.setSceneMode(sc)
elif control == 'control_mode':
cm = control_mode.step(change)
print("Control mode:", cm)
ctrl.setControlMode(cm)
elif control == 'capture_intent':
ci = capture_intent.step(change)
print("Capture intent:", ci)
ctrl.setCaptureIntent(ci)
elif control == 'brightness':
brightness = clamp(brightness + change, -10, 10)
print("Brightness:", brightness)
Expand Down

0 comments on commit 0eb95f1

Please sign in to comment.