|
2 | 2 |
|
3 | 3 | import cv2
|
4 | 4 | import depthai as dai
|
5 |
| - |
| 5 | +import numpy as np |
6 | 6 | stepSize = 0.05
|
7 | 7 |
|
8 | 8 | newConfig = False
|
|
30 | 30 | monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_400_P)
|
31 | 31 | monoRight.setBoardSocket(dai.CameraBoardSocket.RIGHT)
|
32 | 32 |
|
33 |
| -lrcheck = False |
34 |
| -subpixel = False |
35 |
| - |
36 | 33 | stereo.setDefaultProfilePreset(dai.node.StereoDepth.PresetMode.HIGH_DENSITY)
|
37 |
| -stereo.setLeftRightCheck(lrcheck) |
38 |
| -stereo.setSubpixel(subpixel) |
| 34 | +stereo.setLeftRightCheck(True) |
| 35 | +stereo.setSubpixel(True) |
39 | 36 |
|
40 | 37 | # Config
|
41 | 38 | topLeft = dai.Point2f(0.4, 0.4)
|
|
77 | 74 |
|
78 | 75 | depthFrame = inDepth.getFrame() # depthFrame values are in millimeters
|
79 | 76 |
|
80 |
| - depthFrameColor = cv2.normalize(depthFrame, None, 255, 0, cv2.NORM_INF, cv2.CV_8UC1) |
81 |
| - depthFrameColor = cv2.equalizeHist(depthFrameColor) |
| 77 | + depth_downscaled = depthFrame[::4] |
| 78 | + min_depth = np.percentile(depth_downscaled[depth_downscaled != 0], 1) |
| 79 | + max_depth = np.percentile(depth_downscaled, 99) |
| 80 | + depthFrameColor = np.interp(depthFrame, (min_depth, max_depth), (0, 255)).astype(np.uint8) |
82 | 81 | depthFrameColor = cv2.applyColorMap(depthFrameColor, cv2.COLORMAP_HOT)
|
83 | 82 |
|
84 | 83 | spatialData = spatialCalcQueue.get().getSpatialLocations()
|
|
94 | 93 | depthMax = depthData.depthMax
|
95 | 94 |
|
96 | 95 | fontType = cv2.FONT_HERSHEY_TRIPLEX
|
97 |
| - cv2.rectangle(depthFrameColor, (xmin, ymin), (xmax, ymax), color, cv2.FONT_HERSHEY_SCRIPT_SIMPLEX) |
98 |
| - cv2.putText(depthFrameColor, f"X: {int(depthData.spatialCoordinates.x)} mm", (xmin + 10, ymin + 20), fontType, 0.5, 255) |
99 |
| - cv2.putText(depthFrameColor, f"Y: {int(depthData.spatialCoordinates.y)} mm", (xmin + 10, ymin + 35), fontType, 0.5, 255) |
100 |
| - cv2.putText(depthFrameColor, f"Z: {int(depthData.spatialCoordinates.z)} mm", (xmin + 10, ymin + 50), fontType, 0.5, 255) |
| 96 | + cv2.rectangle(depthFrameColor, (xmin, ymin), (xmax, ymax), color, 1) |
| 97 | + cv2.putText(depthFrameColor, f"X: {int(depthData.spatialCoordinates.x)} mm", (xmin + 10, ymin + 20), fontType, 0.5, color) |
| 98 | + cv2.putText(depthFrameColor, f"Y: {int(depthData.spatialCoordinates.y)} mm", (xmin + 10, ymin + 35), fontType, 0.5, color) |
| 99 | + cv2.putText(depthFrameColor, f"Z: {int(depthData.spatialCoordinates.z)} mm", (xmin + 10, ymin + 50), fontType, 0.5, color) |
101 | 100 | # Show the frame
|
102 | 101 | cv2.imshow("depth", depthFrameColor)
|
103 | 102 |
|
|
0 commit comments