feeding
This commit is contained in:
@ -1,30 +1,35 @@
|
||||
# vision/alignment_detector.py
|
||||
def detect_vehicle_alignment(image_array, alignment_model):
|
||||
from vision.align_model.yolo11_main import run_yolo_classification
|
||||
def detect_vehicle_alignment(image_array):
|
||||
"""
|
||||
通过图像检测模具车是否对齐
|
||||
"""
|
||||
try:
|
||||
# 检查模型是否已加载
|
||||
if alignment_model is None:
|
||||
print("对齐检测模型未加载")
|
||||
return False
|
||||
|
||||
if image_array is None:
|
||||
print("输入图像为空")
|
||||
return False
|
||||
|
||||
# 直接使用模型进行推理
|
||||
results = alignment_model(image_array)
|
||||
pared_probs = results[0].probs.data.cpu().numpy().flatten()
|
||||
# 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])
|
||||
# # 类别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
|
||||
|
||||
# 只有当对齐且置信度>95%时才认为对齐
|
||||
if class_id == 1 and confidence > 0.95:
|
||||
return True
|
||||
return False
|
||||
except Exception as e:
|
||||
print(f"对齐检测失败: {e}")
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user