c++ - k-nn algorithm does not detect digits correctly/perfectly -


i have learned coding, image processing, opencv, c++ , visual studio 1 month, , in trouble solving problem. need , shed light.

i have tried code website detect digits opencv library, 7 digits detected, 3 digits corrects. parameters should changed? in addition, detection start right bottom left up, shouldn't detected upper left right? should change?

if use code , ressources, should alright if test code on image different numbers , typo, give try image used in sample (python).

you need replace train data these one:

// loading digit models hogdescriptor h(size(20, 20), size(10, 10), size(5, 5), size(5, 5), 9); std::vector<float> hdata; mat data(size(324, 5000), cv_32fc1); mat responses(size(1, 5000), cv_32fc1); (int = 0; < 50; i++) {     (int j = 0; j < 100; j++) {         h.compute(digits(rect(j * 20, * 20, 20, 20)), hdata);         (unsigned int k = 0; k < hdata.size(); k++) {             data.at<float>(i * 100 + j, k) = hdata[k];         }         responses.at<float>(i * 100 + j, 0) = (float)floor(i / 5.0);     } } knearest knearest(data, responses); 

in case, use hog features represent way better digits. here, digit image quoted above. , match:

mat sample(size(324, 1), cv_32fc1); h.compute(digit, hdata); (unsigned int k = 0; k < hdata.size(); k++) {     sample.at<float>(0, k) = hdata[k]; } mat results, neighborresponses, dists; cout << "recognised: " << knearest.find_nearest(sample, 7, results, neighborresponses, dists) << endl; 

if need detect black letters on white background, need revert samples:

digit = 255 - digit; 

i have never tried, used these opencv functions text detection , recognition. simpler better results.

good luck.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -