😎 공부하는 징징알파카는 처음이지?
[C++ 로 OpenCV 구현하기] (11) Project3 - License Plate Detector 본문
👩💻 IoT (Embedded)/Image Processing
[C++ 로 OpenCV 구현하기] (11) Project3 - License Plate Detector
징징알파카 2023. 6. 14. 15:13728x90
반응형
<본 블로그는 Murtaza's Workshop 의 유튜브를 참고해서 공부하며 작성하였습니다 :-)>
=> LEARN OPENCV C++ in 4 HOURS | Including 3x Projects | Computer Vision
🌀 Project3 - License Plate Detector
💧 russian number Detect 하기
#include <opencv2/opencv.hpp> // OpenCV에서 지원하는 모든 기능
#include <opencv2/videoio.hpp> // 비디오 추적 및 배경 segmentation과 관련된 루틴
#include <opencv2/imgcodecs.hpp> // 기본 데이터 타입이 선언 (Mat 이나 Point가 선언, 행렬 연산 혹은 벡터 연산)
#include <opencv2/highgui.hpp> // 윈도우 화면, UI처리(슬라이더, 버튼 등) 및 마우스 제어 가능
#include <opencv2/objdetect.hpp>
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
// #11. License Plate Detector
void main() {
VideoCapture cap(0);
Mat img;
// 미리 학습되어 있는 정보를 불러와서 내가 찾고자 하는 객체를 검출하는 기능을 제공
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++) {
rectangle(img, plates[i].tl(), plates[i].br(), Scalar(255, 0, 44));
}
imshow("img", img);
waitKey(1);
}
}
💧 Detection 된 부분을 crop 으로 다시 띄우기
#include <opencv2/opencv.hpp> // OpenCV에서 지원하는 모든 기능
#include <opencv2/videoio.hpp> // 비디오 추적 및 배경 segmentation과 관련된 루틴
#include <opencv2/imgcodecs.hpp> // 기본 데이터 타입이 선언 (Mat 이나 Point가 선언, 행렬 연산 혹은 벡터 연산)
#include <opencv2/highgui.hpp> // 윈도우 화면, UI처리(슬라이더, 버튼 등) 및 마우스 제어 가능
#include <opencv2/objdetect.hpp>
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
// #11. License Plate Detector
void main() {
VideoCapture cap(0);
Mat img;
// 미리 학습되어 있는 정보를 불러와서 내가 찾고자 하는 객체를 검출하는 기능을 제공
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);
rectangle(img, plates[i].tl(), plates[i].br(), Scalar(255, 0, 44));
}
imshow("img", img);
waitKey(1);
}
}
💧 crop 된 부분을 png 로 저장하기
#include <opencv2/opencv.hpp> // OpenCV에서 지원하는 모든 기능
#include <opencv2/videoio.hpp> // 비디오 추적 및 배경 segmentation과 관련된 루틴
#include <opencv2/imgcodecs.hpp> // 기본 데이터 타입이 선언 (Mat 이나 Point가 선언, 행렬 연산 혹은 벡터 연산)
#include <opencv2/highgui.hpp> // 윈도우 화면, UI처리(슬라이더, 버튼 등) 및 마우스 제어 가능
#include <opencv2/objdetect.hpp>
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
// #11. License Plate Detector
void main() {
VideoCapture cap(0);
Mat img;
// 미리 학습되어 있는 정보를 불러와서 내가 찾고자 하는 객체를 검출하는 기능을 제공
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);
// crop 된 부분을 png 로 저장하기
imwrite("Resources/Plates/" + to_string(i) + ".png", imgCrop);
rectangle(img, plates[i].tl(), plates[i].br(), Scalar(255, 0, 44));
}
imshow("img", img);
waitKey(1);
}
}
728x90
반응형
'👩💻 IoT (Embedded) > Image Processing' 카테고리의 다른 글
[Python 으로 영상처리 (2)] 이진화 (0) | 2023.12.28 |
---|---|
[Python 으로 영상처리 (1)] cv2.seamlessClone() 영상의 조화로움!! (1) | 2023.12.28 |
[C++ 로 OpenCV 구현하기] (10) Project2 - Document Scanner (1) | 2023.06.14 |
[C++ 로 OpenCV 구현하기] (9) Project1 - Virtual Painter (0) | 2023.06.13 |
[C++ 로 OpenCV 구현하기] (8) Face Detection (0) | 2023.06.13 |
Comments