Split a cv::mat into submats based on each containing a contour
Hey Guys,
I'm trying to process an image, so that I can do some data analysis with it afterwards. As input I have an image with one or multiple bright spots. I use some filters to reduce noise and then use threshhold to get a binary image. Now I search for all Contours in this image and get the bounding Rectangles. So far no problem. It could look similar to this (but probably with more bright spots):
But now I have to split up the image, so that I can analyse the data with better accuracy. Therefore I want to split the whole cv::mat into several rectangular submatrizes, with each containing exactly one contour.
Do anyone have a idea how to do that? To be precise, I only need the start column/row and the end column/row of each submatrix.
For Example: With the given image it should split the image along the red line:
Thank you in advance! :)
So simple. Used Region Of Interest(ROI)
@supra56 Thank you for your comment. I've found some information about ROI. But I still have a problem with it. It's easy to use ROI for exactly that image above. But I will get tons of those images and have to find the values for the ROI automatically. I think this is maybe more my problem...
@samkro
you are already drawing the bounding boxes
@berak Yes exactly. I first thought about just using a bigger region around the bounding boxes, but this could become a problem, if the contours are too close together. I know I have a vector with all the bounding boxes, so I have the information about position, width, height etc. So there should be a way to figure out where the ROI has to be, but I don't see the right approach at the moment.