mat不是数字元组:openCV错误

问题描述 投票:9回答:2

我写下了一个代码显示错误我没有得到它:请帮助:它的显示垫不是一个数字元组:

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
python opencv
2个回答
20
投票

我自己得到了答案:cv2.threshold返回两个值并在开始时添加一个额外的变量来纠正错误,就像我在capture.read()中所做的那样

thresholdImage = cv2.threshold(differenceImage,25,255,cv2.THRESH_BINARY)

应该:

_ ,thresholdImage = cv2.threshold(differenceImage,25,255,cv2.THRESH_BINARY)

1
投票

_,thresholdImage = cv2.threshold(differenceImage,25,255,cv2.THRESH_BINARY)

也可能是

thresholdImage = cv2.threshold(differenceImage,25,255,cv2.THRESH_BINARY)**[1]**
© www.soinside.com 2019 - 2024. All rights reserved.