opencv blob分析

Blob翻译成中文,是“一滴”,“一抹”,“一团”,“弄脏”,“弄错”的意思。在计算机视觉中的Blob是指图像中的具有相似颜色、纹理等特征所组成的一块连通区域。显然,Blob分析其实就是将图像进行二值化,分割得到前景和背景,然后进行连通区域检测,从而得到Blob快的过程。简单来说,blob分析就是在一块“光滑”区域内,将出现“灰度突变”的小区域寻找出来。举例来说,假如现在有一块刚生产出来的玻璃,表面非常光滑,平整。如果这块玻璃上面没有瑕疵,那么,我们是检测不到“灰度突变”的;相反,如果在玻璃生产线上,由于种种原因,造成了玻璃上面有一个凸起的小泡、有一块黑斑、有一点裂缝。。。那么,我们就能在这块玻璃上面检测到纹理,颜色发生突变的部分,而这些部分,就是生产过程中造成的瑕疵,而这个过程,就是blob分析。显然,纺织品的瑕疵检测,玻璃的瑕疵检测,机械零件表面缺陷检测,可乐瓶缺陷检测,药品胶囊缺陷检测等很多场合都会用到blob分析。
————————————————
版权声明:本文为CSDN博主「ChenLee_1」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/carson2005/article/details/8145412


opencv python中

# Standard imports
import cv2
import numpy as np;
# Read image
im = cv2.imread("blob.jpg", cv2.IMREAD_GRAYSCALE)
# Set up the detector with default parameters.
detector = cv2.SimpleBlobDetector()
# Detect blobs.
keypoints = detector.detect(im)
# Draw detected blobs as red circles.
# cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS ensures the size of the circle corresponds to the size of blob
im_with_keypoints = cv2.drawKeypoints(im, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
# Show keypoints
cv2.imshow("Keypoints", im_with_keypoints)
cv2.waitKey(0)


opencv c++ 

using namespace cv;
// Read image
Mat im = imread( "blob.jpg", IMREAD_GRAYSCALE );
// Set up the detector with default parameters.
SimpleBlobDetector detector;
// Detect blobs.
std::vector<KeyPoint> keypoints;
detector.detect( im, keypoints);
// 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(0);


sitemap