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;
}
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With