第一章
目标:为了查看自己在标注标签时是否准确,写了这段代码来将标注的框打到原图上
第二章
步骤:进行反归一化得到坐标画出矩形框
第二行是目标图片对应的txt,第三行是目标图片
第三章
全部代码如下:
import cv2
import numpy as np
label_path = 'C:/Users/23918/Desktop/01_missing_hole_01.txt'
image_path = 'C:/Users/23918/Desktop/01_missing_hole_01.jpg'
# 坐标转换,原始存储的是YOLOv5格式
# Convert nx4 boxes from [x, y, w, h] normalized to [x1, y1, x2, y2] where xy1=top-left, xy2=bottom-right
def xywh2xyxy(x, y, w, h, w1, h1, img):
print("原图宽高:\nw1={}\nh1={}".format(w1, h1))
# 边界框反归一化
x_t = x * w1
y_t = y * h1
w_t = w * w1
h_t = h * h1
print("反归一化后输出:\n第一个:{}\t第二个:{}\t第三个:{}\t第四个:{}\t\n\n".format(x_t, y_t, w_t, h_t))
# 计算坐标
top_left_x = x_t - w_t / 2
top_left_y = y_t - h_t / 2
bottom_right_x = x_t + w_t / 2
bottom_right_y = y_t + h_t / 2
print("左上x坐标:{}".format(top_left_x))
print("左上y坐标:{}".format(top_left_y))
print("右下x坐标:{}".format(bottom_right_x))
print("右下y坐标

本文详细描述了如何通过Python代码,利用YOLOv5格式的标注信息,对图像进行反归一化并绘制矩形框,以验证标注的准确性。作者展示了坐标转换和绘制图像的具体步骤。
2173

被折叠的 条评论
为什么被折叠?



