From e14f5f1f4ef9d76614b260486851c370222000a3 Mon Sep 17 00:00:00 2001 From: TG <905865530@qq.com> Date: Tue, 18 Jun 2024 16:32:38 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E5=BA=94=E5=BE=90=E8=80=80?= =?UTF-8?q?=E9=9C=80=E8=A6=81=EF=BC=8C=E6=9A=82=E6=97=B6=E7=A9=BA=E6=9E=9C?= =?UTF-8?q?=E5=9B=9E=E4=BC=A0=E6=8C=87=E4=BB=A4=E5=B9=B6=E6=9C=AA=E6=8C=89?= =?UTF-8?q?=E7=85=A7=E5=8D=8F=E8=AE=AE=E8=BF=9B=E8=A1=8C=EF=BC=8C=E8=80=8C?= =?UTF-8?q?=E6=98=AF=E5=85=A8=E4=B8=BA0=EF=BC=9B=E5=BD=93=E5=89=8D?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E5=85=A8=E4=B8=BA=E6=9C=89=E6=9E=9C=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 20240529RGBtest3/main.py | 8 +++++--- 20240529RGBtest3/utils.py | 40 ++++++++++++++++++++++++++++----------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/20240529RGBtest3/main.py b/20240529RGBtest3/main.py index 9b009ef..abd9599 100644 --- a/20240529RGBtest3/main.py +++ b/20240529RGBtest3/main.py @@ -124,13 +124,15 @@ def main(is_debug=False): print(f'接收一张图时间:{end_time1 - start_time1}秒') # 使用分类器进行预测 - prediction = classifier.predict(img) - print(f'预测结果:{prediction}') + # prediction = classifier.predict(img) + # print(f'预测结果:{prediction}') + #默认全为有果 + prediction = 1 if prediction == 1: images.append(img) else: response = pipe.send_data(cmd='KO', brix=0, diameter=0, green_percentage=0, weigth=0, defect_num=0, - total_defect_area=0, rp=None) + total_defect_area=0, rp=np.zeros((100, 100, 3), dtype=np.uint8)) print("图像中无果,跳过此图像") continue diff --git a/20240529RGBtest3/utils.py b/20240529RGBtest3/utils.py index ea7c5bd..b802ba1 100644 --- a/20240529RGBtest3/utils.py +++ b/20240529RGBtest3/utils.py @@ -173,17 +173,17 @@ class Pipe: :return: ''' cmd = cmd.strip().upper() - if cmd == 'KO': - cmd_ko = cmd.encode('ascii') - length = (2).to_bytes(4, byteorder='big') # 因为只有KO两个字节,所以长度是2 - send_message = length + cmd_ko - try: - win32file.WriteFile(self.rgb_send, send_message) - print('KO消息发送成功') - except Exception as e: - logging.error(f'发送KO指令失败,错误类型:{e}') - return False - return True + # if cmd == 'KO': + # cmd_ko = cmd.encode('ascii') + # length = (2).to_bytes(4, byteorder='big') # 因为只有KO两个字节,所以长度是2 + # send_message = length + cmd_ko + # try: + # win32file.WriteFile(self.rgb_send, send_message) + # print('KO消息发送成功') + # except Exception as e: + # logging.error(f'发送KO指令失败,错误类型:{e}') + # return False + # return True cmd_type = 'RE' cmd_re = cmd_type.upper().encode('ascii') @@ -211,6 +211,24 @@ class Pipe: gp = gp.to_bytes(1, byteorder='big') weigth = weigth.to_bytes(1, byteorder='big') send_message = length + cmd_re + brix + gp + diameter + weigth + defect_num + total_defect_area + height + width + img_bytes + elif cmd == 'KO': + brix = 0 + brix = brix.to_bytes(2, byteorder='big') + gp = 0 + gp = gp.to_bytes(1, byteorder='big') + weigth = 0 + weigth = weigth.to_bytes(1, byteorder='big') + defect_num = 0 + defect_num = defect_num.to_bytes(2, byteorder='big') + total_defect_area = 0 + total_defect_area = total_defect_area.to_bytes(4, byteorder='big') + height = 100 + height = height.to_bytes(2, byteorder='big') + width = 100 + width = width.to_bytes(2, byteorder='big') + img_bytes = np.zeros((100, 100, 3), dtype=np.uint8).tobytes() + length = (18).to_bytes(4, byteorder='big') + send_message = length + cmd_re + brix + gp + diameter + weigth + defect_num + total_defect_area + height + width + img_bytes try: win32file.WriteFile(self.rgb_send, send_message) # time.sleep(0.01)