import cv2
import 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)
CCPD数据转成YOLO v5数据格式
最新推荐文章于 2026-04-04 09:57:10 发布
本文介绍了一种基于Python的车牌检测数据集标注方法。该方法读取特定路径下的图片文件,并通过解析文件名获取车牌位置信息,将其转换为YOLO格式的标注文件。适用于定制化的车牌检测训练数据准备。
CLIP-GmP-ViT-L-14编码模型
CLIP-GmP-ViT-L-14编码模型` 是一个图文双塔编码模型,适合做图文匹配、零样本分类和跨模态检索演示。本镜像已经完成 Web 部署,打开页面即可上传图片并测试图文表征能力
您可能感兴趣的与本文相关的镜像
CLIP-GmP-ViT-L-14编码模型
图像识别
CLIP
CLIP-GmP-ViT-L-14编码模型` 是一个图文双塔编码模型,适合做图文匹配、零样本分类和跨模态检索演示。本镜像已经完成 Web 部署,打开页面即可上传图片并测试图文表征能力


2291

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



