Opencv handwritten multiple choice question marking (2) Character Recognition and opencv Character Recognition
Opencv handwritten multiple choice question marking (2) Character Recognition
Generally, you only need to identify ABCD and empty content for multiple-choice questions. In theory, the recognition rate is high. The recognition code references the online search code because there are many reference URLs, it's hard to figure out where the code is to be referenced, so I will not thank you here.
Basic steps:
1. The recognition function accepts 64x64 gray images;
2. binarization and reversed to black and white characters;
3. Find the minimum enclosed rectangle of the character and convert the size to 32X32;
4. Calculate HOG features of images;
5. Identify HOG features using SVM classifier to determine whether the current image is ABCD or blank;
The entire recognition code is relatively simple, thanks to opencv's encapsulation of classifier. In addition to the image preprocessing code, there are only a few lines of actual recognition code;
Some code
CvSVM; int svm_inited = 0; int svm_init (char * data_filename) {svm. load (data_filename); // "HOG_SVM_DATA.xml" svm_inited = 1; return 0;} // int svm_recognition (IplImage * image) {if (svm_inited! = 1) {return-1;} // pre-processing IplImage * test_img = cvCreateImage (cvSize (32, 32), 8, 1); preproc_img (image, test_img ); // black and white characters are processed, and the size is normalized # ifdef _ WIN32 cvShowImage ("Image", test_img); cvWaitKey (0 ); # endif // Feature Extraction HOGDescriptor * hog = new HOGDescriptor (cvSize (32, 32), cvSize (16, 16), cvSize (8, 8), cvSize (8, 8), 9); vector <float> descriptors; // stores the result hog-> compute (test_img, descriptors, Size (1, 1), Size (0, 0 )); // H Og feature compute cvReleaseImage (& test_img); // release unwanted images, release memory // generate the feature data matrix CvMat * mat_samples = cvCreateMat (1, descriptors. size (), CV_32FC1); int n = 0; for (vector <float >:: iterator iter = descriptors. begin (); iter! = Descriptors. end (); iter ++) {cvmSet (mat_samples, 0, n, * iter); n ++;} // identifies int ret = svm. predict (mat_samples); // cvReleaseMat (& mat_samples); return ret ;}