python OpenCV 中的 ValueError - 没有足够的值来解压(预期 3,得到 2)
ValueError in python OpenCV - not enough values to unpack (expected 3, got 2)
我在 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.
如您所见,here findContours
只有 returns 轮廓和层次结构,而不是图像本身,如
contour, hierarchy = cv2.findContours(imthres, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
这就是这条错误信息的意思。
我在 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.
如您所见,here findContours
只有 returns 轮廓和层次结构,而不是图像本身,如
contour, hierarchy = cv2.findContours(imthres, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
这就是这条错误信息的意思。