License Plate Recognition In Rust
A Chinese license plate regognition implemention in rust. This repo use:
- image and impageproc for image processing
- tensorflow-rust for machine learning
- some pre-trained model and fonts from HyperLPR
- all the images for training and test comes from CCPD
Rust and Cargo
is needed. If you don't have it yet, check this out first!!
There is two way to use this repo: cli and lib
Use it as a cli tool, just run the following command.
cargo run ./test_images/1.jpg
Then you could see something like this:
Here is a simple example for using this as a library.
use imageproc::window;
use std::error::Error;
use lpr_rust::Lpr;
fn main() -> Result<(), Box<dyn Error>>{
let img = image::open(file_name)?;
let lpr = Lpr::new("./models/detect.pb", "./models/ocr_plate_all_gru.pb", "./models/fine_mapping.pb")?;
let res_img = lpr.recognize_and_draw(&img)?;
window::display_image("res", &res_img.to_rgba(), 700, 700);
Ok(())
}
- detect - a simple detect example of Chinese license plate detect
- oblique_fix - an example of fix oblique image
- recognize - just recognize the image and show it in shell
- recognize_dir - this is sort of benchmark thing
example for checking out examples
cargo run --example detect test_images/2.jpg
There should be three steps to making a license recognition tool:
- detection
- image processing
- recognition
There is two main macheine learning model respectively used for detection and recognition
This repo use object detection for model training. And I use ssd_mobilenet_v3_small_coco for Transfer Learning
The model I used has been trained with 1167 pics, which is very little.
You dive into this for training more image
The main problem that I encoutered is how to fix oblique plate in image detected
Here is an image you may want to see how do I do this:
If you found a better way, please let me know.
I use a keras model(ocr_plate_all_gru) from HyperLPR for recognition
But in Rust you don't have way to load keras model, so the thing i do is convert keras model to tensorflow model, then load this model to recognize.
Here is a blog found on internet, maybe you can take a look.
Code part is under either MIT License or Apache 2.0 License at your option.
Models, images and font is under the License of original repo.
In some cases, the program will freeze, this happens when creating a Projection, I think this is a bug of imageproc, then I filed an issue #412