|
|
@@ -1,3 +1,4 @@
|
|
|
+import os
|
|
|
import time
|
|
|
|
|
|
import cv2
|
|
|
@@ -7,14 +8,23 @@ from pyorbbecsdk import *
|
|
|
|
|
|
ESC_KEY = 27
|
|
|
PRINT_INTERVAL = 1 # seconds
|
|
|
-MIN_DEPTH = 500 # mm
|
|
|
-MAX_DEPTH = 4000 # mm
|
|
|
-ROI_WIDTH_CM = 10.0 # cm
|
|
|
-ROI_HEIGHT_CM = 12.0 # cm
|
|
|
MEDIAN_BLUR_KSIZE = 5 # odd number, 0 to disable
|
|
|
MORPH_OPEN_KSIZE = 3 # odd number, 0 to disable
|
|
|
NEAREST_PERCENTILE = 5 # use low percentile to suppress isolated noise (0 for raw min)
|
|
|
|
|
|
+def _get_env_int(name, default):
|
|
|
+ value = os.getenv(name)
|
|
|
+ if value is None or value.strip() == "":
|
|
|
+ return default
|
|
|
+ try:
|
|
|
+ return int(value)
|
|
|
+ except ValueError:
|
|
|
+ return default
|
|
|
+
|
|
|
+MIN_DEPTH = _get_env_int("MIN_DEPTH", 500) # mm
|
|
|
+MAX_DEPTH = _get_env_int("MAX_DEPTH", 4000) # mm
|
|
|
+ROI_WIDTH_CM = _get_env_int("ROI_WIDTH_CM", 10) # cm
|
|
|
+ROI_HEIGHT_CM = _get_env_int("ROI_HEIGHT_CM", 12) # cm
|
|
|
|
|
|
class TemporalFilter:
|
|
|
def __init__(self, alpha):
|
|
|
@@ -84,9 +94,9 @@ def main():
|
|
|
center_distance = depth_data[center_y, center_x]
|
|
|
if center_distance == 0:
|
|
|
continue
|
|
|
- center_distance_m = center_distance / 1000.0
|
|
|
- half_width_m = (ROI_WIDTH_CM / 100.0) / 2.0
|
|
|
- half_height_m = (ROI_HEIGHT_CM / 100.0) / 2.0
|
|
|
+ center_distance_m = center_distance / 1000
|
|
|
+ half_width_m = (ROI_WIDTH_CM / 100) / 2
|
|
|
+ half_height_m = (ROI_HEIGHT_CM / 100) / 2
|
|
|
half_width_px = int(depth_intrinsics.fx * half_width_m / center_distance_m)
|
|
|
half_height_px = int(depth_intrinsics.fy * half_height_m / center_distance_m)
|
|
|
if half_width_px <= 0 or half_height_px <= 0:
|