Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What can I do for eliminate a "reflection light" of a image? using OpenCV

Tags:

image

opencv

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;
}  
like image 934
U23r Avatar asked Jun 10 '13 04:06

U23r


2 Answers

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:

  • Restricting all but the dominant peak in the pixels contained in the histogram of the intermediate (what you have right now) thresholded image
  • Use the derivative to find boundaries (cvSobel may help)
  • Use a combination of strict adaptive and liberal hard thresholding to take into account the varying illumination of different parts of the image
like image 146
Boyko Perfanov Avatar answered Nov 06 '22 03:11

Boyko Perfanov


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.

like image 22
Tõnu Samuel Avatar answered Nov 06 '22 03:11

Tõnu Samuel