import cv2
import numpy as np
img1 = cv2.imread('p1.jpg')
img2 = cv2.imread('p2.jpg')
rows,cols,channels = img2.shape
roi = img1[0:rows,0:cols]
ret,img2gray = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
mask = cv2.threshold(img2gray,100,255, cv2.THRESH_BINARY_INV)
cv2.imshow('mask',mask)
cv2.waitKey(0)
cv2.destroyAllWindows()
如果我从img2gray代码行中删除ret,则以下错误将生成此ValueError
Traceback (most recent call last):
File "oc5.py", line 10, in <module>
ret,img2gray = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
ValueError: too many values to unpack (expected 2)
答案 0 :(得分:2)
cv2.cvtColor返回两个值。 Ret只是一个虚拟变量,用于保存第一个值