YOLO格式的旋转框标注在图像上显示

主要用于一些格式转换后,检查转换后的坐标是否有问题

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值