Opencv handwritten multiple choice question marking (2) Character Recognition and opencv Character Recognition

Source: Internet
Author: User
Tags svm

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 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.