俄罗斯车牌识别案例:实时识别车牌,并且读取到指定文件夹中。
惯例先展示结果图:
对于摄像头读取图片进行车牌匹配,原理和人脸识别其实是一致的。
利用训练好的模型进行匹配即可。可参考:
对视频实现人脸识别-CSDN博客
具体代码:
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/objdetect.hpp>
#include <iostream>
Project3 - License Plate Detector ///
using namespace std;
using namespace cv;
void main() {
VideoCapture cap(0);
Mat img;
CascadeClassifier plateCascade;
plateCascade.load("Learn-OpenCV-cpp-in-4-Hours-main\\Resources\\haarcascade_russian_plate_number.xml");
if (plateCascade.empty())
{
cout << "XML file not loadeed" << endl;
}
vector<Rect>plates;
while (true) {
cap.read(img);
plateCascade.detectMultiScale(img, plates, 1.1, 10);
for (int i = 0; i < plates.size(); i++)
{
Mat imgcrop = img(plates[i]);
imwrite("Learn-OpenCV-cpp-in-4-Hours-main\\Resources\\plates\\"+ to_string(i) + ".png", imgcrop);
rectangle(img, plates[i].tl(), plates[i].br(), Scalar(255, 0, 255), 3);
}
namedWindow("Image", WINDOW_NORMAL);
imshow("Image", img);
waitKey(1);
}
}