Blob在机器视觉中是指图像中的具备类似颜色、纹理等特征所组成的一块连通区域。Blob分析就是对这一块连通区域进行几何分析获得一些重要的几何特征,例如:区域的面积、中心点坐标、质心坐标、最小外接矩形、主轴等。
在检测运动目标时,若是背景是静止的,利用当前图像与预存的背景图像做差分,再利用阈值来检测运动区域的一种动态目标识别技术。 背景差分算法适用于背景已知的状况,但难点是如何自动得到长久的静态背景模型。 matlab中单纯的背景差分直接是函数imabsdiff(X,Y)就能够。ios
利用视频序列中连续的两帧或几帧图像的差来进行目标检测和提取。在运动的检测过程当中,该方法利用时间信息,经过比较图像中若干连续帧得到对应像素点的灰度差值,若是均大于必定的阈值T2,则能够判断该位置存在运动的目标。 较适合于动态变化场景。 算法
利用相邻两帧中对应像素的灰度保持原理来评估二维图像的变化。可以较好的从背景中检测到相关前景目标,甚至是运动屋里中的部分运动目标,适用于摄像机运动过程当中相对运动目标的检测。 开口问题、光流场约束方程的解的不惟一性问题。不能正确的表示实际的运动场。app
1 @brief Class for extracting blobs from an image. : 2 The class implements a simple algorithm for extracting blobs from an image: 3 4 1. Convert the source image to binary images by applying thresholding with several thresholds from 5 minThreshold (inclusive) to maxThreshold (exclusive) with distance thresholdStep between 6 neighboring thresholds. 7 2. Extract connected components from every binary image by findContours and calculate their 8 centers. 9 3. Group centers from several binary images by their coordinates. Close centers form one group that 10 corresponds to one blob, which is controlled by the minDistBetweenBlobs parameter. 11 4. From the groups, estimate final centers of blobs and their radiuses and return as locations and 12 sizes of keypoints. 13 14 This class performs several filtrations of returned blobs. You should set filterBy\* to true/false 15 to turn on/off corresponding filtration. Available filtrations: 16 17 - **By color**. This filter compares the intensity of a binary image at the center of a blob to 18 blobColor. If they differ, the blob is filtered out. Use blobColor = 0 to extract dark blobs 19 and blobColor = 255 to extract light blobs. 20 - **By area**. Extracted blobs have an area between minArea (inclusive) and maxArea (exclusive). 21 - **By circularity**. Extracted blobs have circularity 22 (\f$\frac{4*\pi*Area}{perimeter * perimeter}\f$) between minCircularity (inclusive) and 23 maxCircularity (exclusive). 24 - **By ratio of the minimum inertia to maximum inertia**. Extracted blobs have this ratio 25 between minInertiaRatio (inclusive) and maxInertiaRatio (exclusive). 26 - **By convexity**. Extracted blobs have convexity (area / area of blob convex hull) between 27 minConvexity (inclusive) and maxConvexity (exclusive). 28 29 Default values of parameters are tuned to extract dark circular blobs.
1 class CV_EXPORTS_W SimpleBlobDetector : public Feature2D 2 { 3 public: 4 struct CV_EXPORTS_W_SIMPLE Params 5 { 6 CV_WRAP Params(); 7 CV_PROP_RW float thresholdStep; 8 CV_PROP_RW float minThreshold; 9 CV_PROP_RW float maxThreshold; 10 CV_PROP_RW size_t minRepeatability; 11 CV_PROP_RW float minDistBetweenBlobs; 12 13 CV_PROP_RW bool filterByColor; 14 CV_PROP_RW uchar blobColor; 15 16 CV_PROP_RW bool filterByArea; 17 CV_PROP_RW float minArea, maxArea; 18 19 CV_PROP_RW bool filterByCircularity; 20 CV_PROP_RW float minCircularity, maxCircularity; 21 22 CV_PROP_RW bool filterByInertia; 23 CV_PROP_RW float minInertiaRatio, maxInertiaRatio; 24 25 CV_PROP_RW bool filterByConvexity; 26 CV_PROP_RW float minConvexity, maxConvexity; 27 28 void read( const FileNode& fn ); 29 void write( FileStorage& fs ) const; 30 };
1 #include <opencv2/highgui.hpp> 2 #include <opencv2/calib3d.hpp> 3 #include <iostream> 4 5 using namespace std; 6 using namespace cv; 7 8 int main() { 9 Mat img = imread("D://Images/cut/2.jpg", 0); 10 11 /* 12 SimpleBlobDetector::Params params; 13 //阈值控制 14 params.minThreshold = 10; 15 params.maxThreshold = 200; 16 //像素面积大小控制 17 params.filterByArea = true; 18 params.minArea = 1000; 19 //形状(凸) 20 params.filterByCircularity = false; 21 params.minCircularity = 0.7; 22 //形状(凹) 23 params.filterByConvexity = true; 24 params.minConvexity = 0.9; 25 //形状(圆) 26 params.filterByInertia = false; 27 params.minInertiaRatio = 0.5; 28 */ 29 30 Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(); 31 vector<KeyPoint> keypoints; 32 detector->detect(img, keypoints); 33 Mat img_with_keypoints; 34 drawKeypoints(img, keypoints, img_with_keypoints, Scalar(0, 0, 255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS); 35 imshow("keypoints", img_with_keypoints); 36 waitKey(0); 37 return 0; 38 }
1 Mat dst=new Mat(); 2 //取单通道图像 3 dst==Imgcodecs.imread("blob.jpg",0); 4 //存储结果信息MatofKeyPoint 包含7个通道,分别对应7项信息 5 /** 6 buff[_channels*i+0] = (float) kp.pt.x; 7 buff[_channels*i+1] = (float) kp.pt.y; 8 buff[_channels*i+2] = kp.size; 9 buff[_channels*i+3] = kp.angle; 10 buff[_channels*i+4] = kp.response; 11 buff[_channels*i+5] = kp.octave; 12 buff[_channels*i+6] = kp.class_id; 13 **/ 14 MatOfKeyPoint keypoints = new MatOfKeyPoint(); 15 Mat keyMat = new Mat(); 16 //FeatureDetector 第九项检测为SimpleBolb 分析 17 /** 18 FAST = 1, 19 STAR = 2, 20 SIFT = 3, 21 SURF = 4, 22 ORB = 5, 23 MSER = 6, 24 GFTT = 7, 25 HARRIS = 8, 26 SIMPLEBLOB = 9, 27 DENSE = 10, 28 BRISK = 11, 29 AKAZE = 12, 30 GRID_FAST = GRIDDETECTOR + FAST, 31 GRID_STAR = GRIDDETECTOR + STAR, 32 GRID_SIFT = GRIDDETECTOR + SIFT, 33 GRID_SURF = GRIDDETECTOR + SURF, 34 GRID_ORB = GRIDDETECTOR + ORB, 35 GRID_MSER = GRIDDETECTOR + MSER, 36 GRID_GFTT = GRIDDETECTOR + GFTT, 37 GRID_HARRIS = GRIDDETECTOR + HARRIS, 38 GRID_SIMPLEBLOB = GRIDDETECTOR + SIMPLEBLOB, 39 GRID_DENSE = GRIDDETECTOR + DENSE, 40 GRID_BRISK = GRIDDETECTOR + BRISK, 41 GRID_AKAZE = GRIDDETECTOR + AKAZE, 42 PYRAMID_FAST = PYRAMIDDETECTOR + FAST, 43 PYRAMID_STAR = PYRAMIDDETECTOR + STAR, 44 PYRAMID_SIFT = PYRAMIDDETECTOR + SIFT, 45 PYRAMID_SURF = PYRAMIDDETECTOR + SURF, 46 PYRAMID_ORB = PYRAMIDDETECTOR + ORB, 47 PYRAMID_MSER = PYRAMIDDETECTOR + MSER, 48 PYRAMID_GFTT = PYRAMIDDETECTOR + GFTT, 49 PYRAMID_HARRIS = PYRAMIDDETECTOR + HARRIS, 50 PYRAMID_SIMPLEBLOB = PYRAMIDDETECTOR + SIMPLEBLOB, 51 PYRAMID_DENSE = PYRAMIDDETECTOR + DENSE, 52 PYRAMID_BRISK = PYRAMIDDETECTOR + BRISK, 53 PYRAMID_AKAZE = PYRAMIDDETECTOR + AKAZE, 54 DYNAMIC_FAST = DYNAMICDETECTOR + FAST, 55 DYNAMIC_STAR = DYNAMICDETECTOR + STAR, 56 DYNAMIC_SIFT = DYNAMICDETECTOR + SIFT, 57 DYNAMIC_SURF = DYNAMICDETECTOR + SURF, 58 DYNAMIC_ORB = DYNAMICDETECTOR + ORB, 59 DYNAMIC_MSER = DYNAMICDETECTOR + MSER, 60 DYNAMIC_GFTT = DYNAMICDETECTOR + GFTT, 61 DYNAMIC_HARRIS = DYNAMICDETECTOR + HARRIS, 62 DYNAMIC_SIMPLEBLOB = DYNAMICDETECTOR + SIMPLEBLOB, 63 DYNAMIC_DENSE = DYNAMICDETECTOR + DENSE, 64 DYNAMIC_BRISK = DYNAMICDETECTOR + BRISK, 65 DYNAMIC_AKAZE = DYNAMICDETECTOR + AKAZE; 66 */ 67 FeatureDetector featureDetector = FeatureDetector.create(9); 68 //配置为xml文件,能够先生成默认xml文件,再进行修改数值 69 featureDetector.read("params.xml"); 70 // 修改测试 71 featureDetector.detect(dst, keypoints);