Skip to content

Commit a53c0a4

Browse files
author
SzabolcsGergely
committed
Set lens position from calibration data
1 parent 917d189 commit a53c0a4

File tree

6 files changed

+27
-10
lines changed

6 files changed

+27
-10
lines changed

examples/Script/script_forward_frames.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
pipeline = dai.Pipeline()
77

88
cam = pipeline.create(dai.node.ColorCamera)
9-
cam.initialControl.setManualFocus(130)
109
# Not needed, you can display 1080P frames as well
1110
cam.setIspScale(1,2)
1211

examples/SpatialDetection/spatial_tiny_yolo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116

117117
stereo.depth.link(spatialDetectionNetwork.inputDepth)
118118
spatialDetectionNetwork.passthroughDepth.link(xoutDepth.input)
119-
spatialDetectionNetwork.outNetwork.link(nnNetworkOut.input);
119+
spatialDetectionNetwork.outNetwork.link(nnNetworkOut.input)
120120

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

examples/StereoDepth/rgb_depth_aligned.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def updateBlendWeights(percent_rgb):
3030

3131
# Create pipeline
3232
pipeline = dai.Pipeline()
33+
device = dai.Device()
3334
queueNames = []
3435

3536
# Define sources and outputs
@@ -53,8 +54,13 @@ def updateBlendWeights(percent_rgb):
5354
if downscaleColor: camRgb.setIspScale(2, 3)
5455
# For now, RGB needs fixed focus to properly align with depth.
5556
# This value was used during calibration
56-
camRgb.initialControl.setManualFocus(130)
57-
57+
try:
58+
calibData = device.readCalibration()
59+
lensPosition = calibData.getLensPosition(dai.CameraBoardSocket.RGB)
60+
if lensPosition:
61+
camRgb.initialControl.setManualFocus(lensPosition)
62+
except:
63+
raise
5864
left.setResolution(monoResolution)
5965
left.setBoardSocket(dai.CameraBoardSocket.LEFT)
6066
left.setFps(fps)
@@ -74,7 +80,8 @@ def updateBlendWeights(percent_rgb):
7480
stereo.disparity.link(disparityOut.input)
7581

7682
# Connect to device and start pipeline
77-
with dai.Device(pipeline) as device:
83+
with device:
84+
device.startPipeline(pipeline)
7885

7986
frameRgb = None
8087
frameDisp = None

examples/StereoDepth/rgb_depth_confidence_aligned.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def updateConfBlendWeights(percent):
5050

5151
# Create pipeline
5252
pipeline = dai.Pipeline()
53+
device = dai.Device()
5354
queueNames = []
5455

5556
# Define sources and outputs
@@ -73,7 +74,13 @@ def updateConfBlendWeights(percent):
7374
if downscaleColor: camRgb.setIspScale(2, 3)
7475
# For now, RGB needs fixed focus to properly align with depth.
7576
# This value was used during calibration
76-
camRgb.initialControl.setManualFocus(130)
77+
try:
78+
calibData = device.readCalibration()
79+
lensPosition = calibData.getLensPosition(dai.CameraBoardSocket.RGB)
80+
if lensPosition:
81+
camRgb.initialControl.setManualFocus(lensPosition)
82+
except:
83+
raise
7784

7885
left.setResolution(monoResolution)
7986
left.setBoardSocket(dai.CameraBoardSocket.LEFT)
@@ -99,7 +106,8 @@ def updateConfBlendWeights(percent):
99106
stereo.confidenceMap.link(xoutConfMap.input)
100107

101108
# Connect to device and start pipeline
102-
with dai.Device(pipeline) as device:
109+
with device:
110+
device.startPipeline(pipeline)
103111

104112
frameRgb = None
105113
frameDisp = None

examples/StereoDepth/stereo_depth_video.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ def getDisparityFrame(frame):
233233
if depth:
234234
streams.append("depth")
235235

236-
calibData = dai.Device().readCalibration()
236+
device = dai.Device()
237+
calibData = device.readCalibration()
237238
leftMesh, rightMesh = getMesh(calibData)
238239
if generateMesh:
239240
meshLeft = list(leftMesh.tobytes())
@@ -245,7 +246,9 @@ def getDisparityFrame(frame):
245246

246247

247248
print("Creating DepthAI device")
248-
with dai.Device(pipeline) as device:
249+
with device:
250+
device.startPipeline(pipeline)
251+
249252
# Create a receive queue for each stream
250253
qList = [device.getOutputQueue(stream, 8, blocking=False) for stream in streams]
251254

0 commit comments

Comments
 (0)