0

I need to extract an object from an image where the background is almost flat...

Consider for example a book over a big white desktop.. I need to get the coordinates of the 4 corners of the book to extract a ROI.

Which technique using OpenCV would you suggest? I was thinking to use k Means but I can't know the color of the background a priori (also the colors inside the object can be vary)

Herr von Wurst
  • 2,571
  • 5
  • 32
  • 53
  • 2
    Why don't you try a simple thresholding to begin with? For k-means also, I don't think you need the specific color, just the number of classes, which in your case is 2 I guess. – Sassa Sep 21 '12 at 18:06
  • @bob: yea taht could work, but what about if the object as inside some pixel with same color of background ? –  Sep 21 '12 at 18:07
  • I guess you could create a mask from the initial segmentation and then do some kind of morphological operation, like closing to include those pixels in the area too. And then apply the mask to the image. This probably can be solved with various ways, this is just something you could try very fast. – Sassa Sep 21 '12 at 18:15
  • I just need to get 4 corners... so i can extract the roi from the original image without any holes –  Sep 21 '12 at 18:18
  • Maybe [this](http://www.mathworks.com/help/images/examples/detecting-a-cell-using-image-segmentation.html), [this](http://www.mathworks.com/help/images/examples/color-based-segmentation-using-k-means-clustering.html), and [this](http://www.mathworks.com/products/image/examples.html?file=/products/demos/shipping/images/ipexrice.html#6) can help you a little bit. I don't know if you use MATLAB, either way they are very useful examples and you can implement them pretty fast in OpenCV too. – Sassa Sep 21 '12 at 18:35
  • Hmm the first link can be good –  Sep 21 '12 at 18:38

1 Answers1

0

If your background is really low contrast, why not try a flood fill from the image borders, then you can obtain bounding box or bounding rect afterwards.

Another option is to apply Hough transform and take intersection of most outer lines as corners. This is, if your object is rectangular.

ypnos
  • 50,202
  • 14
  • 95
  • 141