def findContours(arg_img,arg_canvas, arg_MinMaxArea=False, arg_debug= False):
image= arg_img.copy()
#print image
canvas= arg_canvas.copy()
if len(image)==3:
image = cv2.cvtColor(self.image, cv2.COLOR_GRAY2BGR)
if sys.version_info.major == 2:
ctrs, hier = cv2.findContours(image.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
else:
_, ctrs, hier = cv2.findContours(image.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
if arg_MinMaxArea is not False:
ctrs = filter(lambda x : arg_MinMaxArea[1]> cv2.contourArea(x) > arg_MinMaxArea[0] , ctrs)
print '>>> ', len(ctrs)
for ctr in ctrs:
print 'Area: ', cv2.contourArea(ctr)
cv2.drawContours(canvas, [ctr], 0, (0, 128, 255), 3)
if arg_debug:
cv2.imwrite('Debug/debug_findContours.jpg',canvas)
return canvas
评论列表
文章目录