mirror of
https://github.com/NanjingForestryUniversity/supermachine--tomato-passion_fruit.git
synced 2025-11-09 14:54:07 +00:00
feat:新增qt_test的预热数据部分,测试成功,预热之后全流程总用时172.5ms
This commit is contained in:
parent
28d403fba7
commit
74e141bb8f
@ -89,7 +89,7 @@ def main(is_debug=False):
|
|||||||
_ = detector.predict(np.ones((30, 30, 224), dtype=np.uint16))
|
_ = detector.predict(np.ones((30, 30, 224), dtype=np.uint16))
|
||||||
_, _, _, _, _ =dp.analyze_tomato(cv2.imread(r'D:\project\supermachine--tomato-passion_fruit\20240529RGBtest3\data\tomato_img\bad\71.bmp'))
|
_, _, _, _, _ =dp.analyze_tomato(cv2.imread(r'D:\project\supermachine--tomato-passion_fruit\20240529RGBtest3\data\tomato_img\bad\71.bmp'))
|
||||||
_, _, _, _, _ = dp.analyze_passion_fruit(cv2.imread(r'D:\project\supermachine--tomato-passion_fruit\20240529RGBtest3\data\passion_fruit_img\38.bmp'))
|
_, _, _, _, _ = dp.analyze_passion_fruit(cv2.imread(r'D:\project\supermachine--tomato-passion_fruit\20240529RGBtest3\data\passion_fruit_img\38.bmp'))
|
||||||
# print('初始化完成')
|
print('初始化完成')
|
||||||
|
|
||||||
rgb_receive_name = r'\\.\pipe\rgb_receive'
|
rgb_receive_name = r'\\.\pipe\rgb_receive'
|
||||||
rgb_send_name = r'\\.\pipe\rgb_send'
|
rgb_send_name = r'\\.\pipe\rgb_send'
|
||||||
@ -98,9 +98,12 @@ def main(is_debug=False):
|
|||||||
rgb_receive, rgb_send, spec_receive = pipe.create_pipes(rgb_receive_name, rgb_send_name, spec_receive_name)
|
rgb_receive, rgb_send, spec_receive = pipe.create_pipes(rgb_receive_name, rgb_send_name, spec_receive_name)
|
||||||
# 预热循环,只处理cmd为'YR'的数据
|
# 预热循环,只处理cmd为'YR'的数据
|
||||||
while True:
|
while True:
|
||||||
|
start_time00 = time.time()
|
||||||
data = pipe.receive_rgb_data(rgb_receive)
|
data = pipe.receive_rgb_data(rgb_receive)
|
||||||
cmd, _ = pipe.parse_img(data)
|
cmd, _ = pipe.parse_img(data)
|
||||||
if cmd != 'YR':
|
end_time00 = time.time()
|
||||||
|
print(f'接收预热数据时间:{end_time00 - start_time00}秒')
|
||||||
|
if cmd == 'YR':
|
||||||
break # 当接收到的不是预热命令时,结束预热循环
|
break # 当接收到的不是预热命令时,结束预热循环
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
@ -108,15 +111,15 @@ def main(is_debug=False):
|
|||||||
images = []
|
images = []
|
||||||
cmd = None
|
cmd = None
|
||||||
for _ in range(5):
|
for _ in range(5):
|
||||||
# start_time1 = time.time()
|
start_time1 = time.time()
|
||||||
data = pipe.receive_rgb_data(rgb_receive)
|
data = pipe.receive_rgb_data(rgb_receive)
|
||||||
# end_time10 = time.time()
|
end_time10 = time.time()
|
||||||
# print(f'接收一份数据时间:{end_time10 - start_time1}秒')
|
print(f'接收一份数据时间:{end_time10 - start_time1}秒')
|
||||||
# start_time11 = time.time()
|
start_time11 = time.time()
|
||||||
cmd, img = pipe.parse_img(data)
|
cmd, img = pipe.parse_img(data)
|
||||||
# end_time1 = time.time()
|
end_time1 = time.time()
|
||||||
# print(f'处理一份数据时间:{end_time1 - start_time11}秒')
|
print(f'处理一份数据时间:{end_time1 - start_time11}秒')
|
||||||
# print(f'接收1张图时间:{end_time1 - start_time1}秒')
|
print(f'接收1张图时间:{end_time1 - start_time1}秒')
|
||||||
# print(cmd, img.shape)
|
# print(cmd, img.shape)
|
||||||
# #打印img的数据类型
|
# #打印img的数据类型
|
||||||
# print(img.dtype)
|
# print(img.dtype)
|
||||||
@ -127,18 +130,18 @@ def main(is_debug=False):
|
|||||||
continue
|
continue
|
||||||
spec = None
|
spec = None
|
||||||
if cmd == 'PF':
|
if cmd == 'PF':
|
||||||
# start_time2 = time.time()
|
start_time2 = time.time()
|
||||||
spec_data = pipe.receive_spec_data(spec_receive)
|
spec_data = pipe.receive_spec_data(spec_receive)
|
||||||
_, spec = pipe.parse_spec(spec_data)
|
_, spec = pipe.parse_spec(spec_data)
|
||||||
# end_time2 = time.time()
|
end_time2 = time.time()
|
||||||
# print(f'接收光谱数据时间:{end_time2 - start_time2}秒')
|
print(f'接收光谱数据时间:{end_time2 - start_time2}秒')
|
||||||
# print(spec.shape)
|
# print(spec.shape)
|
||||||
# start_time3 = time.time()
|
start_time3 = time.time()
|
||||||
response = process_data(cmd, images, spec, dp, pipe, detector)
|
response = process_data(cmd, images, spec, dp, pipe, detector)
|
||||||
# end_time3 = time.time()
|
end_time3 = time.time()
|
||||||
# print(f'处理时间:{end_time3 - start_time3}秒')
|
print(f'处理时间:{end_time3 - start_time3}秒')
|
||||||
end_time = time.time()
|
end_time = time.time()
|
||||||
# print(f'全流程时间:{end_time - start_time}秒')
|
print(f'全流程时间:{end_time - start_time}秒')
|
||||||
if response:
|
if response:
|
||||||
logging.info(f'处理成功,响应为: {response}')
|
logging.info(f'处理成功,响应为: {response}')
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -71,6 +71,8 @@ class MainWindow(QMainWindow):
|
|||||||
rgb_files = [os.path.join(image_dir, f) for f in os.listdir(image_dir) if f.endswith(('.bmp'))][:5]
|
rgb_files = [os.path.join(image_dir, f) for f in os.listdir(image_dir) if f.endswith(('.bmp'))][:5]
|
||||||
spec_files = [os.path.join(image_dir, f) for f in os.listdir(image_dir) if f.endswith('.raw')][:1]
|
spec_files = [os.path.join(image_dir, f) for f in os.listdir(image_dir) if f.endswith('.raw')][:1]
|
||||||
|
|
||||||
|
self.send_YR()
|
||||||
|
|
||||||
for image_path in rgb_files:
|
for image_path in rgb_files:
|
||||||
img = cv2.imread(image_path, cv2.IMREAD_COLOR)
|
img = cv2.imread(image_path, cv2.IMREAD_COLOR)
|
||||||
img = np.asarray(img, dtype=np.uint8)
|
img = np.asarray(img, dtype=np.uint8)
|
||||||
@ -116,6 +118,18 @@ class MainWindow(QMainWindow):
|
|||||||
|
|
||||||
self.receive_result()
|
self.receive_result()
|
||||||
|
|
||||||
|
def send_YR(self):
|
||||||
|
|
||||||
|
length = 2
|
||||||
|
length = length.to_bytes(4, byteorder='big')
|
||||||
|
cmd = 'YR'
|
||||||
|
data_send = length + cmd.upper().encode('ascii')
|
||||||
|
try:
|
||||||
|
win32file.WriteFile(self.rgb_send, data_send)
|
||||||
|
print("发送预热指令成功")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"发送预热指令失败. 错误原因: {e}")
|
||||||
|
|
||||||
def receive_result(self):
|
def receive_result(self):
|
||||||
try:
|
try:
|
||||||
# 读取结果数据
|
# 读取结果数据
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user