Ask Your Question

x y cordinates of the blobs detected by simple blob detector

asked 2017-02-18 02:56:09 -0500

shreya gravatar image

updated 2017-02-18 03:17:47 -0500

i am running the sample code for simple blob detector in open cv 3 in c++ i want to print the x and y cordinate of the keypoints that are detected , here is the code:

using namespace cv; using namespace std;

int main() {

 // Read image
 Mat im = imread( "24.jpg", IMREAD_GRAYSCALE );
Size s(400,300);

// Setup SimpleBlobDetector parameters.
SimpleBlobDetector::Params params;

// Change thresholds
params.minThreshold = 10;
params.maxThreshold = 256;

// Filter by Area.
params.filterByArea = true;
params.minArea =50;

// filter my min distance

// Filter by Circularity
params.filterByCircularity = true;
params.minCircularity = 0.8;

// Filter by Convexity
params.filterByConvexity = true;
params.minConvexity = 0.5;

// Filter by Inertia
params.filterByInertia = false;
params.minInertiaRatio = 0.01;

//filter by colour

// Storage for blobs
vector<KeyPoint> keypoints;

// Set up detector with params
Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params);   

// Detect blobs
detector->detect( im, keypoints);

//the total no of blobs detected are:
size_t x=keypoints.size();
cout<<"total no of circles detected are:"<<x<<endl;

//location of first blob
float x1=point1.x;
float y1=point1.y;
cout<<"location of the first blob is "<<x1<<","<<y1;

// Draw detected blobs as red circles.
// DrawMatchesFlags::DRAW_RICH_KEYPOINTS flag ensures
// the size of the circle corresponds to the size of blob

Mat im_with_keypoints;
drawKeypoints( im, keypoints, im_with_keypoints, Scalar(0,0,255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS );

// Show blobs
imshow("keypoints", im_with_keypoints );



edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-02-18 03:06:37 -0500

LBerger gravatar image

updated 2017-02-18 05:22:12 -0500

May be you can use a loop...

for (int i=0;i<keypoints.size();i++)

you can use this sample too

edit flag offensive delete link more


how can i print the diameter of blob detected? and what does the octave parameter of the keypoint return?

shreya gravatar imageshreya ( 2017-02-18 03:18:42 -0500 )edit

To know the diameter of detected blob you can use keypoints[i].size which actually is diameter in pixels

for(int i=0;i<keypoints.size();i++)
Satyam Sevanya gravatar imageSatyam Sevanya ( 2018-01-21 04:11:10 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-02-18 02:56:09 -0500

Seen: 6,354 times

Last updated: Feb 18 '17