Hi im new with opencv, currently i need to detect a beans from a live feed camera, im able to detect it with SimpleBlobDetector function. Now i want to know the average color inside of the blob to do some calculation. What is the best way to do it?
Mat im_with_keypoints;
drawKeypoints( capture, keypoints, im_with_keypoints, Scalar(0,0,255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS );
size_t i, k;
Point Coordinate;
for( i = k = 0; i < keypoints.size(); i++ )
{
Coordinate = keypoints[i].pt ;
qDebug ()<< "x " << Coordinate.x << "y " <<Coordinate.y;
qDebug ()<< "s " << keypoints[i].size ;
}
This is my Code to detect the coordinate of each blob and the diameter of it
Thanks for the reply this help me alot! I tried to change a little bit of the code
Mat im_with_keypoints;
drawKeypoints( capture, keypoints, im_with_keypoints, Scalar(0,0,255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS );
size_t i, k;
Point Coordinate;
for( i = k = 0; i < keypoints.size(); i++ )
{
Coordinate = keypoints[i].pt ;
Rect r(Coordinate.x-(keypoints[i].size /2), Coordinate.y-(keypoints[i].size/2), keypoints[i].size, keypoints[i].size) ;
Mat roi(im_with_keypoints, r);
cv::Scalar mean;
mean = cv::mean(roi);
qDebug() << "Blue " << mean[0] ;
qDebug() << "Green " << mean[1] ;
qDebug() << "Red " << mean[2] ;
}
This code above also the same right? also i have another question, if i use cvtColor to change the color from BGR to HSV is it better to detect the color or it will be just the same with BGR color?
sure, but you still have to explain “my case”, please. which is ? what are you trying to do ?
is it still: " detect a beans" ? if so, you might profit from doing it in HSV space, since most likely you only have to look at hue for classification (not 3 r,g,b vaues)
Yess its still about detecting the beans. Since the result of the color is not exactly the same with the real color but i know there is a factor from my camera and lighting as well, but maybe i can optimize it if i change the color space, maybe?