Reputation: 1703
My imagem has a "light reflection", the two first zeros on the image has some light different of the rest of the image. Whe I convert this to a binary image, this part becomes white, and I need to get the exact contour of the number and this hinders. ow I could solve this by using OpenCV?
the original image https://docs.google.com/file/d/0BzUNc6BOkYrNNlE3U04wWEVvVE0/edit?usp=sharing
the binary version https://docs.google.com/file/d/0BzUNc6BOkYrNeEE0U3NvOElqa1E/edit?usp=sharing
If I increase the value of the threshold, I lose the numbers on the right side of the image. My code:
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main ( int argc, char **argv )
{
Mat im_gray = imread("img2.jpg",CV_LOAD_IMAGE_GRAYSCALE);
Mat im_rgb = imread("img2.jpg");
cvtColor(im_rgb,im_gray,CV_RGB2GRAY);
Mat img_bw = im_gray > 90;
imwrite("image_bw2.jpg", img_bw);
return 0;
}
Upvotes: 6
Views: 9345
Reputation: 2896
Actually problem is not so difficult in your case. Because you have just 10 different numbers, trains some classifier to recognize them.
For fast start you can use http://blog.damiles.com/2008/11/basic-ocr-in-opencv.html
It will work because defects also repeat to some extent. You can train algorithm to recognize images with defects and forget about removing these.
Upvotes: 1
Reputation: 3047
Shadows and glares are not easy problems to work with. But with some good work, they are possible to overcome.
Another step is to use your thresholded image as a mask to get another thresholded image. Here are some criteria that have worked for me:
Upvotes: 2