首先,我正在使用Python 2.7和OpenCV进行Blob检测。我想要做的是在颜色检测后完成Blob检测。我想要检测红色圆圈(标记),并避免其他Blob的干扰。因此,我想要先进行颜色检测,然后再进行Blob检测。
经过颜色检测后的图像为二值掩模
现在,我想在这个图像上进行Blob检测,但是它没有起作用。这是我的代码。
import cv2
import numpy as np;
# Read image
im = cv2.imread("myblob.jpg", cv2.IMREAD_GRAYSCALE)
# Set up the detector with default parameters.
params = cv2.SimpleBlobDetector_Params()
# Change thresholds
params.minThreshold = 10; # the graylevel of images
params.maxThreshold = 200;
params.filterByColor = True
params.blobColor = 255
# Filter by Area
params.filterByArea = False
params.minArea = 10000
detector = cv2.SimpleBlobDetector(params)
# 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)`
我对这段代码感到非常困惑,因为它可以在这张图片上运行:白点。我认为这张白点图片与二进制掩码非常相似,但为什么我不能在二进制图像上进行斑点检测呢?有人能告诉我其中的区别或正确的代码吗?
谢谢!!
敬礼, 南