Files
AutoControlSystem-G/test6.py
2025-11-08 20:38:55 +08:00

38 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
import sys
import time
from Mv3D.CameraUtil import CameraUtil
from Mv3D.calculate_diff2 import calculate_offset_from_image
if __name__=='__main__':
camera_img=CameraUtil()
loc_image_path=camera_img.save_img()
print(f"保存图片路径:{loc_image_path}")
try:
loc_model_result = calculate_offset_from_image(loc_image_path, visualize=False)
if loc_model_result['success']:
#置信度
if loc_model_result['obj_conf']>0.5:
loc_offsetX=loc_model_result['dx_mm']
if abs(loc_model_result['dx_mm'])<200:
loc_is_next=True
print(f'{loc_image_path}:料带偏移{loc_offsetX}mm')
else:
print(f"{loc_image_path}:料带偏移过大,报警")
# self.feed_error_signal.emit(1,f"{loc_image_path}:料带偏移过大,报警")
else:
print(f"{loc_image_path}:未检测到料带,置信度低")
# self.feed_error_signal.emit(2,f"{loc_image_path}:未检测到料带,置信度低")
else:
print(f"{loc_image_path}:计算偏移失败视觉返回False")
# self.feed_error_signal.emit(2,f"{loc_image_path}:计算偏移失败视觉返回False")
# loc_is_next=False
loc_offsetX=0
except Exception as e:
print(f"{loc_image_path}:计算偏移失败:{e}")
time.sleep(10)