Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
we0091234 committed Sep 15, 2022
0 parents commit 9588838
Show file tree
Hide file tree
Showing 192 changed files with 18,573 additions and 0 deletions.
1 change: 1 addition & 0 deletions CCPD2019
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/mnt/Gpan/BaiduNetdiskDownload/CCPD2019/
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
环境配置:

```
pip install -r requirements.txt
```

运行:

```
python detect_plate.py
```

测试文件夹imgs,结果保存再 result 文件夹中

parser.add_argument('--image_path', type=str, default='imgs', help='source') # file/folder, 0 for webcam

--image_path 修改为自己的路劲即可

车牌检测参考:

yolov5-face:

[deepcam-cn/yolov5-face: YOLO5Face: Why Reinventing a Face Detector (https://arxiv.org/abs/2105.12931) ECCV Workshops 2022) (github.com)](https://github.com/deepcam-cn/yolov5-face)

车牌识别参考:

crnn:

[bgshih/crnn: Convolutional Recurrent Neural Network (CRNN) for image-based sequence recognition. (github.com)](https://github.com/bgshih/crnn)


支持如下:

1.蓝牌 2.黄牌 3.双层黄牌 4.农用车牌 5 警车 6 校车 7 教练车 8 港澳车牌 9 使领馆 10 武警 11 新能源 12 等等。。。

![Image text](result/3.jpg)
Binary file added __pycache__/test.cpython-38.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions ccpd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../datasets/ccpd/
196 changes: 196 additions & 0 deletions ccpd_process.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
import os
import shutil
import cv2
import numpy as np
def allFilePath(rootPath,allFIleList):
fileList = os.listdir(rootPath)
for temp in fileList:
if os.path.isfile(os.path.join(rootPath,temp)):
if temp.endswith(".jpg"):
allFIleList.append(os.path.join(rootPath,temp))
else:
allFilePath(os.path.join(rootPath,temp),allFIleList)

def order_points(pts):
# initialzie a list of coordinates that will be ordered
# such that the first entry in the list is the top-left,
# the second entry is the top-right, the third is the
# bottom-right, and the fourth is the bottom-left
pts=pts[:4,:]
rect = np.zeros((5, 2), dtype = "float32")

# the top-left point will have the smallest sum, whereas
# the bottom-right point will have the largest sum
s = pts.sum(axis = 1)
rect[0] = pts[np.argmin(s)]
rect[2] = pts[np.argmax(s)]

# now, compute the difference between the points, the
# top-right point will have the smallest difference,
# whereas the bottom-left will have the largest difference
diff = np.diff(pts, axis = 1)
rect[1] = pts[np.argmin(diff)]
rect[3] = pts[np.argmax(diff)]

# return the ordered coordinates
return rect

def get_partical_ccpd():
ccpd_dir = r"/mnt/Gpan/BaiduNetdiskDownload/CCPD1/CCPD2020/ccpd_green"
save_Path = r"ccpd/green_plate"
folder_list = os.listdir(ccpd_dir)
for folder_name in folder_list:
count=0
folder_path = os.path.join(ccpd_dir,folder_name)
if os.path.isfile(folder_path):
continue
if folder_name == "ccpd_fn":
continue
name_list = os.listdir(folder_path)

save_folder=save_Path
if not os.path.exists(save_folder):
os.mkdir(save_folder)

for name in name_list:
file_path = os.path.join(folder_path,name)
count+=1
if count>1000:
break
new_file_path =os.path.join(save_folder,name)
shutil.move(file_path,new_file_path)
print(count,new_file_path)

def get_rect_and_landmarks(img_path):
file_name = img_path.split("/")[-1].split("-")
landmarks_np =np.zeros((5,2))
rect = file_name[2].split("_")
landmarks=file_name[3].split("_")
rect_str = "&".join(rect)
landmarks_str= "&".join(landmarks)
rect= rect_str.split("&")
landmarks=landmarks_str.split("&")
rect=[int(x) for x in rect]
landmarks=[int(x) for x in landmarks]
for i in range(4):
landmarks_np[i][0]=landmarks[2*i]
landmarks_np[i][1]=landmarks[2*i+1]
middle_landmark_w =int((landmarks[4]+landmarks[6])/2)
middle_landmark_h =int((landmarks[5]+landmarks[7])/2)
landmarks.append(middle_landmark_w)
landmarks.append(middle_landmark_h)
landmarks_np_new=order_points(landmarks_np)
landmarks_np_new[4]=np.array([middle_landmark_w,middle_landmark_h])
return rect,landmarks,landmarks_np_new

def x1x2y1y2_yolo(rect,landmarks,img):
h,w,c =img.shape
rect[0] = max(0, rect[0])
rect[1] = max(0, rect[1])
rect[2] = min(w - 1, rect[2]-rect[0])
rect[3] = min(h - 1, rect[3]-rect[1])
annotation = np.zeros((1, 14))
annotation[0, 0] = (rect[0] + rect[2] / 2) / w # cx
annotation[0, 1] = (rect[1] + rect[3] / 2) / h # cy
annotation[0, 2] = rect[2] / w # w
annotation[0, 3] = rect[3] / h # h

annotation[0, 4] = landmarks[0] / w # l0_x
annotation[0, 5] = landmarks[1] / h # l0_y
annotation[0, 6] = landmarks[2] / w # l1_x
annotation[0, 7] = landmarks[3] / h # l1_y
annotation[0, 8] = landmarks[4] / w # l2_x
annotation[0, 9] = landmarks[5] / h # l2_y
annotation[0, 10] = landmarks[6] / w # l3_x
annotation[0, 11] = landmarks[7] / h # l3_y
annotation[0, 12] = landmarks[8] / w # l4_x
annotation[0, 13] = landmarks[9] / h # l4_y
return annotation

def xywh2yolo(rect,landmarks_sort,img):
h,w,c =img.shape
rect[0] = max(0, rect[0])
rect[1] = max(0, rect[1])
rect[2] = min(w - 1, rect[2]-rect[0])
rect[3] = min(h - 1, rect[3]-rect[1])
annotation = np.zeros((1, 14))
annotation[0, 0] = (rect[0] + rect[2] / 2) / w # cx
annotation[0, 1] = (rect[1] + rect[3] / 2) / h # cy
annotation[0, 2] = rect[2] / w # w
annotation[0, 3] = rect[3] / h # h

annotation[0, 4] = landmarks_sort[0][0] / w # l0_x
annotation[0, 5] = landmarks_sort[0][1] / h # l0_y
annotation[0, 6] = landmarks_sort[1][0] / w # l1_x
annotation[0, 7] = landmarks_sort[1][1] / h # l1_y
annotation[0, 8] = landmarks_sort[2][0] / w # l2_x
annotation[0, 9] = landmarks_sort[2][1] / h # l2_y
annotation[0, 10] = landmarks_sort[3][0] / w # l3_x
annotation[0, 11] = landmarks_sort[3][1] / h # l3_y
annotation[0, 12] = landmarks_sort[4][0] / w # l4_x
annotation[0, 13] = landmarks_sort[4][1] / h # l4_y
return annotation

def yolo2x1y1x2y2(annotation,img):
h,w,c = img.shape
rect= annotation[:,0:4].squeeze().tolist()
landmarks=annotation[:,4:].squeeze().tolist()
rect_w = w*rect[2]
rect_h =h*rect[3]
rect_x =int(rect[0]*w-rect_w/2)
rect_y = int(rect[1]*h-rect_h/2)
new_rect=[rect_x,rect_y,rect_x+rect_w,rect_y+rect_h]
for i in range(5):
landmarks[2*i]=landmarks[2*i]*w
landmarks[2*i+1]=landmarks[2*i+1]*h
return new_rect,landmarks

def write_lable(file_path):
pass


if __name__ == '__main__':
file_root = r"ccpd/val"
file_list=[]
count=0
allFilePath(file_root,file_list)
for img_path in file_list:
count+=1
# img_path = r"ccpd_yolo_test/02-90_85-173&466_452&541-452&553_176&556_178&463_454&460-0_0_6_26_15_26_32-68-53.jpg"
text_path= img_path.replace(".jpg",".txt")
img =cv2.imread(img_path)
rect,landmarks,landmarks_sort=get_rect_and_landmarks(img_path)
# annotation=x1x2y1y2_yolo(rect,landmarks,img)
annotation=xywh2yolo(rect,landmarks_sort,img)
str_label = "0 "
for i in range(len(annotation[0])):
str_label = str_label + " " + str(annotation[0][i])
str_label = str_label.replace('[', '').replace(']', '')
str_label = str_label.replace(',', '') + '\n'
with open(text_path,"w") as f:
f.write(str_label)
print(count,img_path)
# get_partical_ccpd()
# file_root = r"ccpd/green_plate"
# file_list=[]
# allFilePath(file_root,file_list)
# count=0
# for img_path in file_list:
# img_name = img_path.split(os.sep)[-1]
# if not "&" in img_name:
# count+=1
# os.remove(img_path)
# print(count,img_path)

# new_rect,new_landmarks=yolo2x1y1x2y2(annotation,img)
# rect= [int(x) for x in new_rect]
# cv2.rectangle(img,(rect[0],rect[1]),(rect[2],rect[3]),(255,0,0),2)
# colors=[(0,255,0),(0,255,255),(255,255,0),(255,255,255),(255,0,255)] #绿 黄 青 白
# for i in range(5):
# cv2.circle(img,(landmarks[2*i],landmarks[2*i+1]),2,colors[i],2)
# cv2.imwrite("1.jpg",img)
# print(rect,landmarks)
# get_partical_ccpd()



Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0.6277 0.4767 0.2444 0.4793 0.2472 0.3991 0.6305 0.3965 0.4388 0.3974
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 0.4340277777777778 0.434051724137931 0.3875 0.06465517241379311 0.24722222222222223 0.39913793103448275 0.6305555555555555 0.39655172413793105 0.6277777777777778 0.47672413793103446 0.24444444444444444 0.4793103448275862 0.4388888888888889 0.39741379310344827
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions data/argoverse_hd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Argoverse-HD dataset (ring-front-center camera) http://www.cs.cmu.edu/~mengtial/proj/streaming/
# Train command: python train.py --data argoverse_hd.yaml
# Default dataset location is next to /yolov5:
# /parent_folder
# /argoverse
# /yolov5


# download command/URL (optional)
download: bash data/scripts/get_argoverse_hd.sh

# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/]
train: ../argoverse/Argoverse-1.1/images/train/ # 39384 images
val: ../argoverse/Argoverse-1.1/images/val/ # 15062 iamges
test: ../argoverse/Argoverse-1.1/images/test/ # Submit to: https://eval.ai/web/challenges/challenge-page/800/overview

# number of classes
nc: 8

# class names
names: [ 'person', 'bicycle', 'car', 'motorcycle', 'bus', 'truck', 'traffic_light', 'stop_sign' ]
35 changes: 35 additions & 0 deletions data/coco.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# COCO 2017 dataset http://cocodataset.org
# Train command: python train.py --data coco.yaml
# Default dataset location is next to /yolov5:
# /parent_folder
# /coco
# /yolov5


# download command/URL (optional)
download: bash data/scripts/get_coco.sh

# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/]
train: ../coco/train2017.txt # 118287 images
val: ../coco/val2017.txt # 5000 images
test: ../coco/test-dev2017.txt # 20288 of 40670 images, submit to https://competitions.codalab.org/competitions/20794

# number of classes
nc: 80

# class names
names: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light',
'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow',
'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard',
'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple',
'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch',
'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone',
'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear',
'hair drier', 'toothbrush' ]

# Print classes
# with open('data/coco.yaml') as f:
# d = yaml.load(f, Loader=yaml.FullLoader) # dict
# for i, x in enumerate(d['names']):
# print(i, x)
28 changes: 28 additions & 0 deletions data/coco128.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# COCO 2017 dataset http://cocodataset.org - first 128 training images
# Train command: python train.py --data coco128.yaml
# Default dataset location is next to /yolov5:
# /parent_folder
# /coco128
# /yolov5


# download command/URL (optional)
download: https://github.com/ultralytics/yolov5/releases/download/v1.0/coco128.zip

# train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/]
train: ../coco128/images/train2017/ # 128 images
val: ../coco128/images/train2017/ # 128 images

# number of classes
nc: 80

# class names
names: [ 'person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'train', 'truck', 'boat', 'traffic light',
'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow',
'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard',
'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple',
'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch',
'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone',
'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear',
'hair drier', 'toothbrush' ]
38 changes: 38 additions & 0 deletions data/hyp.finetune.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Hyperparameters for VOC finetuning
# python train.py --batch 64 --weights yolov5m.pt --data voc.yaml --img 512 --epochs 50
# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials


# Hyperparameter Evolution Results
# Generations: 306
# P R mAP.5 mAP.5:.95 box obj cls
# Metrics: 0.6 0.936 0.896 0.684 0.0115 0.00805 0.00146

lr0: 0.0032
lrf: 0.12
momentum: 0.843
weight_decay: 0.00036
warmup_epochs: 2.0
warmup_momentum: 0.5
warmup_bias_lr: 0.05
box: 0.0296
cls: 0.243
cls_pw: 0.631
obj: 0.301
obj_pw: 0.911
iou_t: 0.2
anchor_t: 2.91
# anchors: 3.63
fl_gamma: 0.0
hsv_h: 0.0138
hsv_s: 0.664
hsv_v: 0.464
degrees: 0.373
translate: 0.245
scale: 0.898
shear: 0.602
perspective: 0.0
flipud: 0.00856
fliplr: 0.5
mosaic: 1.0
mixup: 0.243
Loading

0 comments on commit 9588838

Please sign in to comment.