This commit is contained in:
2025-11-21 14:55:52 +08:00
parent e3ecd0550f
commit 26ed8df502
36 changed files with 908 additions and 433 deletions

View File

@ -62,6 +62,30 @@ class DualCameraController:
# print('aaaaa')
ret, frame = cap.read()
if ret and frame is not None:
# 在帧右上角添加时间戳
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
# 获取帧尺寸
height, width = frame.shape[:2]
# 设置文字参数
font = cv2.FONT_HERSHEY_SIMPLEX
font_scale = 0.6
thickness = 2
color = (0, 255, 0) # 绿色
# 计算文字位置(右上角)
text_size = cv2.getTextSize(current_time, font, font_scale, thickness)[0]
text_x = width - text_size[0] - 10 # 距离右边10像素
text_y = 30 # 距离顶部30像素
# 添加文字背景(半透明)
overlay = frame.copy()
cv2.rectangle(overlay, (text_x - 5, text_y - text_size[1] - 5),
(text_x + text_size[0] + 5, text_y + 5), (0, 0, 0), -1)
cv2.addWeighted(overlay, 0.7, frame, 0.3, 0, frame)
# 添加时间戳文字
cv2.putText(frame, current_time, (text_x, text_y), font, font_scale, color, thickness)
# 使用高精度时间戳
timestamp = time.time()
# 检查队列是否已满
@ -216,11 +240,11 @@ class DualCameraController:
dt_t1, frame_latest = self.frame_queues['cam1'].queue[-1]
# 获取cam2的最新帧选择时间戳更新的那个
if frame_latest is None:
if not self.frame_queues['cam2'].empty():
dt_t2, frame2 = self.frame_queues['cam2'].queue[-1]
if dt_t1 is None or dt_t2 > dt_t1:
frame_latest = frame2
# if frame_latest is None:
if not self.frame_queues['cam2'].empty():
dt_t2, frame2 = self.frame_queues['cam2'].queue[-1]
if dt_t1 is None or dt_t2 > dt_t1:
frame_latest = frame2
# 返回最新帧的副本(如果找到)
return frame_latest.copy() if frame_latest is not None else None

View File

@ -4,11 +4,12 @@ import cv2
from vision.angle_detector import get_current_door_angle
from vision.overflow_detector import detect_overflow_from_image
from vision.alignment_detector import detect_vehicle_alignment
from config.settings import app_set_config
class VisionDetector:
def __init__(self, settings):
self.settings = settings
def __init__(self):
pass
#model路径在对应的模型里面
# self.alignment_model = os.path.join(current_dir, "align_model/yolov11_cls_640v6.rknn")
@ -21,36 +22,36 @@ class VisionDetector:
# 加载夹角检测模型
try:
if not os.path.exists(self.settings.angle_model_path):
print(f"夹角检测模型不存在: {self.settings.angle_model_path}")
if not os.path.exists(app_set_config.angle_model_path):
print(f"夹角检测模型不存在: {app_set_config.angle_model_path}")
success = False
else:
# 注意angle.pt模型通过predict_obb_best_angle函数使用不需要预加载
print(f"夹角检测模型路径: {self.settings.angle_model_path}")
print(f"夹角检测模型路径: {app_set_config.angle_model_path}")
except Exception as e:
print(f"检查夹角检测模型失败: {e}")
success = False
# 加载堆料检测模型
try:
if not os.path.exists(self.settings.overflow_model_path):
print(f"堆料检测模型不存在: {self.settings.overflow_model_path}")
if not os.path.exists(app_set_config.overflow_model_path):
print(f"堆料检测模型不存在: {app_set_config.overflow_model_path}")
success = False
else:
self.overflow_model = YOLO(self.settings.overflow_model_path)
print(f"成功加载堆料检测模型: {self.settings.overflow_model_path}")
self.overflow_model = YOLO(app_set_config.overflow_model_path)
print(f"成功加载堆料检测模型: {app_set_config.overflow_model_path}")
except Exception as e:
print(f"加载堆料检测模型失败: {e}")
success = False
# 加载对齐检测模型
try:
if not os.path.exists(self.settings.alignment_model_path):
print(f"对齐检测模型不存在: {self.settings.alignment_model_path}")
if not os.path.exists(app_set_config.alignment_model_path):
print(f"对齐检测模型不存在: {app_set_config.alignment_model_path}")
success = False
else:
self.alignment_model = YOLO(self.settings.alignment_model_path)
print(f"成功加载对齐检测模型: {self.settings.alignment_model_path}")
self.alignment_model = YOLO(app_set_config.alignment_model_path)
print(f"成功加载对齐检测模型: {app_set_config.alignment_model_path}")
except Exception as e:
print(f"加载对齐检测模型失败: {e}")
success = False
@ -64,7 +65,7 @@ class VisionDetector:
# image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
image=cv2.flip(image, 0)
return get_current_door_angle(
model=self.settings.angle_model_path,
model=app_set_config.angle_model_path,
image=image
)
@ -72,21 +73,21 @@ class VisionDetector:
"""
通过图像检测是否溢料
"""
# image_array=cv2.flip(image_array, 0)
image_array=cv2.flip(image_array, 0)
# cv2.imwrite('test.jpg', image_array)
cv2.namedWindow("Alignment", cv2.WINDOW_NORMAL)
cv2.resizeWindow("Alignment", 640, 480)
cv2.imshow("Alignment", image_array)
cv2.waitKey(1)
print('path:', self.settings.overflow_model_path)
print('roi:', self.settings.roi_file_path)
# cv2.namedWindow("Alignment", cv2.WINDOW_NORMAL)
# cv2.resizeWindow("Alignment", 640, 480)
# cv2.imshow("Alignment", image_array)
# cv2.waitKey(1)
# print('path:', app_set_config.overflow_model_path)
# print('roi:', app_set_config.roi_file_path)
return detect_overflow_from_image(
self.settings.overflow_model_path,
self.settings.roi_file_path,
app_set_config.overflow_model_path,
app_set_config.roi_file_path,
image_array
)
def detect_vehicle_alignment(self, image_array):
def detect_vehicle_alignment(self, image_array)->bool:
"""
通过图像检测模具车是否对齐
"""

View File

@ -1 +1 @@
859,810,696,328
644,608,522,246