算法采用纵向及横向扫描方式,对清晰图片进行了实验,效果较好。
算法未检测小数点,感兴趣的同学可以Y方向腐蚀检测小数点,按照X坐标排序即可。
当然,数字及字符识别,SVM、K近邻、神经网络等等这些才是正道,平常用得比较多的算法。
源图如下:
代码如下:
//DATE : 20160729
//CODE FOR LIDAN NUMBER RECG
#include "highgui.h"
#include "cv.h"
using namespace std;
using namespace cv;
void detect(IplImage * img, char * strnum, CvRect rc);
int list[10][2] = {0}; //1列坐标,2列字符数值
int l = 0; //字符个数
int main()
{
IplImage * src_img = cvLoadImage("plate1.jpg");
if(!src_img)
{
printf("src_img could not be load\n");
return -1;
}
//cvShowImage("src", src_img); //src img
IplImage * gray_img = cvCreateImage(cvGetSize(src_img), src_img->depth, 1);
cvCvtColor(src_img, gray_img, CV_BGR2GRAY);
cvShowImage("gray", gray_img); //gray img
IplImage * adp_img = cvCreateImage(cvGetSize(src_img), src_img->depth, 1);
int threshold_type = CV_THRESH_BINARY_INV;
int adaptive_method = CV_ADAPTIVE_THRESH_GAUSSIAN_C; //CV_ADAPTIVE_THRESH_MEAN_C
int block_size = 7;
double offset = 5;
//cvAdaptiveThreshold(gray_img, adp_img, 255, adaptive_method, threshold_type, block_size, offset);
cvThreshold(gray_img, adp_img, 80, 255.0, CV_THRESH_BINARY);
cvShowImage("adp", adp_img);
IplImage * xtx_img = cvCreateImage(cvGetSize(adp_img), adp_img->depth, adp