如何在不同的OpenCV版本中使用`cv2.findContours`? [英] How to use `cv2.findContours` in different OpenCV versions?

查看:446
本文介绍了如何在不同的OpenCV版本中使用`cv2.findContours`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将OpenCV与Python配合使用,以便检测来自Raspberry Pi摄像机的实时视频源中的正方形.但是,下面的代码中的cv2.GaussianBlurcv2.Canny函数导致以下错误:"TypeError:numpy.ndarray'对象不可调用"..

I am trying to use OpenCV with Python in order to detect squares in a live video feed from a Raspberry Pi camera. However, the cv2.GaussianBlur and cv2.Canny functions in the code below are causing the following error: "TypeError: numpy.ndarray' object is not callable".

我似乎无法解决该错误.任何帮助表示赞赏.

I cannot seem to resolve the error. Any help is appreciated.

代码取自

推荐答案

使用2.x,3.x,4.x的另一种方法是:

An alternative to work with 2.x 、3.x、4.x is:

cnts, hiers = cv2.findContours(...)[-2:]


注意:


Notice:

cv2.findContours已更改,但是在OpenCV 4.0中,它变回来了!!!

cv2.findContours has changed since OpenCV 3.x, but in OpenCV 4.0 it changes back!!!

在OpenCV 3.4中:

In OpenCV 3.4:

findContours(image, mode, method[, contours[, hierarchy[, offset]]]) -> image, contours, hierarchy

在OpenCV 4.0中:

In OpenCV 4.0:

findContours(image, mode, method[, contours[, hierarchy[, offset]]]) -> contours, hierarchy

这篇关于如何在不同的OpenCV版本中使用`cv2.findContours`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆