CCTV Vehicle and Number Plate Recognition
This was a personal home security project to detect vehicles at my house and apply Automated Number Plate Recognition (ANPR) to detect and read their number plates.
To begin with it would be running 24/7, I used an existing application called Frigate NVR that can use a Google Coral TPU to efficiently detect objects in CCTV camera feeds. I used a pre-trained model on the MS COCO dataset to detect cars and people, however, for this project only the cars is required.
Frigate is a well designed application and works very well with Home Assistant, but for this project I decided to use MQTT instead. When Frigate detects a vehicle on my camera, it records and saves an annotated clip of the vehicle and publishes a message to my locally hosted MQTT server to say that a vehicle has been detected. I have a python script subscribed to this topic, and when a message is received, it downloads the latest clip from Frigate.
As Frigate was using a lightweight real-time model, and this application is for very infrequent traffic, I decided to use a more sophisticated model that I trained used transfer learning on a dataset downloaded from my own Frigate installation after leaving it to run alone for several months. This meant that the model was better suited to my individual camera, and should hopefully make more accurate with more confident detections. Since this is being done on a saved clip, this part is no longer required to be done in real time.Â
After the output of the second model is combined into a video output of only what is inside the bounding box, i.e. only the vehicle itself, number plate detection is performed to identify the location of the number plate in the image using another transfer learning model trained specifically for this purpose from my own collected and labelled dataset. After some image processing, Google's Tesseract is then used to identify the characters in the number plate, and the ANPR portion of the project is now complete.
During my time researching online for this project, I discovered that in the UK, number plates, tax status, MOT status and MOT history is open to the public and not considered personal data as the focus is on the vehicle and not the keeper of the vehicle. In fact, the government, DLVA and DVSA offer APIs that can be used to easily check this information provided the number plate of the vehicle.
As I already had the number plate as a string from tesseract, after I had applied and been approved for developer accounts for the DVLA's Vehicle Enquiry Service (VES) and the DVSA's MOT History API and received my API keys, it was trivial to integrate the API request into my python program. I theorized this could also have a secondary purpose of checking whether the number-plate was read correctly, possibly even by comparing it to the colour of the vehicle, however, I did not get around to implementing this.
If I was to continue this project and develop more features for it, I think I would like to add a system to estimate the speed of the vehicle passing by. This should be possible as it is a static camera pointed at a road of known distance, similarly to how some real static police speed cameras work by using known distances of white lines painted on the road.