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:
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.
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)
Extract the contours of the white areas in the mask (cv::findContours). Hopefully you will get one contour per each sub-image.
Calculate the bounding box of each detected contour (cv::boundingRect).
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!
Am I right that images are placed not regularly, i.e. not in the same grid every time? Otherwise you can simply search for the white vertical and horizontal lines (i.e. cv::countNonZero after thresholding), and use them for splitting. In other words I'm saying that you should provide more information about your task, an image will be enough.