Ask Your Question
0

x y cordinates of the blobs detected by simple blob detector

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

shreya gravatar image

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

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);
resize(im,im,s);
imshow("original",im);




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

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

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

// filter my min distance
//params.minDistBetweenBlobs=100;

// 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
params.filterByColor=true;
params.blobColor=255;

// 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
Point2f point1=keypoints.at(0).pt;
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 );

waitKey();

}

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

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

LBerger gravatar image

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

May be you can use a loop...

for (int i=0;i<keypoints.size();i++)
     cout<<keypoints[i].pt<<"\n";

you can use this sample too

edit flag offensive delete link more

Comments

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 -0600 )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++)
           cout<<keypoints[i].size<<endl;
Satyam Sevanya gravatar imageSatyam Sevanya ( 2018-01-21 04:11:10 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 9,139 times

Last updated: Feb 18 '17