主要用于一些格式转换后,检查转换后的坐标是否有问题
import cv2
img_path = "/ai32jjg/codes/data/qishi_dom/20241104091655_car_dom/0_0.tif"
txt_path = "/ai32jjg/codes/data/qishi_dom/20241104091655_car_dom/0_0.txt"
cv_img = cv2.imread(img_path)
img_width = cv_img.shape[1]
img_height = cv_img.shape[0]
point_color = (255, 255, 0) # BGR
thickness = 3
lineType = 4
labels = open(txt_path, "r").readlines()
for lab in labels:
# print(lab)
lab_arr = lab.split(" ")
# print(lab_arr)
x1, y1 = int(float(lab_arr[1]) * img_width), int(float(lab_arr[2]) * img_height)
x2, y2 = int(float(lab_arr[3]) * img_width), int(float(lab_arr[4]) * img_height)
x3, y3 = int(float(lab_arr[5]) * img_width), int(float(lab_arr[6]) * img_height)
x4, y4 = int(float(lab_arr[7]) * img_width), int(float(lab_arr[8]) * img_height)
cv2.line(cv_img, (x1, y1), (x2, y2), point_color, thickness, lineType)
cv2.line(cv_img, (x2, y2), (x3, y3), point_color, thickness, lineType)
cv2.line(cv_img, (x3, y3), (x4, y4), point_color, thickness, lineType)
cv2.line(cv_img, (x4, y4), (x1, y1), point_color, thickness, lineType)
cv2.imwrite("test_yolo.jpg", cv_img)