display without edge + depth map smoothing

This commit is contained in:
unknown
2025-12-22 10:41:36 +08:00
parent 799b0d4ed9
commit de55d73764
3 changed files with 240 additions and 65 deletions
+19 -5
View File
@@ -4,7 +4,7 @@ import cv2
import numpy as np
from orisys import Sensor
def draw_arrows_fade(img, flow, depth, depth_scale=0.5, grid_spacing=40, arrow_scale=1.0, threshold=5.0):
def draw_arrows_fade(img, flow, depth, depth_scale=0.5, grid_spacing=20, arrow_scale=1.0, threshold=5.0):
"""
Draw optical flow arrows on image with transparency based on magnitude.
@@ -18,10 +18,11 @@ def draw_arrows_fade(img, flow, depth, depth_scale=0.5, grid_spacing=40, arrow_s
Returns:
Image with arrows drawn, blended with original image
"""
depth_img = cv2.applyColorMap(((depth+1)*depth_scale* 255.0).astype('uint8'), cv2.COLORMAP_HOT)
# Make a copy of the image
img_copy = depth_img.copy()
# Convert grayscale to BGR if needed
if len(img_copy.shape) == 2 or img_copy.shape[2] == 1:
@@ -132,9 +133,9 @@ def main():
global start_time
# 打开视频
sensor1 = Sensor("./s1.mp4",isstitch=True,cuda = True,verbose = True)
# sensor1 = Sensor("./s1.mp4",isstitch=True,cuda = True,verbose = True)
# 打开摄像头
# sensor1 = Sensor(0,isstitch=True,cuda = True,verbose = True)
sensor1 = Sensor(0,isstitch=True,cuda = True,verbose = True)
while True:
sensor1.get_img() # 提取并拼接复眼图像
sensor1.compute_deformation() # 计算形变和分解
@@ -145,7 +146,20 @@ def main():
fps, fn, fx, fy, flow, depth = sensor1.read_info(sensor1.info.FPS, sensor1.info.FNORMAL, sensor1.info.FSHEARX, sensor1.info.FSHEARY, sensor1.info.VRAW, sensor1.info.DEPTH)
arrows = draw_arrows_fade(sensor1.img, flow, depth)
print(fps,np.min(depth),np.mean(depth))
cv2.imshow("Deformation", arrows)
# Crop edges (15 pixels from each side) - only if image is large enough
h, w = arrows.shape[:2]
if h > 30 and w > 30:
cv2.imshow("Deformation", arrows[15:-15, 15:-15, :])
else:
cv2.imshow("Deformation", arrows)
# Crop raw image edges if large enough
h_raw, w_raw = sensor1.img.shape[:2]
if h_raw > 30 and w_raw > 30:
cv2.imshow("raw", sensor1.img[15:-15, 15:-15])
else:
cv2.imshow("raw", sensor1.img)
key = cv2.waitKey(1)
if key & 0xFF == ord("q"):