36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
# vision/alignment_detector.py
|
|
from vision.align_model.yolo11_main import run_yolo_classification
|
|
def detect_vehicle_alignment(image_array):
|
|
"""
|
|
通过图像检测模具车是否对齐
|
|
"""
|
|
try:
|
|
# 检查模型是否已加载
|
|
if image_array is None:
|
|
print("输入图像为空")
|
|
return False
|
|
|
|
# 直接使用模型进行推理
|
|
# results = alignment_model(image_array)
|
|
# pared_probs = results[0].probs.data.cpu().numpy().flatten()
|
|
|
|
# # 类别0: 未对齐, 类别1: 对齐
|
|
# class_id = int(pared_probs.argmax())
|
|
# confidence = float(pared_probs[class_id])
|
|
|
|
# # 只有当对齐且置信度>95%时才认为对齐
|
|
# if class_id == 1 and confidence > 0.95:
|
|
# return True
|
|
# return False
|
|
|
|
# 使用yolov11_cls_inference函数进行推理
|
|
results = run_yolo_classification(image_array)
|
|
if results=="盖板对齐":
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
except Exception as e:
|
|
print(f"对齐检测失败: {e}")
|
|
return False
|