Yolov5 串口传输坐标

问题遇到的现象和发生背景 :将Yolov5检测到的目标通过串口发出
yolov5_uart.py部分代码:
# Write results
                counter=0
                for *xyxy, conf, cls in reversed(det):
                    if save_txt:  # Write to file
                        xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist()  # normalized xywh
                        line = (cls, *xywh, conf) if opt.save_conf else (cls, *xywh)  # label format
                        with open(txt_path + '.txt', 'a') as f:
                            f.write(('%g ' * len(line)).rstrip() % line + '\n')

                    if save_img or view_img or uart_yes:  # Add bbox to image
                        label = f'{names[int(cls)]} {conf:.2f}'
                        plot_one_box(xyxy, im0, color=colors[int(cls)], line_thickness=3)
                        xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist()
                        counter=counter+1;
                       #print(int(100*xywh[0]),int(100*xywh[1]),int(100*xywh[2]),int(100*xywh[3]))
                        uart.write(bytearray([255,254]))   #start with FF FE
                        uart.write(bytearray([counter]))   # 
                        uart.write(bytearray([252]))       #first session end with FC
                        for cnt in range(0,4):
                           watertank=int(100*xywh[cnt])
                           high=int(bin(watertank)[:-8],2)
                           low=int(bin(watertank)[-8:],2)  # eight little sessions
                           uart.write(bytearray([watertank]))
                        uart.write(bytearray([251]))       #end with FB

运行结果:

img

img

得到的结果为标签值,而想要的为实际图片中的像素值,但由于值超过256所以将一个值拆分为高低两个八位二进制数发送过去 。

img

理想结果:

img

img

源码位置:https://gitee.com/ai-rujing/yolov5-serial-communication.git