이번에는 OpenCV를 이용한 자동차 번호판 숫자를 인식하는 프로젝트입니다.
1. 이미지 입력
2. 이미지 Grayscale 변환
3. 임계값 설정 이진화
4. 숫자 관심 영역 추출
5. 히스토그램 픽셀수 비교
6. 인식
단계로 나눴습니다.
목표
OpenCV를 활용하여 자동차 번호판의 숫자를 인식해보자.
#define _CRT_SECURE_NO_WARNINGS
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat original_image; //image read(grayscale)
Mat binary_image; //binary image
original_image = imread("2.jpg", IMREAD_GRAYSCALE); //grayscale
threshold(original_image, binary_image, 127, 255, THRESH_BINARY); //threshold
imshow("grayscale", original_image);
imshow("binary", binary_image);
waitKey(0);
}
threshold( src, dst, threshold_value, Max_value, threshold_type) | - src : 입력할 이미지 변수 (grayscale 이미지) - dst : 필터가 적용되어 저장될 이미지 변수 - threshold_value : 임계 값 (0~255), 이진화 시킬 기준 값을 입력 - Max_value : 임계 값 이상의 픽셀들에 적용할 값 (0 또는 255) |
보다 정확한 숫자 표현을 위해 그레이스케일 변환과
0과 255 두개의 픽셀로 표현하기 위해서 threshold (임계값)으로 이진화를 진행시켜준다.
'C++ 공부 > OpenCV' 카테고리의 다른 글
Visual Studio 2022 OpenCV 설치하기 [C++ OpenCV] (0) | 2022.11.01 |
---|
댓글