-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage2characters.py~
executable file
·71 lines (59 loc) · 2.38 KB
/
image2characters.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
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
From an image get a list of possible characters of a licence plate,
There may be more than one plate in the image,
we hopefully get all licence plates.
Typically one also gets extra false positive plates
getting string of characters of a licence plate
cd /home/mka/PycharmProjects/Image2Letters/test
Usage:
python3 image2characters.py "plate.yuv"
"""
import sys
from rekkariDetectionSave import DetectPlate
# from filterImage import FilterImage
from filterCharacterRegions import FilterCharacterRegions
from initialCharacterRegions import InitialCharacterRegions
# from myTesseract import MyTesseract
from myClassifier import Classifier
import glob
import cv2
class image2Characters():
""" from an input file or yuv numpy array get array of strings representing
characters in (a) number plate(s) """
def __init__(self, npImage=None):
self.img = npImage # image as numpy array
def setImageFromFile(self, imageFileName, colorConversion=cv2.COLOR_BGR2GRAY):
""" for debuggin image can be read from file also"""
self.img = cv2.imread(imageFileName)
self.img = cv2.cvtColor(self.img, colorConversion)
def getChars(self):
"""
From Image to list of strings, representing characters of (a) number plate(s)
"""
myChars = []
app1 = DetectPlate(npImage=self.img)
plates = app1.getNpPlates()
#app1.showPlates()
#app1.writePlates(name='plateOnly-'+sys.argv[1])
#print(file+' number of plates found '+ str(len(plates)))
for plate in plates:
# from a plate image to list of six-rectangles
#app2 = FilterImage(npImage=plate)
#plate = app2.filterOtsu()
app3 = FilterCharacterRegions(npImage=plate)
platesWithCharacterRegions = app3.imageToPlatesWithCharacterRegions()
app5 = Classifier(npImage=plate)
#app3.showImage()
app5.defineSixPlateCharacters(platesWithCharacterRegions)
myChars = myChars + app5.getFinalStrings()
return myChars
if __name__ == '__main__':
import sys, glob
files=glob.glob(sys.argv[1])
print(files)
if len(files)==0:
raise FileNotFoundError('no files with search term: '+sys.argv[1])
app = image2Characters()
for file in files:
app.setImageFromFile(imageFileName=file)
print("Image, plate(s): ",file, app.getChars())