added self.img filter
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 MiB After Width: | Height: | Size: 2.3 MiB |
+17
-1
@@ -70,6 +70,7 @@ class Sensor:
|
||||
ret, frame = self.cap.read()
|
||||
if not ret:
|
||||
time.sleep(1)
|
||||
raise RuntimeError("Could not open video source")
|
||||
if self.verbose:
|
||||
print("Video source connected.")
|
||||
|
||||
@@ -85,6 +86,7 @@ class Sensor:
|
||||
self.n_boxes = None
|
||||
self.stitch_calibration = []
|
||||
self.img = self.flow = self.normal = self.shear = self.force = self.depth = None
|
||||
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)]
|
||||
@@ -131,7 +133,21 @@ class Sensor:
|
||||
self.__stitcher.get_stitch_unit(gray_frame)
|
||||
self.__get_tiles(gray_frame)
|
||||
img = np.ascontiguousarray(self.__stitcher.stitch_rt_optimized())
|
||||
self.img = cv2.resize(img, (400, 400), interpolation=cv2.INTER_CUBIC)
|
||||
|
||||
img_resized = cv2.resize(img, (400, 400), interpolation=cv2.INTER_CUBIC)
|
||||
|
||||
# Apply temporal noise reduction using exponential moving average
|
||||
# Blend current frame with previous filtered frame to reduce temporal noise
|
||||
alpha = 0.7 # Weight for current frame (0.7 = 70% current, 30% previous)
|
||||
if self.img_filtered is None:
|
||||
# First frame: no previous frame to blend with
|
||||
self.img_filtered = img_resized.astype(np.float32)
|
||||
else:
|
||||
# Temporal filtering: blend current frame with previous filtered frame
|
||||
self.img_filtered = alpha * img_resized.astype(np.float32) + (1 - alpha) * self.img_filtered
|
||||
|
||||
# Convert back to uint8
|
||||
self.img = self.img_filtered.astype(np.uint8)
|
||||
self.imgupdate = True
|
||||
return self.img
|
||||
|
||||
|
||||
Reference in New Issue
Block a user