This university project is an introduction to working with python and image editing. Especially to work with libraries, classes and openCV. The documentation should be beginner-friendly and will also contain workflows, and a guide how to set up the project.
The licenseplatelib.py contains the class IdentifyLicensePlate which takes a path to an image. If it detects a licenseplate, and the text is matching the given format, the getLicenseplatestring method will return the licenseplate text as a String.
Before you start working with this code you'll need to install some libraries. You can either use the features of your IDE (if you use one) or else here is a how to install python libaries.
| libary | documentation |
|---|---|
| cv2 | cv2 documentation |
| Pillow | Pillow documentation |
| Tesseract-OCR | Tesseract documentation |
| NumPy | Numpy documentation |
| Imutils | Imutils documentation |
The IdentifyLicensePlate has following attributes and methods:

rawImage and name are set after initiating an Object. The rawImage holds the image from the path loaded with cv2.imread. The name is generated by the path but the /pictures/ and the suffix are cut. The attributes feature and district are being set after getLicenseplate has been run successfully.
getlicenseplateString() is the method which starts the identifying process. All other methods are beeing used soley internally. For further explanation look at the Flowcharts below.
Following the process of getting the licenseplate as a string from the original image is explained with flowcharts. For best understanding of the code, try to follow the flowchart inside the code.
The main method from the IdentifyLicensePlate is getLicenseplateString. The method is called in the main script to get the feature. It starts the image processing as well as the text recognition.

To understand the image processing more in depth we are looking at the findAndCropLicensePlate. This method searches in the original image for a licenseplate and cuts the suspected part of the image out. It returns a list with all cutted images. Note: The method will cut wrong images also. The text detection will filter them out. As long as the licenseplate is in the imagelist it is working.

The returned imagelist is thrown into the text detection (explained later). If the text detection is not able to identify a licenseplate the originalImgEdgeDetection is used instead. This method takes the original image put some filter for edge detection on it. The image is then thrown into the text detection and we hope for the best.

The validateFormate-method works with the python inbuild regrex libary. It mainly filters non letters and numbers out of the string, and then compares the resulting string with a pattern for german licenseplates. The following flowchart doesn't use the real code lines. Instead, the comments are being used, as they are more understable.

The main.py script contains an example, how to use the class.
The class is beeing imported as ILP. That means we can use ILP instead of licenseplatelib.IdentifyLicenseplate in the following code:
from licenseplatelib import IdentifyLicensePlate as ILP
We initiate an Object with: The showDebug option is going to print information about the image editing process to understand it, or look why the class is not able to identify a licenseplate. The showImages option will show multiple images of different steps from the image editing process.
exampleCar = ILP("examplePictures/examplecar.jpg", showImages=True, showDebug=True)
the method call .getLicenseplateString is going to start the identifying process. It returns the feature as string and will be printed into the terminal.
print("The Feature from: " + exampleCar.name + ' is ' + exampleCar.getLicenseplateString())
The if statement checks if the district is set, then the district is printed:
if len(exampleCar.district) > 0:
print("The Car comes from: " + exampleCar.district)
glob.glob is creating a list with all images in the directory pictures. The for loop iterates through that list and initiates an object for every image and saves them to the cars list.
cars = []
for path in glob.glob("pictures/*.*"):
cars.append(ILP(path, showDebug=True))
For being able to show the pictures the following two lines of code are needed in every script using the IdentifyLicenseplate class with "showImages = True":
cv2.waitKey(0)
cv2.destroyAllWindows()