2

I am using this image as an example: Original - almost - rectangle

What I want, is to identify a bounding rectangle that's close to the original rectangle part, ignoring most of the imperfections outside of it.

What I get right now is this (contour and bounding rectangle created from that contour):

Bounding rectangle

How can I, more or less, ignore that small area when creating my bounding rectangle, so that it's not included in it? In other words: what I need is a bounding rectangle that's as close as possible to the original "rectangle part".

Thums
  • 187
  • 7
  • You could get out of it two histograms: projection on x and y axis. Then pick the highest points up and use them as x/y coordinates to create your rectangle. Would it work for you? – skypjack May 28 '17 at 04:55
  • Straight line detection, find intersection points, done. OpenCV has some functions to do line detection using hough transforms, for example. See http://docs.opencv.org/3.0-beta/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html – Rook May 28 '17 at 06:41
  • Or write your own rectangle-detecting code using a hough transform. It isn't super difficult, after all. – Rook May 28 '17 at 06:42
  • have a look at my question and Miki's answer on how to crop away the concave parts of a contour: https://stackoverflow.com/questions/35226993/how-to-crop-away-convexity-defects try it, it might work for you, too! – Micka May 28 '17 at 07:34
  • 1
    Thank you guys for your answers, I ended up realizing that for my specific use case the bigger bounding rect won't be a problem. For the record, I think @Micka's question would have the solution I needed. – Thums May 28 '17 at 08:37

0 Answers0