当前位置:网站首页>CCPD data set processing (target detection and text recognition)
CCPD data set processing (target detection and text recognition)
2022-07-27 00:15:00 【~Nothing~】
List of articles
Preface
lately , Yes CCPD Data sets , But open source CCPD Datasets are not easy to use , So I wrote a script with reference to the explanation of image format to generate a script that supports target detection and text recognition label file . All of the following have been CCPD2019 For example .
One 、CCPD Data set introduction
CCPD The data set is mainly collected from the data of a parking lot in Anhui Province for a period of time , All picture sizes are fixed to 720×1160(w×h), It contains about 25w+ Pictures of various scenes , As shown in the figure below :
meanwhile , Also based on CCPD-Base Split the training set 、 Test set 、 Verification set , The file path is stored in splits Next , As shown in the figure :
The remaining text corresponds to the relative path of the picture in each scene , It is convenient for us to divide , It is suggested that you divide the data set according to your own needs .
Two 、 Download address
Download at :CCPD
3、 ... and 、 Format interpretation
After the image is unzipped, it looks like this ,
We can see that the file names here are all composed of a pile of numbers and symbols , What do these represent ? Let's take the first file name :“01-86_91-298&341_449&414-458&394_308&410_304&357_454&341-0_0_14_28_24_26_29-124-24.jpg” For example , according to “-” Separate these symbols from numbers , Each paragraph represents a meaning :
1、01: The proportion of license plates in the whole interface ;( It doesn't work , Negligible )
2、86_91: The horizontal and vertical angles of the license plate
3、298&341_449&414: Coordinates of the upper left corner and lower right corner of the license plate marking box
4、458&394_308&410_304&357_454&341: The coordinates of the four vertices of the license plate , The order is bottom right 、 The lower left 、 Top left 、 The upper right
5、0_0_14_28_24_26_29: This represents and provinces ( first place )、 Local market ( Second )、 license plate number ( rest ) The mapping relation of
6、124: brightness , The higher the value, the higher the brightness ( For reference only )
7、24: Ambiguity , The smaller the value, the more blurred ( For reference only )
Four 、 Generate corresponding lable
Let's go directly to the code , You need to specify your own path in the code , Such as image file path and generation txt The path to save ; secondly , You also need to turn on the corresponding switch according to your task , If the license plate is located use_landmarks Set to True, Other similar :
import os
import glob
import cv2
from pathlib import Path
import numpy as np
root_dir=""
txt_dir=""
use_landmarks=False # For license plate location , Such as MTCNN、YOLO5Face
use_xywh=False # For license plate detection , Such as YOLO etc.
use_ocr=False # Used to identify
os.makedirs(txt_dir,exist_ok=True)
# Returns the coordinates of the center point 、 wide 、 The height and the position information of the four vertices are 12 Messages , Can be used for mtcnn or yolo5Face Detect and locate the license plate
def ccpd_landmarks(points_list,imgw,imgh):
''' Args: points_list: The position information of the four vertices of the license plate imgw: Image width imgh: Picture height Returns: '''
annotation=np.zeros((1,12))
points_list_=[]
# Get four endpoints
for points in points_list.split("_"):
points_=list(map(int,points.split("&")))
points_list_.append(points_)
points_list_=np.array(points_list_)
# Acquired box Coordinates of
xmin=min(points_list_[:,0])
xmax=max(points_list_[:,0])
ymin=min(points_list_[:,1])
ymax=max(points_list_[:,1])
dw=1./imgw
dh=1./imgh
w,h=xmax-xmin,ymax-ymin
# Generate the corresponding information list
annotation[0,0]=((xmin+xmax)/2.-1)*dw #cx
annotation[0,1]=((ymin+ymax)/2.-1)*dh #cy
annotation[0,2]=w*dw #w
annotation[0,3]=h*dh #h
annotation[0,4]=points_list_[2][0]/imgw # Top left x
annotation[0,5]=points_list_[2][1]/imgh # Top left y
annotation[0,6]=points_list_[3][0]/imgw # The upper right x
annotation[0,7]=points_list_[3][1]/imgh # The upper right y
annotation[0,8]=points_list_[0][0]/imgw # The lower right x
annotation[0,9]=points_list_[0][1]/imgh # The upper right y
annotation[0,10]=points_list_[1][0]/imgw # The lower left x
annotation[0,11]=points_list_[1][1]/imgh # The lower left y
return annotation
# Only the coordinates of the center point and the width and height information of the picture are returned , Can be used for YOLO Serial inspection license plate
def ccpd_xywh(points_list,imgw,imgh):
''' Args: points_list: The position information of the four vertices of the license plate imgw: Image width imgh: Picture height Returns: '''
annotation = np.zeros((1, 4))
points_list_ = []
# Get four endpoints
for points in points_list.split("_"):
points_ = list(map(int, points.split("&")))
points_list_.append(points_)
points_list_ = np.array(points_list_)
# Acquired box Coordinates of
xmin=min(points_list_[:,0])
xmax=max(points_list_[:,0])
ymin=min(points_list_[:,1])
ymax=max(points_list_[:,1])
dw=1./imgw
dh=1./imgh
w,h=xmax-xmin,ymax-ymin
# Generate the corresponding information list
annotation[0, 0] = ((xmin + xmax) / 2. - 1) * dw # cx
annotation[0, 1] = ((ymin + ymax) / 2. - 1) * dh # cy
annotation[0, 2] = w * dw # w
annotation[0, 3] = h * dh # h
return annotation
# Return the corresponding text information , Can be used for ocr License plate recognition
def ccpd_ocr(plate):
''' Args: plate: The number in the file name Returns: '''
# License plate dictionary
# province
provinces = [" Wan ", " Shanghai ", " tianjin ", " chongqing ", " Ji ", " Jin ", " Mongolia ", " liao ", " ji ", " black ", " Sue ", " Zhejiang ", " Beijing ", " Fujian ", " Gan ", " Lu ", " Yu ", " E ", " hunan ", " guangdong ",
" guangxi ", " Joan ", " sichuan ", " your ", " cloud ", " hidden ", " shan ", " gump ", " green ", " ning ", " new ", " police ", " learn ", "O"]
# Specific information
word_lists = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
'W','X', 'Y', 'Z', 'O', '1', '2', '3', '4', '5', '6', '7', '8', '9','0']
label_list=plate.split("_")
print(len(label_list))
result=""
result+=provinces[int(label_list[0])]
result+=word_lists[int(label_list[1])]
result+=word_lists[int(label_list[2])]+word_lists[int(label_list[3])]+word_lists[int(label_list[4])]+\
word_lists[int(label_list[5])]+word_lists[int(label_list[6])]
return result
def ccpd2label(all_list):
for imgpath in all_list:
img=cv2.imread(imgpath)
h,w=img.shape[:2]
imgname=Path(imgpath).name
points_list,plate_list=imgname.split("-")[3],imgname.split("-")[4]# Coordinates of the four key points [ The lower right 、 The lower left 、 Top left 、 The upper right ], License plate number mapping table
if use_landmarks:
annotation=ccpd_landmarks(points_list,w,h) # Get to write txt Information about
txtname = imgname.replace(".jpg", ".txt")
txt_path = os.path.join(txt_dir, txtname)
str_label = "0" # The category defaults to 0
with open(txt_path, "a+") as fw:
for i in range(len(annotation[0])):
str_label = str_label + " " + str(annotation[0][i])
fw.write(str_label)
elif use_xywh:
annotation=ccpd_xywh(points_list,w,h) # Get to write txt Information about
txtname = imgname.replace(".jpg", ".txt")
txt_path = os.path.join(txt_dir, txtname)
str_label = "0" # The category defaults to 0
with open(txt_path, "a+") as fw:
for i in range(len(annotation[0])):
str_label = str_label + " " + str(annotation[0][i])
fw.write(str_label)
elif use_ocr:
ocr_label=ccpd_ocr(plate_list)
txtname=imgname.replace(".jpg",".txt")
txt_path=os.path.join(txt_dir,txtname)
with open(txt_path,"a+") as fw:
fw.write(ocr_label)
if __name__ == '__main__':
image_list=glob.glob(root_dir+os.sep+"*.jpg")
ccpd2label(image_list)
Reference blog :https://blog.csdn.net/luohenyj/article/details/117752120
summary
The above is the whole content of this article , If you have any questions , Welcome to comment or join QQ Group :995760755 communication .
边栏推荐
- Upload files to the server
- Share a regular expression
- Codeforces E. maximum subsequence value (greed + pigeon nest principle)
- [Gorm] model relationship -hasone
- 11_ Weather case - monitoring properties
- 第1章 需求分析与ssm环境准备
- Design of intelligent humidification controller based on 51 single chip microcomputer
- Chapter 1 Introduction and use skills of interceptors
- Apple TV HD with the first generation Siri remote is listed as obsolete
- Relationship between limit, continuity, partial derivative and total differential of multivariate function (learning notes)
猜你喜欢

Chapter 1 develop the first restful application

About no module named'django.db.backends.mysql'

What scenarios are Tencent cloud lightweight application servers suitable for?

买不到的数目

Apple TV HD with the first generation Siri remote is listed as obsolete

In depth interpretation of the investment logic of the consortium's participation in the privatization of Twitter

Anaconda => PyCharm => CUDA => cudnn => PyTorch 环境配置

In simple terms, cchart daily lesson - happy high school lesson 57 new starting point, the old tree and new bud of colorful interface library

Chapter 1 Introduction and use skills of interceptors

知识蒸馏——pytorch实现
随机推荐
The difference between SQL join and related subinquiry
[interview: concurrency 26: multithreading: two-phase termination mode] volatile version
Practice of data storage scheme in distributed system
分页插件--PageHelper
买不到的数目
Codeforces d.constructing the array (priority queue)
【C语言】数组
What is Tencent cloud lightweight application server? What are the differences between CVM and ECS?
DHCP, VLAN, NAT, large comprehensive experiment
Azure synapse analytics Performance Optimization Guide (4) -- optimize performance using result set caching
At 12:00 on July 17, 2022, the departure of love life on June 28 was basically completed, and it needs to rebound
Section 6: introduction to cmake grammar
Familiarize you with the "phone book" of cloud network: DNS
Chapter 2 develop user traffic interceptors
In simple terms, cchart's daily lesson - Lesson 59 of happy high school 4 comes to the same end by different ways, and the C code style of the colorful interface library
滑动窗口问题总结
Simple SQL optimization
机器学习模型——lightGBM
The basic operation of data tables in MySQL is very difficult. This experiment will take you through it from the beginning
Transformers is a graph neural network