Skip to content

Commit f86c134

Browse files
author
Matevz Morato
committed
Merge branch 'develop' into feat/stubs-docstring-generation
2 parents b91216b + 141cbf2 commit f86c134

File tree

13 files changed

+94
-763
lines changed

13 files changed

+94
-763
lines changed

examples/ImageAlign/depth_align.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
COLOR_RESOLUTION = dai.ColorCameraProperties.SensorResolution.THE_1080_P
1414
LEFT_RIGHT_RESOLUTION = dai.MonoCameraProperties.SensorResolution.THE_400_P
1515

16+
ISP_SCALE = 3
17+
1618
class FPSCounter:
1719
def __init__(self):
1820
self.frameTimes = []
@@ -27,6 +29,14 @@ def getFps(self):
2729
return 0
2830
return (len(self.frameTimes) - 1) / (self.frameTimes[-1] - self.frameTimes[0])
2931

32+
device = dai.Device()
33+
34+
calibrationHandler = device.readCalibration()
35+
rgbIntrinsics = calibrationHandler.getCameraIntrinsics(RGB_SOCKET, int(1920 / ISP_SCALE), int(1080 / ISP_SCALE))
36+
rgbDistortion = calibrationHandler.getDistortionCoefficients(RGB_SOCKET)
37+
distortionModel = calibrationHandler.getDistortionModel(RGB_SOCKET)
38+
if distortionModel != dai.CameraModel.Perspective:
39+
raise RuntimeError("Unsupported distortion model for RGB camera. This example supports only Perspective model.")
3040

3141
pipeline = dai.Pipeline()
3242

@@ -50,9 +60,11 @@ def getFps(self):
5060
camRgb.setBoardSocket(RGB_SOCKET)
5161
camRgb.setResolution(COLOR_RESOLUTION)
5262
camRgb.setFps(FPS)
53-
camRgb.setIspScale(1, 3)
63+
camRgb.setIspScale(1, ISP_SCALE)
64+
5465

5566
stereo.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_DENSITY)
67+
stereo.setDepthAlign(dai.CameraBoardSocket.LEFT)
5668

5769
out.setStreamName("out")
5870

@@ -113,7 +125,8 @@ def updateBlendWeights(percentRgb):
113125

114126

115127
# Connect to device and start pipeline
116-
with dai.Device(pipeline) as device:
128+
with device:
129+
device.startPipeline(pipeline)
117130
queue = device.getOutputQueue("out", 8, False)
118131

119132
# Configure windows; trackbar adjusts blending ratio of rgb/depth
@@ -144,6 +157,13 @@ def updateBlendWeights(percentRgb):
144157
# Blend when both received
145158
if frameDepth is not None:
146159
cvFrame = frameRgb.getCvFrame()
160+
161+
# Undistort the rgb frame
162+
cvFrameUndistorted = cv2.undistort(
163+
cvFrame,
164+
np.array(rgbIntrinsics),
165+
np.array(rgbDistortion),
166+
)
147167
# Colorize the aligned depth
148168
alignedDepthColorized = colorizeDepth(frameDepth.getFrame())
149169
# Resize depth to match the rgb frame

examples/ImageAlign/image_align.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def updateDepthPlane(depth):
9595
updateBlendWeights,
9696
)
9797
cv2.createTrackbar(
98-
"Static Depth Plane",
98+
"Static Depth Plane [mm]",
9999
windowName,
100100
0,
101101
2000,
@@ -126,4 +126,4 @@ def updateDepthPlane(depth):
126126
break
127127

128128
cfg.staticDepthPlane = staticDepthPlane
129-
cfgQ.send(cfg)
129+
cfgQ.send(cfg)

examples/ImageAlign/thermal_align.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def getFps(self):
3838
raise RuntimeError("No thermal camera found!")
3939

4040

41-
4241
pipeline = dai.Pipeline()
4342

4443
# Define sources and outputs
@@ -114,7 +113,7 @@ def updateDepthPlane(depth):
114113
updateBlendWeights,
115114
)
116115
cv2.createTrackbar(
117-
"Static Depth Plane",
116+
"Static Depth Plane [mm]",
118117
windowName,
119118
0,
120119
2000,
@@ -161,4 +160,4 @@ def updateDepthPlane(depth):
161160
break
162161

163162
cfg.staticDepthPlane = staticDepthPlane
164-
cfgQ.send(cfg)
163+
cfgQ.send(cfg)

examples/ImageAlign/tof_align.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def tick(self):
2020
self.frameTimes.append(now)
2121
self.frameTimes = self.frameTimes[-100:]
2222

23-
def get_fps(self):
23+
def getFps(self):
2424
if len(self.frameTimes) <= 1:
2525
return 0
2626
# Calculate the FPS
@@ -141,7 +141,7 @@ def updateBlendWeights(percentRgb):
141141
# Resize depth to match the rgb frame
142142
cv2.putText(
143143
alignedDepthColorized,
144-
f"FPS: {fpsCounter.get_fps():.2f}",
144+
f"FPS: {fpsCounter.getFps():.2f}",
145145
(10, 30),
146146
cv2.FONT_HERSHEY_SIMPLEX,
147147
1,

examples/Reprojection/projector_3d.py

Lines changed: 0 additions & 57 deletions
This file was deleted.

examples/Reprojection/reprojection.py

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)