深度学习目标检测---yolov5网络打印输出检测框的像素坐标信息

1.打开yolov5项目,然后打开dectect.py文件。

 2.按键盘 Ctrl+F 进入查找功能,输入 plot_one_box  找到对应的函数。如下图所示:

 3.将鼠标放置在该函数上,按住 Ctrl 键,然后 点击 进入该函数。如下图所示:

 这里面的函数就是对检测矩形框的输出。

4.在plot_one_box函数下打印坐标信息,添加以下 print() 代码即可:

def plot_one_box(x, img, color=None, label=None, line_thickness=3):
    # Plots one bounding box on image img
    tl = line_thickness or round(0.002 * (img.shape[0] + img.shape[1]) / 2) + 1  # line/font thickness
    color = color or [random.randint(0, 255) for _ in range(3)]
    c1, c2 = (int(x[0]), int(x[1])), (int(x[2]), int(x[3]))
    cv2.rectangle(img, c1, c2, color, thickness=tl, lineType=cv2.LINE_AA)
    print("左上点的坐标为:(" + str(c1[0]) + "," + str(c1[1]) + "),右上点的坐标为(" + str(c2[0]) + "," + str(c1[1]) + ")")
    print("左下点的坐标为:(" + str(c1[0]) + "," + str(c2[1]) + "),右下点的坐标为(" + str(c2[0]) + "," + str(c2[1]) + ")")
    print("中心点的坐标为:("+str((c2[0]-c1[0])/2+c1[0])+","+str((c2[1]-c1[1])/2+c1[1])+ ")")

5.回到 dectect.py 文件,点击 运行 程序即可生成坐标信息。

 

猜你喜欢

转载自blog.csdn.net/weixin_42795788/article/details/121862368