首页 > 编程知识 正文

CCPD数据转成YOLO v5数据格式,mat转voc数据格式

时间:2023-05-06 05:16:17 阅读:188567 作者:30

import cv2import os#参考 https://blog.csdn.net/qq_36516958/article/details/114274778# https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data#2-create-labels# path = "/public/ccpd_green/test/"path = "/public/CCPD2019/ccpd_challenge/"for filename in os.listdir(path): list1 = filename.split("-", 3) # 第一次分割,以减号'-'做分割 subname = list1[2] lt, rb = subname.split("_", 1) #第二次分割,以下划线'_'做分割 lx, ly = lt.split("&", 1) rx, ry = rb.split("&", 1) width = int(rx) - int(lx) height = int(ry) - int(ly) # bounding box的宽和高 cx = float(lx) + width/2 cy = float(ly) + height/2 #bounding box中心点 img = cv2.imread(path + filename) width = width/img.shape[1] height = height/img.shape[0] cx = cx/img.shape[1] cy = cy/img.shape[0] txtname = filename.split(".", 1) txtfile = path + txtname[0] + ".txt" # 绿牌是第0类,蓝牌是第1类 with open(txtfile, "w") as f: f.write(str(1)+" "+str(cx)+" "+str(cy)+" "+str(width)+" "+str(height)) print(filename) print(txtfile) print(img.shape) print(cx) print(cy) print(width) print(height)

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。