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

找到detect.py文件
yolov5输出检测到的目标坐标信息_第1张图片

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函数
yolov5输出检测到的目标坐标信息_第2张图片

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])+ ")")

yolov5输出检测到的目标坐标信息_第3张图片
结果能打出来

你可能感兴趣的:(python,人工智能)