Skip to content

Commit cc5370b

Browse files
Merge pull request #859 from luxonis/camera_node_alpha_scaling
Camera node: modify alpha scaling parameter behavior to be consistent with StereoDepth
2 parents 6f15fe1 + 0efec25 commit cc5370b

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

examples/StereoDepth/rgb_depth_aligned.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
import cv2
44
import numpy as np
55
import depthai as dai
6+
import argparse
67

78
# Weights to use when blending depth/rgb image (should equal 1.0)
89
rgbWeight = 0.4
910
depthWeight = 0.6
1011

12+
parser = argparse.ArgumentParser()
13+
parser.add_argument('-alpha', type=float, default=None, help="Alpha scaling parameter to increase float. [0,1] valid interval.")
14+
args = parser.parse_args()
15+
alpha = args.alpha
1116

1217
def updateBlendWeights(percent_rgb):
1318
"""
@@ -21,9 +26,6 @@ def updateBlendWeights(percent_rgb):
2126
depthWeight = 1.0 - rgbWeight
2227

2328

24-
# Optional. If set (True), the ColorCamera is downscaled from 1080p to 720p.
25-
# Otherwise (False), the aligned depth is automatically upscaled to 1080p
26-
downscaleColor = True
2729
fps = 30
2830
# The disparity is computed at this resolution, then upscaled to RGB resolution
2931
monoResolution = dai.MonoCameraProperties.SensorResolution.THE_720_P
@@ -34,7 +36,7 @@ def updateBlendWeights(percent_rgb):
3436
queueNames = []
3537

3638
# Define sources and outputs
37-
camRgb = pipeline.create(dai.node.ColorCamera)
39+
camRgb = pipeline.create(dai.node.Camera)
3840
left = pipeline.create(dai.node.MonoCamera)
3941
right = pipeline.create(dai.node.MonoCamera)
4042
stereo = pipeline.create(dai.node.StereoDepth)
@@ -48,15 +50,17 @@ def updateBlendWeights(percent_rgb):
4850
queueNames.append("disp")
4951

5052
#Properties
51-
camRgb.setBoardSocket(dai.CameraBoardSocket.CAM_A)
52-
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
53+
rgbCamSocket = dai.CameraBoardSocket.CAM_A
54+
55+
camRgb.setBoardSocket(rgbCamSocket)
56+
camRgb.setSize(1280, 720)
5357
camRgb.setFps(fps)
54-
if downscaleColor: camRgb.setIspScale(2, 3)
58+
5559
# For now, RGB needs fixed focus to properly align with depth.
5660
# This value was used during calibration
5761
try:
5862
calibData = device.readCalibration2()
59-
lensPosition = calibData.getLensPosition(dai.CameraBoardSocket.CAM_A)
63+
lensPosition = calibData.getLensPosition(rgbCamSocket)
6064
if lensPosition:
6165
camRgb.initialControl.setManualFocus(lensPosition)
6266
except:
@@ -71,14 +75,19 @@ def updateBlendWeights(percent_rgb):
7175
stereo.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_DENSITY)
7276
# LR-check is required for depth alignment
7377
stereo.setLeftRightCheck(True)
74-
stereo.setDepthAlign(dai.CameraBoardSocket.CAM_A)
78+
stereo.setDepthAlign(rgbCamSocket)
7579

7680
# Linking
77-
camRgb.isp.link(rgbOut.input)
81+
camRgb.video.link(rgbOut.input)
7882
left.out.link(stereo.left)
7983
right.out.link(stereo.right)
8084
stereo.disparity.link(disparityOut.input)
8185

86+
camRgb.setMeshSource(dai.CameraProperties.WarpMeshSource.CALIBRATION)
87+
if alpha is not None:
88+
camRgb.setCalibrationAlpha(alpha)
89+
stereo.setAlphaScaling(alpha)
90+
8291
# Connect to device and start pipeline
8392
with device:
8493
device.startPipeline(pipeline)

0 commit comments

Comments
 (0)