-
Notifications
You must be signed in to change notification settings - Fork 63
/
plateLabel.py
58 lines (57 loc) · 2.02 KB
/
plateLabel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import cv2
import imageio
import numpy as np
import os
import shutil
import argparse
from alphabets import plate_chr
def allFileList(rootfile,allFile):
folder =os.listdir(rootfile)
for temp in folder:
fileName = os.path.join(rootfile,temp)
if os.path.isfile(fileName):
allFile.append(fileName)
else:
allFileList(fileName,allFile)
def is_str_right(plate_name):
for str_ in plate_name:
if str_ not in palteStr:
return False
return True
if __name__=="__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--image_path', type=str, default="/mnt/EPan/carPlate/@realTest2_noTraining/realrealTest", help='source')
parser.add_argument('--label_file', type=str, default='datasets/val.txt', help='model.pt path(s)')
opt = parser.parse_args()
rootPath = opt.image_path
labelFile = opt.label_file
# palteStr=r"#京沪津渝冀晋蒙辽吉黑苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云藏陕甘青宁新学警港澳挂使领民深危险品0123456789ABCDEFGHJKLMNPQRSTUVWXYZ"
# palteStr=r"#京沪津渝冀晋蒙辽吉黑苏浙皖闽赣鲁豫鄂湘粤桂琼川贵云藏陕甘青宁新学警港澳挂使领民航深0123456789ABCDEFGHJKLMNPQRSTUVWXYZ"
palteStr=plate_chr
print(len(palteStr))
plateDict ={}
for i in range(len(list(palteStr))):
plateDict[palteStr[i]]=i
fp = open(labelFile,"w",encoding="utf-8")
file =[]
allFileList(rootPath,file)
picNum = 0
for jpgFile in file:
print(jpgFile)
jpgName = os.path.basename(jpgFile)
name =jpgName.split("_")[0]
if " " in name:
continue
labelStr=" "
if not is_str_right(name):
continue
strList = list(name)
for i in range(len(strList)):
labelStr+=str(plateDict[strList[i]])+" "
# while i<7:
# labelStr+=str(0)+" "
# i+=1
picNum+=1
# print(jpgFile+labelStr)
fp.write(jpgFile+labelStr+"\n")
fp.close()