斑点检测
1、斑点
- 斑点:是一组连通的像素在图像中共享一些共同的属性(如灰度值、颜色等)
2、opencv中的斑点检测(SimpleBlobDetector)
#include <opencv2/highgui.hpp>
#include <opencv2/calib3d.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(){
Mat img = imread("blob.jpg",IMREAD_GRAYSCALE);
/*
SimpleBlobDetector::Params params;
//阈值控制
params.minThreshold = 10;
params.maxThreshold = 200;
//像素面积大小控制
params.filterByArea = true;
params.minArea = 1000;
//形状(凸)
params.filterByCircularity = false;
params.minCircularity = 0.7;
//形状(凹)
params.filterByConvexity = true;
params.minConvexity = 0.9;
//形状(园)
params.filterByInertia = false;
params.minInertiaRatio = 0.5;
*/
Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create();
vector<KeyPoint> keypoints;
detector->detect(img,keypoints);
Mat img_with_keypoints;
drawKeypoints(img,keypoints,img_with_keypoints,Scalar(0,0,255),DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
imshow("keypoints",img_with_keypoints);
waitKey(0);
return 0;
}
原图:
检测结果
3、SimpleBolbDetector参数:
- 像素大小参数:
- 凸型参数:
- 凹型参数:
- 圆型参数: