diff --git a/20240529RGBtest3/main.py b/20240529RGBtest3/main.py index dff44e1..543fdcc 100644 --- a/20240529RGBtest3/main.py +++ b/20240529RGBtest3/main.py @@ -6,21 +6,20 @@ import sys import os + +import cv2 + from root_dir import ROOT_DIR from classifer import Spec_predict, Data_processing import logging from utils import Pipe import numpy as np +import time -rgb_receive_name = r'\\.\pipe\rgb_receive' -rgb_send_name = r'\\.\pipe\rgb_send' -spec_receive_name = r'\\.\pipe\spec_receive' -pipe = Pipe(rgb_receive_name, rgb_send_name, spec_receive_name) -dp = Data_processing() -rgb_receive, rgb_send, spec_receive = pipe.create_pipes(rgb_receive_name, rgb_send_name, spec_receive_name) -def process_data(cmd: str, images: list, spec: any, detector: Spec_predict) -> bool: + +def process_data(cmd: str, images: list, spec: any, dp: Data_processing, pipe: Pipe, detector: Spec_predict) -> bool: """ 处理指令 @@ -85,37 +84,60 @@ def main(is_debug=False): handlers=[file_handler, console_handler], level=logging.DEBUG) detector = Spec_predict(ROOT_DIR/'models'/'passion_fruit_2.joblib') + dp = Data_processing() + _ = 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_passion_fruit(cv2.imread(r'D:\project\supermachine--tomato-passion_fruit\20240529RGBtest3\data\passion_fruit_img\38.bmp')) + print('初始化完成') + + rgb_receive_name = r'\\.\pipe\rgb_receive' + rgb_send_name = r'\\.\pipe\rgb_send' + spec_receive_name = r'\\.\pipe\spec_receive' + pipe = Pipe(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) while True: + + start_time = time.time() images = [] cmd = None - for _ in range(5): + start_time1 = time.time() data = pipe.receive_rgb_data(rgb_receive) + end_time10 = time.time() + print(f'接收一份数据时间:{end_time10 - start_time1}秒') + start_time11 = time.time() cmd, img = pipe.parse_img(data) - + end_time1 = time.time() + print(f'处理一份数据时间:{end_time1 - start_time11}秒') + print(f'接收1张图时间:{end_time1 - start_time1}秒') # print(cmd, img.shape) - + # #打印img的数据类型 + # print(img.dtype) images.append(img) - # print(len(images)) - - if cmd not in ['TO', 'PF']: logging.error(f'错误指令,指令为{cmd}') continue - spec = None if cmd == 'PF': + start_time2 = time.time() spec_data = pipe.receive_spec_data(spec_receive) _, spec = pipe.parse_spec(spec_data) + end_time2 = time.time() + print(f'接收光谱数据时间:{end_time2 - start_time2}秒') # print(spec.shape) - - response = process_data(cmd, images, spec, detector) + start_time3 = time.time() + response = process_data(cmd, images, spec, dp, pipe, detector) + end_time3 = time.time() + print(f'处理时间:{end_time3 - start_time3}秒') + end_time = time.time() + print(f'全流程时间:{end_time - start_time}秒') if response: logging.info(f'处理成功,响应为: {response}') else: logging.error('处理失败') + if __name__ == '__main__': main(is_debug=False) diff --git a/20240529RGBtest3/通信协议(20240612).md b/20240529RGBtest3/通信协议(20240612).md index 1f8dadf..a16334f 100644 --- a/20240529RGBtest3/通信协议(20240612).md +++ b/20240529RGBtest3/通信协议(20240612).md @@ -21,6 +21,7 @@ | T | O | 番茄数据 | | P | F | 百香果数据 | | R | E | 返回结果数据 | +| K | O | 返回空果 | ## **数据** @@ -60,3 +61,4 @@ $$ | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | --- | --- | --- | --- | | Brix[15:8] | Brix[7:0] | color[7:0] | long[15:8] | long[7:0] | weight[7:0] | num[15:8] | num[7:0] | area[31:24] | area[23:16] | area[15:8] | area[7:0] | rows[15:8] | rows[7:0] | cols[15:8] | cols[7:0] | | ... | | +**返回空果数据包:‘K’‘O’**,不包含数据字段,仅有**长度字段+指令字段**