【问题标题】:Error is using opencv with python错误是在 python 中使用 opencv
【发布时间】:2015-12-23 07:52:39
【问题描述】:

我有这段代码可以用 python 在 opencv 中查找轮廓

im = cv2.imread('test.jpg')
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray,127,255,0)
image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

当我尝试运行它时,我收到一条错误消息

"ValueError: 需要两个以上的值才能解压"

感谢任何帮助。

【问题讨论】:

    标签: python opencv contour


    【解决方案1】:

    实际上cv2.findcontours()方法有一些文档不匹配,它简单地返回2个值:contours, hierarchy,所以你应该把最后一行替换为:

    contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
    

    【讨论】:

      猜你喜欢
      • 2020-09-13
      • 1970-01-01
      • 2018-05-08
      • 2021-12-20
      • 1970-01-01
      • 2017-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多