我试图计算二值化后的白点数量,但我的代码似乎没有检测到任何东西。
输入图像
我的输出如下所示。
输入图像
![enter image description here](https://istack.dev59.com/bAU03.webp)
#Standard imports
#!/usr/bin/python
# Standard imports
import cv2
import numpy as np;
# Read and threshold image
im = cv2.imread("CopperSEM.tif", cv2.IMREAD_GRAYSCALE)
ret2, LocalTH1 = cv2.threshold(im,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU) #Without Filtering
# Set up the detector with default parameters.
parameters = cv2.SimpleBlobDetector_Params()
#change Colors to White
parameters.filterByColor = True
parameters.blobColor = 255
parameters.filterByArea = True
parameters.minArea = 1500
parameters.filterByCircularity = True
parameters.minCircularity = 0.1
parameters.filterByConvexity = True
parameters.minConvexity = 0.87
#reset the detector
detector = cv2.SimpleBlobDetector_create(parameters)
# Detect blobs.
keypoints = detector.detect(LocalTH1)
print(len(keypoints)) #will print out the number of objects that were found since keypoints is a list?
# 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(LocalTH1, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
# Show keypoints
cv2.imshow("Keypoints", im_with_keypoints)
cv2.waitKey(0)
我的输出如下所示。
![在这里输入图片描述](https://istack.dev59.com/9X8FA.webp)