forked from murtazahassan/Learn-OpenCV-cpp-in-4-Hours
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Project3.cpp
40 lines (29 loc) · 947 Bytes
/
Project3.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/objdetect.hpp>
#include <iostream>
using namespace cv;
using namespace std;
/////////////// Project 3 - License Plate Detector //////////////////////
void main() {
Mat img;
VideoCapture cap(0);
CascadeClassifier plateCascade;
plateCascade.load("Resources/haarcascade_russian_plate_number.xml");
if (plateCascade.empty()) { cout << "XML file not loaded" << 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]);
//imshow(to_string(i), imgCrop);
imwrite("Resources/Plates/" + to_string(i) + ".png", imgCrop);
rectangle(img, plates[i].tl(), plates[i].br(), Scalar(255, 0, 255), 3);
}
imshow("Image", img);
waitKey(1);
}
}