重构目录结构:调整项目布局
This commit is contained in:
30
vision/alignment_detector.py
Normal file
30
vision/alignment_detector.py
Normal file
@ -0,0 +1,30 @@
|
||||
# vision/alignment_detector.py
|
||||
def detect_vehicle_alignment(image_array, alignment_model):
|
||||
"""
|
||||
通过图像检测模具车是否对齐
|
||||
"""
|
||||
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()
|
||||
|
||||
# 类别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
|
||||
except Exception as e:
|
||||
print(f"对齐检测失败: {e}")
|
||||
return False
|
||||
Reference in New Issue
Block a user