Home > Back-end >  Opencv license plate number digit recognition the last step! Great god help ~
Opencv license plate number digit recognition the last step! Great god help ~

Time:09-26

Last week to do the images digital identification, online to find the character segmentation code (can be used, it is the old code), write a separate Numbers (0 ~ 9) identification code (code), the new and old code can be changed, but the two code is not clear how can together? (the following is my own and in code, compiled no problem, there is something wrong with the algorithm,) of the current problem is the license plate number, even after the split, but how integral a few characters respectively in the code into a single digital identity, identified, and the final output images digital and thanks for your help ~ ~ and can before, on Friday, and give some hints or help me to change and down below is the code:
#include
#include
#include
#include
#include
#include
#include
#include
#include
# include "opencv2/imgproc/imgproc HPP"
# include "opencv2/highgui/highgui. HPP"
using namespace std;
Using the namespace CV;
Void findX (min IplImage * img, int * and an int * Max)
{
Int found=0;
CvScalar very=cvRealScalar (img - & gt; Width * 255);
CvScalar val=cvRealScalar (0);
CvMat data;
Int minCount=img - & gt; Width * 255/5;
int count=0;

For (int I=0; i CvGetCol (img, & amp; The data, I);
Val=cvSum (& amp; The data);
If (val val [0] Count=val. Val [0];
If (count & gt; MinCount & amp; & The count & lt; Img - & gt; Width * 255) {
* Max=I;
If (found==0) {
* min=I;
Found=1;
}
}
}
}

}

//find contain the top of the license plate characters, ruled out the location of the two screws
Void findY (min IplImage * img, int * and an int * Max)
{
Int found=0;
CvScalar very=cvRealScalar (img - & gt; Height * 255);
CvScalar val=cvRealScalar (0);
CvMat data;
Int minCount=img - & gt; Width * 255/5;
int count=0;

For (int I=0; i CvGetRow (img, & amp; The data, I);
Val=cvSum (& amp; The data);
If (val val [0] Count=val. Val [0];
If (count & gt; MinCount & amp; & The count & lt; Img - & gt; Height * 255) {
* Max=I;
If (found==0) {
* min=I;
Found=1;
}
}
}
}
}

The minimum area//license plate character
CvRect findArea (IplImage * img)
{
Int minX, maxX;
Int minY, maxY;

FindX (img, & amp; MinX, & amp; MaxX);
FindY (img, & amp; MinY, & amp; MaxY);

CvRect rc=CvRect (minX, minY, maxX - minX, maxY - minY);

Return the rc;
}

Mat img_divide Mat (SRC)
{
Mat dst_gray, dst_gra dst_gr;
Int I=5;//matrix size

Mat DST (cvRound (SRC) rows/1), cvRound (SRC. The cols/1), CV_8UC1);
CvtColor (SRC, dst_gray, CV_BGR2GRAY);
The resize (dst_gray, DST, DST. The size (), 0, 0, INTER_LINEAR);
MedianBlur (DST, dst_gra, I);
Threshold (dst_gra dst_gr, 0, 255, CV_THRESH_BINARY | CV_THRESH_OTSU);

//to find the minimum area and intercept
IplImage * pI=& amp; Dst_gr. Operator IplImage ();
CvRect rc=findArea (pI);
CvSetImageROI (pI, rc);
IplImage * img_gray2=cvCreateImage (cvSize (rc) width, rc, height), IPL_DEPTH_8U, 1);
CvCopyImage (pI, img_gray2);
CvResetImageROI (pI);

IplImage * imgSrc2=cvCreateImage (cvSize (rc) width, rc, height), IPL_DEPTH_8U, 3);
IplImage * P_src=https://bbs.csdn.net/topics/&src.operator IplImage ();
CvSetImageROI (P_src, rc);
CvCopyImage (P_src imgSrc2);
CvResetImageROI (P_src);

//morphology
CvMorphologyEx (img_gray2 img_gray2, NULL, NULL, CV_MOP_CLOSE);

CvSeq * contours=NULL;
CvMemStorage * storage=cvCreateMemStorage (0);
Int count=cvFindContours (img_gray2, storage, & amp; Contours,
Sizeof (CvContour), CV_RETR_EXTERNAL);

int idx=0;
Char szName [56]={0};

For (CvSeq * c=contours; C!!!=NULL; C=c - & gt; H_next)
{

//cvDrawContours (imgSrc2, c, CV_RGB (255, 0, 0), CV_RGB (255, 255, 0), 100);
CvRect rc=cvBoundingRect (c);
CvDrawRect (imgSrc2 cvPoint (rc, rc. X, y), cvPoint (rc) x + rc) width, rc, y + rc. The height), CV_RGB (255, 0, 0));

If (rc) width & lt; ImgSrc2 - & gt; Width/10 & amp; & Rc. Height & lt; ImgSrc2 - & gt; Height/5) {continue; }
}

IplImage * imgNo=cvCreateImage (cvSize (rc) width, rc, height), IPL_DEPTH_8U, 3);
CvSetImageROI (imgSrc2, rc);
CvCopyImage (imgSrc2 imgNo);
CvShowImage (" SRC ", imgNo);
Mat PIC (imgNo);

CvWaitKey (0);
CvDestroyAllWindows ();

Return PIC;
}

Int img_gramme (Mat img, int * result)
{
Vector Contours.
VectorFloat b [3], [3] s, num [3].
int i;

/* int result [5]; CV_THRESH_TOZERO | */
CvPoint rect_pts [4], * pt=rect_pts;
Mat src_image;

Threshold (img, src_image, 0, 255, CV_THRESH_BINARY);
Img=src_image. Clone ();
FindContours (src_image, contours, hierarchy, CV_RETR_TREE CV_CHAIN_APPROX_SIMPLE, Point (0, 0));//Find contours

Vector Contours_poly (contours. The size ());
Vector BoundRect (contours. The size ());

For (I=0; i{
S [I]=contourArea (contours [I]);

ApproxPolyDP (Mat (contours [I]), contours_poly [I], 3, true);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related