automatic number plate recognition engine based on deep learning in c++
Deep learning number plate recognition engine, based on and . Operates on latin characters.
- Build
- Integrating to your c++ code
- Deep learning model file
- More detailed description
- Third party software
- License
This code is standard c++ and relies on and . These two softwares are meant to operate on a vast range of hardwares and os. Based on that, it should be possible to build on various platforms. Among them, I tested successfully Windows 10 and Linux Ubuntu (20.04). Use of CUDA has not (yet) been tested (only CPU).
Download onnxruntime-win-x64-1.4.0.zip and decompress somewhere
In LPReditor_ANPR/CMakeLists.txt, change ../onnxruntime-win-x64-1.4.0/ to point to the actual path of the onnxruntime-win-x64-1.4.0 directory
From cmake-gui, configure and generate LPReditor_ANPR/CMakeLists.txt
Download onnxruntime-linux-x64-1.6.0.tgz and decompress somewhere
In LPReditor_ANPR/CMakeLists.txt, change ../onnxruntime-linux-x64-1.6.0/ to point to the actual path of the onnxruntime-linux-x64-1.6.0 directory
From cmake-gui, configure and generate LPReditor_ANPR/CMakeLists.txt
//step 1 declare a global instance of ONNX Runtime api
const OrtApi* g_ort = OrtGetApiBase()->GetApi(ORT_API_VERSION);
//step2 declare an onnx runtime environment
std::string instanceName{ "image-classification-inference" };
// https://github.com/microsoft/onnxruntime/blob/rel-1.6.0/include/onnxruntime/core/session/onnxruntime_c_api.h#L123
Ort::Env env(OrtLoggingLevel::ORT_LOGGING_LEVEL_WARNING,instanceName.c_str());
//step 3 declare options for the runtime environment
Ort::SessionOptions sessionOptions;
sessionOptions.SetIntraOpNumThreads(1);
sessionOptions.SetGraphOptimizationLevel(GraphOptimizationLevel::ORT_ENABLE_EXTENDED);
//step 4 declare an onnx session (ie model), by giving references to the runtime environment, session options and path to the model
std::wstring widestr = std::wstring(model_filename.begin(), model_filename.end());
Yolov5_anpr_onxx_detector onnx_net(env, widestr.c_str(), sessionOptions);
//step 5 call the detect function of the Yolov5_anpr_onxx_detector object, on a cv::mat frame.
//This will retieves the lpn string
std::string lpn;
onnx_net.detect(frame, lpn);
Mandatory : to operate, the executable must load the model file. Doing that, you have to specify, either in the command line or directly in the source code (see step 4) its file path. You can download the model : due to its size, the lpreditor_anpr.onnx file is in the LPReditor_ANPR.zip release, under (LPReditor_ANPR/data/models/) or in the repo as a zipped file (/data/models/lpreditor_anpr.zip). Another option, is to train your own model, on your dataset, using and then it.
Building will produce an executable, with command line options (see them in the Open_LPReditor.cpp). It can read lpn(s) from a single image file or alternatively, from multiple image files, in a common directory. If the actual license plate number is provided (see func getTrueLPN in the code), in the image filename, then statistics of the correctness of the readings, are available.
Optionaly (in the command line), it can display a window, named with the read lpn :
Another option is to display bounding boxes of caracters and license plate ROI (by activating show_boxes function, directly in the code) :
Copyright © 2021 , OpenCV team Apache 2 License
Copyright © 2020 Microsoft. All rights reserved. MIT License
by Glenn Jocher (Ultralytics.com) GPL-3.0 License
Copyright (c) Facebook, Inc. and Microsoft Corporation. All rights reserved. MIT License
All files, including the deep learning model file provided, are subject to GNU General Public License v3.0.
Commercial-friendly licensing available.