feeding
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
# vision/detector.py
|
||||
import os
|
||||
from ultralytics import YOLO
|
||||
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
|
||||
@ -9,16 +9,14 @@ from vision.alignment_detector import detect_vehicle_alignment
|
||||
class VisionDetector:
|
||||
def __init__(self, settings):
|
||||
self.settings = settings
|
||||
|
||||
# 模型实例
|
||||
self.angle_model = None
|
||||
self.overflow_model = None
|
||||
self.alignment_model = None
|
||||
|
||||
#model路径在对应的模型里面
|
||||
# self.alignment_model = os.path.join(current_dir, "align_model/yolov11_cls_640v6.rknn")
|
||||
|
||||
def load_models(self):
|
||||
"""
|
||||
加载所有视觉检测模型
|
||||
"""
|
||||
from ultralytics import YOLO
|
||||
success = True
|
||||
|
||||
# 加载夹角检测模型
|
||||
@ -59,28 +57,44 @@ class VisionDetector:
|
||||
|
||||
return success
|
||||
|
||||
def detect_angle(self, image=None, image_path=None):
|
||||
def detect_angle(self, image=None):
|
||||
"""
|
||||
通过视觉系统获取当前出砼门角度
|
||||
"""
|
||||
# image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
||||
image=cv2.flip(image, 0)
|
||||
return get_current_door_angle(
|
||||
model=self.angle_model,
|
||||
image=image,
|
||||
image_path=image_path
|
||||
model=self.settings.angle_model_path,
|
||||
image=image
|
||||
)
|
||||
|
||||
def detect_overflow(self, image_array):
|
||||
"""
|
||||
通过图像检测是否溢料
|
||||
"""
|
||||
# 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)
|
||||
return detect_overflow_from_image(
|
||||
image_array,
|
||||
self.overflow_model,
|
||||
self.settings.roi_file_path
|
||||
self.settings.overflow_model_path,
|
||||
self.settings.roi_file_path,
|
||||
image_array
|
||||
)
|
||||
|
||||
def detect_vehicle_alignment(self, image_array):
|
||||
"""
|
||||
通过图像检测模具车是否对齐
|
||||
"""
|
||||
return detect_vehicle_alignment(image_array, self.alignment_model)
|
||||
image_array = cv2.cvtColor(image_array, cv2.COLOR_BGR2RGB)
|
||||
image_array=cv2.flip(image_array, 0)
|
||||
# cv2.namedWindow("Alignment", cv2.WINDOW_NORMAL)
|
||||
# cv2.resizeWindow("Alignment", 640, 480)
|
||||
# cv2.imshow("Alignment", image_array)
|
||||
# cv2.waitKey(1)
|
||||
|
||||
return detect_vehicle_alignment(image_array)
|
||||
|
||||
Reference in New Issue
Block a user