0

I've an image like this one ![enter image description here][1]. The non-black part is expanded at each iteration. So, after a certain point, I need to enlarge the final image so the non-black one can fit in. For now, what I'm doing is to find the contour of the non-black image,find the bounding box of the contours and check the width/height of the box. At a first time it works, but after some iterations my program finds a bounding box of size 1 (it seems that it doesn't find any contour). What the problem could be?

Ps: the program is a mosaic from a video file, I followed the opencv tutorial for find homography and other stuff.

EDIT Sorry but I had to remove images

bjorn
  • 338
  • 6
  • 18
  • Did you apply [threshold](http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html?highlight=threshold#threshold) for the non-black pixels before finding contours? – Kornel Apr 08 '15 at 11:20
  • Yes, first I was using Canny, then I switch to threshold! – bjorn Apr 08 '15 at 11:47
  • Sorry for the double post, but do you think there's a faster way for finding contour/bounding box? – bjorn Apr 09 '15 at 07:52

1 Answers1

1

Just a suggestion:

It's easier to simply iterate through each element in the matrix and record the coordinates of the uppermost, bottommost, leftmost and rightmost non-zero elements. These will be the four corners of your up-right bounding rectangle. Of course it is not necessarily the rectangle of the minimum area enclosing the non-zero pixels (not a rotated rectangle), but further can be used as a ROI.

Kornel
  • 5,264
  • 2
  • 21
  • 28
  • I've found this for extract the extreme points http://docs.opencv.org/master/d1/d32/tutorial_py_contour_properties.html, but it's for python. There's a similar way to do it in c++? I'm sorry but I'm very new to opencv! – bjorn Apr 09 '15 at 08:56
  • this is also based on `cv::findContours()`, but every function have C++ version too, i.e. [Tutorial - Bounding rects / circles](http://docs.opencv.org/master/da/d0c/tutorial_bounding_rects_circles.html) – Kornel Apr 09 '15 at 08:59