无法检测到任何白色斑点 - opencv python

Sha*_*r S 0 python opencv

我试图在图像中找到白色圆形斑点.当我尝试使用houghcircles时,我不断将字母和数字误认为是圆圈,而我只需要完整的圆圈,即blob.

所以我用自定义参数运行这个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)
Run Code Online (Sandbox Code Playgroud)

这是我的输出图像: 输出图像

红色圆圈是检测到的圆圈.我想要在蓝色标记的顶部检测到白色圆形斑点.

我试过更改阈值参数,仍然没有影响.请告诉我出错的地方或提高产量的建议.提前致谢

Jer*_*uke 6

通常假设斑点为灰色/黑色.在你的情况下,字母边的斑点是黑色的.但是你想要的斑点是白色的.因此它不被承认.

在您的代码中,您必须将第四行更改为:

retval, threshold = cv2.threshold(img, 200, 255, cv2.THRESH_BINARY_INV)
Run Code Online (Sandbox Code Playgroud)

我对以下内容采用了相同的方法:

我在下图中执行了blob检测:

在此输入图像描述

但没有找到任何blob:

在此输入图像描述

我将二进制图像反转为以下内容:

在此输入图像描述

现在我能够检测到它们如图所示:

在此输入图像描述