如何不显示特定大小的斑点? (OpenCV,Python)
How do I not get blobs of a certain size displayed? (OpenCV, Python)
我需要 OpenCV 中的一个函数,它允许我不显示特定大小的斑点,就像图中斑点用红色圆圈标记的图片,我希望它们不显示在图片。
这是我使用的代码:
img = cv.imread('Fotos/1.jpg')
params = cv.SimpleBlobDetector_Params()
params.filterByArea = True
params.minArea = 8200
params.maxArea = 15500
detector = cv.SimpleBlobDetector_create(params)
keypoints = detector.detect(img)
#draw blobs
img_with_blobs = cv.drawKeypoints(img, keypoints, np.array([]), (0, 0, 255), cv.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
plt.imshow(img_with_blobs)
cv.imshow("Keypoints", img_with_blobs)
Blobs detected
import cv2
img = cv2.imread('input/1.png')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 51, 9)
cnts = cv2.findContours(thresh, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
if 8200 < cv2.contourArea(c) < 12500:
cv2.drawContours(img, [c], -1, (255, 255, 255), -1)
cv2.imshow("1", img)
erased result
我需要 OpenCV 中的一个函数,它允许我不显示特定大小的斑点,就像图中斑点用红色圆圈标记的图片,我希望它们不显示在图片。
这是我使用的代码:
img = cv.imread('Fotos/1.jpg')
params = cv.SimpleBlobDetector_Params()
params.filterByArea = True
params.minArea = 8200
params.maxArea = 15500
detector = cv.SimpleBlobDetector_create(params)
keypoints = detector.detect(img)
#draw blobs
img_with_blobs = cv.drawKeypoints(img, keypoints, np.array([]), (0, 0, 255), cv.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
plt.imshow(img_with_blobs)
cv.imshow("Keypoints", img_with_blobs)
Blobs detected
import cv2
img = cv2.imread('input/1.png')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
thresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 51, 9)
cnts = cv2.findContours(thresh, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
if 8200 < cv2.contourArea(c) < 12500:
cv2.drawContours(img, [c], -1, (255, 255, 255), -1)
cv2.imshow("1", img)
erased result