当前位置:网站首页>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 .
边栏推荐
- Chapter 3 cross domain issues
- Pytorch学习记录(二):张量
- What is Tencent cloud lightweight application server? What are the differences between CVM and ECS?
- Pytorch data pipeline standardized code template
- Abstract classes and interfaces (sorting out some knowledge points)
- Complex SQL_ 01
- 10_ Name Case - Calculation attribute
- Arthas quick start
- push to origin/master was rejected 错误解决方法
- Everything you should know about wearable NFT!
猜你喜欢

Question 141 of Li Kou: circular linked list
![[C language] array](/img/b7/fe090984af689e45cf3492ff8d4c61.png)
[C language] array

深度学习调参技巧

第1章 开发第一个restful应用

C and pointer Chapter 18 runtime environment 18.1 judgment of runtime environment

Share a regular expression

Codeforces C1. Simple Polygon Embedding

The attorney general and the director of the national security service of Ukraine were dismissed

ResNet论文解读及代码实现(pytorch)

04 traditional synchronized lock
随机推荐
Add an article ----- scanf usage
In simple terms, cchart daily lesson - happy high school lesson 57 new starting point, the old tree and new bud of colorful interface library
New features of ES6
Typesript generic constraint
DHCP, VLAN, NAT, large comprehensive experiment
深度学习调参技巧
[interview: concurrency 26: multithreading: two-phase termination mode] volatile version
Paging plug-in -- PageHelper
Skiasharp's WPF self drawn bouncing ball (case version)
Several search terms
Anaconda => PyCharm => CUDA => cudnn => PyTorch 环境配置
C language array
2022.7.18-----leetcode.749
Meeting OA project seating function and submission function
Chapter 1 develop the first restful application
Push to origin/master was rejected error resolution
4. Talk about the famous Zhang Zhengyou calibration method
Tree and binary tree (learning notes)
09_ Keyboard events
08 design of intelligent agricultural environmental monitoring system based on ZigBee