Blob是指图像中的一块连通区域,Blob分析就是对前景/背景分离后的二值图像,进行连通域提取和标记。
知识点就是SimpleBlobDetector的使用,blob(斑点)筛选条件:斑点颜色、面积、圆度、惯性率、凸度,参数解读链接
#include<opencv2/opencv.hpp> #include <iostream> using namespace std; using namespace cv; int main() { Mat src=imread("D:/sunflower.png"); //*参数设置,以下都是默认参数 SimpleBlobDetector::Params pDefaultBLOB; pDefaultBLOB.thresholdStep = 10; pDefaultBLOB.minThreshold = 50; pDefaultBLOB.maxThreshold = 220; pDefaultBLOB.minRepeatability = 2; pDefaultBLOB.minDistBetweenBlobs = 10; pDefaultBLOB.filterByColor = true; pDefaultBLOB.blobColor = 0; pDefaultBLOB.filterByArea = true; pDefaultBLOB.minArea = 25; pDefaultBLOB.maxArea = 5000; pDefaultBLOB.filterByCircularity = false; pDefaultBLOB.minCircularity = 0.8f; pDefaultBLOB.maxCircularity = (float)3.40282e+038; pDefaultBLOB.filterByInertia = true; pDefaultBLOB.minInertiaRatio = 0.1f; pDefaultBLOB.maxInertiaRatio = (float)3.40282e+038; pDefaultBLOB.filterByConvexity = true; pDefaultBLOB.minConvexity = 0.95f; pDefaultBLOB.maxConvexity = (float)3.40282e+038; //*用参数创建对象 Ptr<SimpleBlobDetector> blob=SimpleBlobDetector::create(pDefaultBLOB); //Ptr<SimpleBlobDetector> blob=SimpleBlobDetector::create();//默认参数创建 //*blob检测 vector<KeyPoint> key_points; blob->detect(src,key_points); Mat outImg; //*绘制结果 drawKeypoints(src,key_points,outImg,Scalar(0,0,255)); imshow("blob",outImg); waitKey(); return 0; }