当前位置: 首页 > news >正文

CCPD 车牌数据集提取标注,并转为标准 YOLO 格式

目录

介绍

转换代码                                          

下载地址:


介绍

        CCPD 是一个大型的、多样化的、经过仔细标注的中国城市车牌开源数据集。CCPD 数据集主要分为 CCPD2019 数据集和 CCPD2020(CCPD-Green)数据集。CCPD2019 数据集车牌类型仅有普通车牌(蓝色车牌),CCPD2020 数据集车牌类型仅有新能源车牌(绿色车牌)。

 具体介绍可以看看这篇:

[深度学习] CCPD车牌数据集介绍_ccpd数据集-CSDN博客https://blog.csdn.net/LuohenYJ/article/details/117752120

下载地址在文末,只要数据集的直接下滑

下载后是这样的:

        可以看到,该数据集包含的场景还是很丰富的,并且数据量也特多,cpdd_base 里甚至有 20w 数据,每个图片名字的文件就是该图片的标注(除了 ccpd_np 文件夹),例如下面这个文件:

01-86_91-298&341_449&414-458&394_308&410_304&357_454&341-0_0_14_28_24_26_29-124-24

我们按照  “-”  分割这个字符串,得到如下结果:

01编号
86_91车牌水平偏转和垂直偏转角
298&341_449&414车牌左上角坐标和右下角坐标(目标识别矩形框)
458&394_308&410_304&357_454&341车牌的四个角点,按照顺序分别为右下、左下、左上、右上(yolo-pose姿态识别)
0_0_14_28_24_26_29车牌号码
124亮度
24模糊度

转换代码                                          

知道字符串各个含义以及连接规则后,则可以通过字符分割字符串,并提取需要的信息,并将

信息批量保存至 txt 文件即可,我这里为大家提供两段代码,一段提取车牌目标识别(仅矩形框),一段提取车牌姿态(矩形框+4个角点)。

车牌目标识别提取:

import os
import cv2def parse_bbox_from_filename(filename):"""从文件名中解析出车牌目标矩形框的左上角、右下角坐标。"""parts = filename.split('-')# 解析矩形框坐标bbox_part = parts[2].split('_')x1, y1 = map(int, bbox_part[0].split('&'))  # 左上角x2, y2 = map(int, bbox_part[1].split('&'))  # 右下角return (x1, y1), (x2, y2)def get_bbox(x_min, y_min, x_max, y_max, img_w, img_h):"""根据给定的最小最大坐标计算YOLO格式的bbox(中心点坐标、宽度、高度)。"""x_center = round((x_min + x_max) / 2 / img_w, 6)y_center = round((y_min + y_max) / 2 / img_h, 6)width = round((x_max - x_min) / img_w, 6)height = round((y_max - y_min) / img_h, 6)return x_center, y_center, width, heightif __name__ == '__main__':images_dir = r'D:\tcy_works\data\CCPD2019\ccpd_base'  # 替换为你自己的图像路径save_dir = r'D:\tcy_works\data\CCPD_deal\CCPD2019\ccpd_base'  # 替换为你想保存结果的路径os.makedirs(os.path.join(save_dir, "labels"), exist_ok=True)image_files = [os.path.join(images_dir, f) for f in os.listdir(images_dir) if f.lower().endswith(('.jpg', '.png'))]for image_path in image_files:filename = os.path.basename(image_path)try:(x_min, y_min), (x_max, y_max) = parse_bbox_from_filename(filename)except Exception as e:print(f"解析文件名失败: {filename}, 错误: {e}")continueimg = cv2.imread(image_path)if img is None:print(f"读取图像失败: {image_path}")continueheight, width = img.shape[:2]# 计算 bounding boxx_center, y_center, w_bbox, h_bbox = get_bbox(x_min, y_min, x_max, y_max, width, height)# 构建 YOLO 格式标注(仅 bbox)class_id = 0  # 假设类别ID为0label_line = [class_id, x_center, y_center, w_bbox, h_bbox]label_line = list(map(str, label_line))# 保存 label 文件label_file = os.path.join(save_dir, "labels", os.path.splitext(filename)[0] + ".txt")with open(label_file, 'w') as f:f.write(' '.join(label_line) + '\n')print(f"已处理图像: {filename}")print("所有图像处理完成!")

车牌姿态提取:

import os
import cv2def parse_points_from_filename(filename):"""从文件名中解析出车牌目标矩形框的左上角、右下角坐标以及车牌四个角点坐标。"""parts = filename.split('-')# 解析矩形框坐标bbox_part = parts[2].split('_')x1, y1 = map(int, bbox_part[0].split('&'))  # 左上角x2, y2 = map(int, bbox_part[1].split('&'))  # 右下角# 解析角点坐标:parts[3] 如 '458&394_308&410_304&357_454&341'points = []for point in parts[3].split('_'):x, y = map(int, point.split('&'))points.append((x, y))return (x1, y1), (x2, y2), pointsdef normalize_points(points, img_w, img_h):"""将点坐标归一化到 [0, 1] 范围内,并保留 6 位小数。返回列表格式:[x1, y1, vis1, x2, y2, vis2, ..., xn, yn, visn]"""norm_points = []for x, y in points:x_norm = round(x / img_w, 6)y_norm = round(y / img_h, 6)visibility = 2.000000  # YOLO-Pose 中表示该关键点始终可见norm_points.extend([x_norm, y_norm, visibility])return norm_pointsdef get_bbox(x_min, y_min, x_max, y_max, img_w, img_h):"""根据给定的最小最大坐标计算YOLO格式的bbox(中心点坐标、宽度、高度)。"""x_center = round((x_min + x_max) / 2 / img_w, 6)y_center = round((y_min + y_max) / 2 / img_h, 6)width = round((x_max - x_min) / img_w, 6)height = round((y_max - y_min) / img_h, 6)return x_center, y_center, width, heightif __name__ == '__main__':images_dir = r'D:\tcy_works\data\CCPD2019\ccpd_base'  # 替换为你自己的图像路径save_dir = r'D:\tcy_works\data\CCPD_deal\CCPD2019\ccpd_base'  # 替换为你想保存结果的路径os.makedirs(os.path.join(save_dir, "labels"), exist_ok=True)image_files = [os.path.join(images_dir, f) for f in os.listdir(images_dir) if f.lower().endswith(('.jpg', '.png'))]for image_path in image_files:filename = os.path.basename(image_path)try:(x_min, y_min), (x_max, y_max), points = parse_points_from_filename(filename)except Exception as e:print(f"解析文件名失败: {filename}, 错误: {e}")continueimg = cv2.imread(image_path)if img is None:print(f"读取图像失败: {image_path}")continueheight, width = img.shape[:2]# 计算 bounding boxx_center, y_center, w_bbox, h_bbox = get_bbox(x_min, y_min, x_max, y_max, width, height)# 归一化角点坐标 + 添加可见性(每个角点加一个 2.000000)norm_points = normalize_points(points, width, height)# 构建 YOLO-Pose 格式标注class_id = 0  # 假设类别ID为0label_line = [class_id, x_center, y_center, w_bbox, h_bbox] + norm_pointslabel_line = list(map(lambda x: f"{x:.6f}", label_line))  # 统一保留6位小数# 保存 label 文件label_file = os.path.join(save_dir, "labels", os.path.splitext(filename)[0] + ".txt")with open(label_file, 'w') as f:f.write(' '.join(label_line) + '\n')print(f"已处理图像: {filename}")print("所有图像处理完成!")

 下载地址:

百度网盘(密码:ol3j)https://pan.baidu.com/share/init?surl=JSpc9BZXFlPkXxRK4qUCyw

drive.google.comhttps://drive.google.com/file/d/1m8w1kFxnCEiqz_-t2vTcgrgqNIv986PR/view?usp=sharing

感谢您的观看!!!

http://www.dtcms.com/a/277706.html

相关文章:

  • C++--红黑树封装实现set和map
  • duckdb和pyarrow读写arrow格式的方法
  • H3C无线旁挂2层直接转发组网模拟实验
  • opendrive文件的格式
  • 专业PPT图片提取工具,操作简单
  • 【Python练习】041. 编写一个函数,检查一个二叉树是否是平衡二叉树
  • 大数据在UI前端的应用深化研究:用户行为数据的情感分析
  • MySQL实操:将Word表格数据导入MySQL表
  • python学习——Matplotlib库的基础
  • 4. MyISAM vs InnoDB:深入解析MySQL两大存储引擎
  • c语言进阶 深度剖析数据在内存中的存储
  • Spring-----MVC配置和基本原理
  • Opencv---blobFromImage
  • macos安装iper3
  • Java面试(基础题)-第一篇!
  • C++模版编程:类模版与继承
  • QCustomPlot绘图结合滑动条演示
  • anaconda常用命令
  • 第一个Flink 程序 WordCount,词频统计(批处理)
  • 从架构到代码:飞算JavaAI电商订单管理系统技术解构
  • 关键点检测 roboflow 折弯识别
  • 从“被动巡检”到“主动预警”:塔能物联运维平台重构路灯管理模式
  • Word 文字编辑状态下按回车换行后是非正文格式
  • 【LeetCode 热题 100】23. 合并 K 个升序链表——(解法一)逐一合并
  • FastAPI快速构建完成一个简单的demo,(curd)
  • 深入理解 Java JVM
  • BERT系列模型
  • Spring Boot 配置注解处理器 - spring-boot-configuration-processor
  • Python I/O 库【输入输出】全面详解
  • JavaScript加强篇——第九章 正则表达式高级应用(终)