yolov5输出检测到的目标坐标信息

找到detect.py文件
在这里插入图片描述

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 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 save_crop or view_img:  # Add bbox to image
        c = int(cls)  # integer class
        label = None if hide_labels else (names[c] if hide_conf else f'{names[c]} {conf:.2f}')
        annotator.box_label(xyxy, label, color=colors(c, True))
        if save_crop:
            save_one_box(xyxy, imc, file=save_dir / 'crops' / names[c] / f'{p.stem}.jpg', BGR=True)

进入box_label函数
在这里插入图片描述

108-110行是新增的打印坐标,加到101行后

                print("zuo shang:(" + str(p1[0]) + "," + str(p1[1]) + "),you shang:(" + str(p2[0]) + "," + str(p1[1]) + ")")
                print("zuo xia:(" + str(p1[0]) + "," + str(p2[1]) + "),you xia:(" + str(p2[0]) + "," + str(p2[1]) + ")")
                print("center("+str((p2[0]-p1[0])/2+p1[0])+","+str((p2[1]-p1[1])/2+p1[1])+ ")")

在这里插入图片描述
结果能打出来

猜你喜欢

转载自blog.csdn.net/Qingyou__/article/details/124095436