mirror of
https://github.com/NanjingForestryUniversity/supermachine--tomato-passion_fruit.git
synced 2025-11-09 14:54:07 +00:00
fix:应徐耀需要,暂时空果回传指令并未按照协议进行,而是全为0;当前默认全为有果子
This commit is contained in:
parent
e7bbaf4b01
commit
e14f5f1f4e
@ -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
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user