def getContours(img,kernel=(10,10)):
#Define kernel
kernel = np.ones(kernel, np.uint8)
#Open to erode small patches
thresh = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel)
#Close little holes
thresh = cv2.morphologyEx(thresh, cv2.MORPH_CLOSE,kernel, iterations=4)
#Find contours
#contours=skimsr.find_contours(thresh,0)
thresh=thresh.astype('uint8')
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_NONE)
areas=[]
for c in contours:
areas.append(cv2.contourArea(c))
return contours,thresh,areas
评论列表
文章目录