Before explaining the ANPR code, we need to define the main steps and tasks in the ANPR algorithm. ANPR is divided into two main steps, plate detection and plate recognition:
- Plate detection has the purpose of detecting the location of the plate in the whole camera frame.
- When a plate is detected in an image, the plate segment is passed to the second step (plate recognition), which uses an OCR algorithm to determine the alphanumeric characters on the plate.
In the following diagram, we can see the two main algorithm steps, plate detection and plate recognition. After these steps, the program paints in the camera image the plate's characters that have been detected. The algorithms can return bad results, or may not return any result:
In each step shown in the previous diagram, we will define three additional steps that are commonly used in pattern recognition algorithms. These steps are as follows:
- Segmentation: This step detects and removes each patch/region of interest in the image.
- Feature extraction: This step extracts from each patch a set of characteristics.
- Classification: This step extracts each character from the plate recognition step, or classifies each image patch into a plate or no plate in the plate detection step.
In the following diagram, we can see these pattern recognition steps in the application as a whole:
Aside from the main application, whose purpose is to detect and recognize a car plate number, we will briefly explain two more tasks that are usually not explained:
- How to train a pattern recognition system
- How to evaluate it
These tasks, however, can be more important than the main application, because if we do not train the pattern recognition system correctly, our system can fail and not work correctly; different patterns need different training and evaluation processes. We need to evaluate our system with different environments, conditions, and features to get the best results. These two tasks are sometimes done together, since different features can produce different results, which we can see in the evaluation section.