update parameter to json

This commit is contained in:
bluepulsar
2025-12-25 16:43:09 +08:00
parent 038941593e
commit eab0294f5b
2 changed files with 29 additions and 17 deletions
+28 -14
View File
@@ -43,10 +43,13 @@ class Sensor:
else:
print("User must specify a video source.")
self.vid_src, self.isstitch, self.cuda, self.verbose = vid_src, isstitch, cuda, verbose
self.index = np.array([1,2,3,6,7,8,11,12,13])
self.config_name = config_name
# Initialize Sensor Configuration
self.get_config()
# Initialize components
self.__stitcher = Stitcher(isstitch=isstitch, index=self.index)
self.__stitcher = Stitcher(isstitch=isstitch, index=self.config_index)
self.tracker = Tracker(adaptive=True, cuda=cuda)
self.hhd = None
@@ -56,9 +59,9 @@ class Sensor:
# Setup video capture
self.cap = cv2.VideoCapture(vid_src)
self.cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter.fourcc('M', 'J', 'P', 'G'))
self.cap.set(cv2.CAP_PROP_FPS, 30)
self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
self.cap.set(cv2.CAP_PROP_FPS, self.config_fps)
self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, self.config_resolution_raw[0])
self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, self.config_resolution_raw[1])
# Wait for first valid frame
if self.verbose:
@@ -86,8 +89,7 @@ class Sensor:
self.img_filtered = None # For temporal noise reduction
self.fnormal=self.fshearx=self.fsheary=self.ftor=0.0
self.imgupdate = self.vupdate = False
self.pos_default = [(260, 56), (577, 62), (897, 69), (1214, 75), (1530, 81), (256, 391), (570, 397), (889, 403), (1208, 409), (1523, 416), (248, 724), (563, 730), (882, 738), (1201, 743), (1516, 751)]
# Logging state
self.last_log_time = time.time()
self.fps = 0
@@ -112,7 +114,19 @@ class Sensor:
DEPTH = auto()
def get_config(self):
return configs.load_config("prototype")
"""
Load and return sensor configuration from JSON file.
Returns:
dict: Dictionary containing sensor configuration
"""
self.config = configs.load_config(self.config_name)
self.config_resolution_raw = self.config["camera"]["resolution_raw"]
self.config_fps = self.config["camera"]["fps"]
self.config_units = self.config["camera"]["units"]
self.config_resolution_stitch = self.config["camera"]["resolution_stitch"]
self.config_index = self.config["camera"]["index"]
self.config_pos_default = self.config["camera"]["pos_default"]
def get_img(self):
"""
@@ -133,7 +147,7 @@ class Sensor:
self.__get_tiles(gray_frame)
img = np.ascontiguousarray(self.__stitcher.stitch_rt_optimized())
img_resized = cv2.resize(img, (400, 400), interpolation=cv2.INTER_CUBIC)
img_resized = cv2.resize(img, (self.config_resolution_stitch[0], self.config_resolution_stitch[1]), interpolation=cv2.INTER_CUBIC)
# Apply temporal noise reduction using exponential moving average
# Blend current frame with previous filtered frame to reduce temporal noise
@@ -280,7 +294,7 @@ class Sensor:
start_time = cv2.getTickCount()
# print("Waiting for camera stabilization...")
while n_boxes < 15:
while n_boxes < self.config_units:
ret, frame = self.cap.read()
v_mean = np.sum(cv2.mean(frame))
@@ -297,7 +311,7 @@ class Sensor:
# print("Camera stabilized.")
# print("Checking validabity for stitching...")
self.n_boxes = n_boxes
self.stitch_valid = self.isstitch and n_boxes == 15
self.stitch_valid = self.isstitch and n_boxes == self.config_units
if self.isstitch:
@@ -420,7 +434,7 @@ class Sensor:
# Arrow rooted at original position (x_axis, y_axis), head points to new position (end_x, end_y)
thickness = max(1, int(2 * magnitudes[i] / magnitudes.max())) if magnitudes.max() > 0 else 2
cv2.arrowedLine(image, (x_axis[i], y_axis[i]), (end_x[i], end_y[i]), color, thickness=thickness, tipLength=0.3)
out_img = cv2.resize(image, (400, 400), interpolation=cv2.INTER_CUBIC)
out_img = cv2.resize(image, (self.config_resolution_stitch[0], self.config_resolution_stitch[1]), interpolation=cv2.INTER_CUBIC)
# if fps:
# out_img = self.draw_fps(image=out_img)
@@ -454,7 +468,7 @@ class Sensor:
if flow_field is None:
# Return blank image if no flow data
return np.zeros((400, 400, 3), dtype=np.uint8)
return np.zeros((self.config_resolution_stitch[0], self.config_resolution_stitch[1], 3), dtype=np.uint8)
# Compute magnitude at each point
magnitude = np.sqrt(flow_field[:, :, 0]**2 + flow_field[:, :, 1]**2)
@@ -480,7 +494,7 @@ class Sensor:
magnitude_colored = cv2.applyColorMap(magnitude_norm, colormap)
# Resize to output size
out_img = cv2.resize(magnitude_colored, (400, 400), interpolation=cv2.INTER_CUBIC)
out_img = cv2.resize(magnitude_colored, (self.config_resolution_stitch[0], self.config_resolution_stitch[1]), interpolation=cv2.INTER_CUBIC)
return out_img