我试图在图像中找到白色圆形斑点。当我尝试使用houghcircles时,我不断将字母和数字误认为是圆圈,而我只需要完整的圆圈,即斑点。
所以我用自定义参数运行这个blob探测器代码,找到左上角的圆形IC引脚标记。但我一直在'9'和'0'内变黑圈。 它根本没有检测到任何白色斑点。
这是我尝试过的代码:
import cv2
import numpy as np;
# Read image
img = cv2.imread("C:\chi4.jpg", cv2.IMREAD_GRAYSCALE)
retval, threshold = cv2.threshold(img, 200, 255, cv2.THRESH_BINARY)
params = cv2.SimpleBlobDetector_Params()
# Change thresholds
params.minThreshold = 10;
params.maxThreshold = 255;
blur = cv2.GaussianBlur(img,(5,5),0)
params.filterByCircularity = True
params.minCircularity = 0.2
params.filterByArea = True;
params.minArea = 1000;
ver = (cv2.__version__).split('.')
if int(ver[0]) < 3 :
detector = cv2.SimpleBlobDetector(params)
else :
detector = cv2.SimpleBlobDetector_create(params)
# Set up the detector with default parameters.
#detector = cv2.SimpleBlobDetector()
# Detect blobs.
keypoints = detector.detect(threshold)
# 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(img, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
# Show keypoints
cv2.imshow("Keypoints", im_with_keypoints)
cv2.waitKey(0)
红色圆圈是检测到的。我希望在蓝色标记的顶部检测到白色圆形斑点。
我尝试更改阈值参数,仍然没有影响。请告诉我出错的地方或提高产量的建议。 提前致谢:D