【问题标题】:ValueError in python OpenCV - not enough values to unpack (expected 3, got 2)python OpenCV中的ValueError - 没有足够的值来解包(预期3,得到2)
【发布时间】:2021-10-07 03:35:59
【问题描述】:

我在 Google Colaboratory 的 python OpenCV 中有一个 ValueError:没有足够的值来解包(预期 3,得到 2)。 另外,我正在制作一些程序来检测水的轮廓并给出坐标。 我怎样才能尽快解决这个问题?

import cv2
import numpy as np
from google.colab import drive

drive.mount('/content/drive')
img = cv2.imread('/content/drive/MyDrive/lake1.jpg')

imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

ret, imthres = cv2.threshold(imgray, 127, 255, cv2.THRESH_BINARY_INV)

im2, contour, hierarchy = cv2.findContours(imthres, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) # here's the ValueError.

【问题讨论】:

标签: python opencv google-colaboratory


【解决方案1】:

如您所见herefindContours 只返回轮廓和层次结构,而不是图像本身,如

contour, hierarchy = cv2.findContours(imthres, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)

这就是这个错误信息的意思。

【讨论】:

  • 谢谢,我刚刚修改,现在可以了。
  • @htl1111 如果答案对您有用,请接受(绿色复选标记)。
猜你喜欢
  • 2017-07-04
  • 2020-07-17
  • 2019-09-24
  • 1970-01-01
  • 2017-09-14
  • 1970-01-01
  • 2019-01-05
  • 2020-09-28
  • 1970-01-01
相关资源
最近更新 更多