imgProcess_tool.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:Farmbot_GeneralAP 作者: SpongeYao 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号