The following pseudocode code works fine in reality, but I have a question concerning the appropriateness with what I am trying to do. I detect a few simple blobs ovoid to circular in nature, in a binary image. I am trying to find the blob centers:
The keypoints returned: do they contain the center coordinates of the blobs detected or should I calculate the centroid of the blob using using an algorithm, a bounding box middle or even by applying a moments function? Where do I go from here to find center coords?
Hi thanks for the recommended solution. Would a “geometric solution” be acceptable as well as simpler? I basically find the leftmost, rightmost, lower-most, higher-most pixel coordinates of the blob in the image plane and calculate the rectangular center from this virtual bounding box. Assuming a relatively symmetrical blob which I am using. How can I find the coordinates marked with “?”
Pseudo:
I’ll have to do some reading about center of gravity versus geometric center and repost --honestly I don’t know the diff. I do know I want to avoid contours and to work with 1-2 round binary blobs that are moving. The algorithm should be light weight and with as few OpenCV fx calls as possible. I am presently using binary keypoints.x etc. as center image points but this is probably not right though close.
I’ve done a lot of reading on the two approaches above. Turns out it appears that the
keypoints already contain centroid coordinates that correlate with image points :
bin_with_keypoints[i].pt.x;
bin_with_keypoints[i].pt.y;
// or equivalent
bin_with_keypoints[i].pt[0];
bin_with_keypoints[i].pt[1];
That’s fine. But I also want to find the blob centers using “moments” to compare as well. However I’m kneecapped immediately with an exception in the the first line of Moments m.
...code to aquire a frame (greyscale) and convert to binary. Tested = ok.
Moments m = moments(matBinImage, true); // exception line
Code snippet:
Moments m = moments(matBinImage, true); // exception line
Point p(m.m10/m.m00, m.m01/m.m00);
//centroid coordinates
cout<<Mat(p) << std::endl;