Python mat 不是数字元组:openCV 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27365634/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mat is not a numerical tuple : openCV error
提问by user3218971
i have write down a code showing error i ma not getting it: Please help: Its showing mat is not a numerical tuple:
我已经写下一个代码,显示错误我可能没有得到它:请帮助:它的显示垫不是数字元组:
import cv
import cv2
capture = cv2.VideoCapture("j.3gp")
while(1):
_, frame1 = capture.read()
grayImage1 = cv2.cvtColor(frame1, cv2.COLOR_BGR2GRAY)
_, frame2 = capture.read()
grayImage2 = cv2.cvtColor(frame2, cv2.COLOR_BGR2GRAY)
differenceImage = cv2.absdiff(grayImage1,grayImage2)
thresholdImage = cv2.threshold(differenceImage,25,255,cv2.THRESH_BINARY)
cv2.imshow("Difference Image", differenceImage)
cv2.imshow("threshold Image", thresholdImage)
cv2.imshow("Image", frame1)
k = cv2.waitKey(30) & 0xff
Error arising :
-----------------------------------------------------------------------------------------
Traceback (most recent call last):
File "Desk.py", line 15, in <module>
cv2.imshow("threshold Image", thresholdImage)
TypeError: mat is not a numerical tuple
回答by user3218971
I got the answer myself: cv2.threshold
returns two values and adding an extra variable at the start rectifies the error like given below as I did in capture.read()
我自己得到了答案:cv2.threshold
返回两个值并在开始时添加一个额外的变量纠正了下面给出的错误,就像我在capture.read()
thresholdImage = cv2.threshold(differenceImage,25,255,cv2.THRESH_BINARY)
should be:
应该:
_ ,thresholdImage = cv2.threshold(differenceImage,25,255,cv2.THRESH_BINARY)
回答by gobrandal
_ ,thresholdImage = cv2.threshold(differenceImage,25,255,cv2.THRESH_BINARY)
_ ,thresholdImage = cv2.threshold(differenceImage,25,255,cv2.THRESH_BINARY)
could also be
也可以
thresholdImage = cv2.threshold(differenceImage,25,255,cv2.THRESH_BINARY)**[1]**