Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

x y cordinates of the blobs detected by simple blob detector

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 s=keypoints.size();
cout<<"total no of circles detected are:"<<s<<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();

}

x y cordinates of the blobs detected by simple blob detector

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 s=keypoints.size();
x=keypoints.size();
cout<<"total no of circles detected are:"<<s<<endl;
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();

}