目标:在另一个蒙版图像中复制较大的斑点
我有一个带有斑点的阈值图像,如图所示:
我怎样才能将较大的斑点复制到蒙版图像中并省略一个像素的斑点?
我的代码(但我没有得到想要的结果):
import numpy as np
import cv2
ref_img = cv2.imread('threshold.jpg', 0)
thresh = np.copy(ref_img)
cnts,_ = cv2.findContours(ref_img, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
mask = np.zeros(ref_img.shape, dtype="uint8")
for c in cnts:
(x,y),radius = cv2.minEnclosingCircle(c)
area = cv2.contourArea(c)
if int(area) < 1:
cv2.circle(mask, (int(x), int(y)), int(radius), (255, 255, 255), -1)
cv2.imshow('img', mask)
cv2.waitKey(0)
注意:使用 OpenCV 2.4.x