3

I need to find largest rectangle in a image, but when I find contours shadow becomes part of the contour.

Any suggestions how to remove/minimize shadow.

Original image

enter image description here

Image with contours

enter image description here

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
d32
  • 53
  • 1
  • 6
  • Do you have a background model? If so, there's an old but effective Pattern Analysis and Machine Intelligence [paper](http://www.techfak.uni-bielefeld.de/~iluetkeb/2006/surveillance/paper/activity/pami_sakbot.pdf) that show in Equation 8 a simple equation to threshold HSV values to remove shadows. Take a look, if you're interested I'll post the code as an answer. – Miki Jul 22 '15 at 11:33
  • background is not fixed it will be different for different images – d32 Jul 22 '15 at 11:36
  • Then that's not the way to go. Another [approach](http://nichol.as/papers/Gevers/Color-based%20object%20recognition.pdf) is to define a color space invariant to illumination changes. You can then work on this model where the shadows "magically" disappear. Have a look at Figure 1 in the paper. Another simpler (maybe simplistic) solution is to work better with your preprocessing. I suppose you need to extract only the barcode. That shouldn't be that difficult. If you post your code we'll give it a try. – Miki Jul 22 '15 at 11:43
  • I have to find image of interest (image region inside border) from the scene image (captured using camera) before extracting/analyzing any information – d32 Jul 22 '15 at 11:51
  • and the border is delimited by the two horizontal lines? – Miki Jul 22 '15 at 11:54
  • @Miki yes border will be delimited by two horizontal lines. But going forward form layout can be configured by the user – d32 Jul 23 '15 at 04:12
  • @nils share option for these images is "Shared to public on the web: no sign in required", they should be accessible. – d32 Jul 23 '15 at 04:14
  • Use **AdaptiveThreshold** rather than normal **Otsu Thresholding**, I was able to resolve same issue with OpenCV Java for Android – Ujju Apr 13 '16 at 12:22

1 Answers1

1

You can use an edge dectector like Canny:

cv::Mat image = cv::imread( "C:/Users/John/Documents/StackOverflow/t8keM.png" );
cv::Mat gray_image, dst, color_dst;

cvtColor( image, gray_image, CV_BGR2GRAY );
Canny( gray_image, dst, 50, 200, 3 );
cvtColor( dst, color_dst, CV_GRAY2BGR );

cv::imshow( "image", image );
cv::imshow( "canny", color_dst );

cv::waitKey();

With result: enter image description here

After that you can have a go with cv::findContours() to find the rectangles.

RevJohn
  • 1,054
  • 9
  • 15