2017-05-02 5 views
-2

, 나는 이런 식으로 작업을 수행 할 수 있습니다connectedComponentsWithStats를 사용하여 도트를 제거하는 방법은 무엇입니까? 윤곽으로

if cv2.contourArea(cntr) <= 3: 
     cv2.drawContours(img, [cntr], -1, (0, 0, 0), 1) 

어떻게 ConnectedComponentsStats 함께 할 수 있나요?

+0

비슷한 질문이 오류가 발생합니까? http://stackoverflow.com/questions/44087581/opencv-3-with-python3-getting-this-error-215-npoints-0-in-function-drawcon – Aleks

답변

1

당신이하는 다음 단계 connectedComponentsWithStats와 동일한 작업을 수행하려면 다음

// This here is for making a custom image 
img = np.zeros((500,500,3),dtype=np.uint8) 
for i in xrange(1,5): 
    img = cv2.circle(img, (i*80,i*80), 5, (255,255,255), -1)  
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 

Custom image

// CCA from here 
labelnum, labelimg, contours, GoCs = cv2.connectedComponentsWithStats(gray) 

for label in xrange(1,labelnum): 
    x,y = GoCs[label] 
    img = cv2.circle(img, (int(x),int(y)), 1, (0,0,255), -1)  

    x,y,w,h,size = contours[label] 
    if size <= 100: 
     img = cv2.rectangle(img, (x,y), (x+w,y+h), (255,255,0), 1)  

이것은 다음과 같은 이미지를 제공합니다 :

CCA image

희망 도움이됩니다!

+0

답변으로 문제가 해결되면 추후에 친절하게 받아들입니다. 사용자! –