Ask Your Question

Revision history [back]

Hi Konstantin!

That sounds like fun!! Well... I am not aware of any OpenCV function that does specifically that, but here is what I would do:

  1. Get a binary mask of the whole image by thresholding on the white color. You should get a mask where appear in black all the pixels with "white color"(the color that corresponds with the borders) and pixels with any other color(that correspond to each of the sub-images) would appear in white.

  2. Improve the quality of the mask (the sub-images will likely also contain white pixels that would generate noise on the mask) by applying a combination of Opening and Closing operations (combinations of cv::erode and cv::dilate)

  3. Extract the contours of the white areas in the mask (cv::findContours). Hopefully you will get one contour per each sub-image.

  4. Calculate the bounding box of each detected contour (cv::boundingRect).

  5. For each bounding box, extract the original content and save it as a separate image.

Take a look at chapters 5 and 7 of the book:

"OpenCV 2 Computer Vision Application Programming Cookbook". Robert Laganiere.

Good luck!