1 | initial version |
First of all apply the findContours function onto the foreground image. This will look for contours in your binary image, around the blobs that you have segmented before with the background segmentation algorithm.
Each of these contours is found as a vector of points, which give you the exact location of the blob, in image coordinates. If this information is enough, then you can stop here.
Next step is to find the smallest bounding box for the blob, which will accurately describe the location of the blob, in fewer coordinates than the list of vector points. This can be done by applying the boundingRect function on each of the contours. This will return a rectangle object, which contains a x and y coordinate of the top left corner and a width and heigth parameter.
You could also calculate the mass center, using the moments of the contour as explained in this tutorial.