OpenCV Handwriting Selection quiz (b) Character recognition
The choice question basically only need to recognize ABCD and empty five content, theoretically should recognize the rate is higher, the identification code refers to the online search code, because the reference URL is more, now also can not clear is the reference where the code, here does not thank each.
Basic steps:
First, the recognition function accepts the gray image of General 64x64;
Second, binary and inverse color for white on black background;
Three, find the minimum bounding rectangle of the character, and the size is normalized to 32x32;
Four, calculate the hog characteristic of the image;
Five, the Hog feature is identified by SVM classifier to determine whether the current image belongs to ABCD or blank;
The entire identification code is still relatively simple. This is due to the opencv of the classifier, in addition to the image preprocessing code, the actual identification code only a few lines;
Part of the Code
CVSVM SVM;intsvm_inited =0;intSvm_init (Char*data_filename) {svm.load (data_filename);//"Hog_svm_data.xml"svm_inited =1; return 0;}//intSvm_recognition (iplimage*image) { if(svm_inited! =1){ return-1; } //pretreatmentiplimage* test_img = Cvcreateimage (Cvsize ( +, +),8,1); Preproc_img (image, test_img);//processing for white on black background, and size normalization#ifdef _win32 cvshowimage ("Image", test_img); Cvwaitkey (0);#endif //Feature ExtractionHogdescriptor *hog =NewHogdescriptor (Cvsize ( +, +), Cvsize ( -, -), Cvsize (8,8), Cvsize (8,8),9); Vector<float> descriptors;//Store ResultsHog->compute (test_img, descriptors, Size (1,1), Size (0,0));//Hog Feature CalculationCvreleaseimage (&TEST_IMG);//free up memory by releasing unwanted images//generate the feature data matrix to be detectedCvmat * Mat_samples = Cvcreatemat (1, Descriptors.size (), CV_32FC1); intn =0; for(vector<float>::iterator iter = Descriptors.begin (); Iter! = Descriptors.end (); iter++) {Cvmset (Mat_samples,0, N, *ITER); N++; } //Identify intret = svm.predict (mat_samples);//Test ResultsCvreleasemat (&mat_samples); returnret;}
OpenCV Handwriting Selection quiz (b) Character recognition