'mat is not a numerical tuple : openCV error
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
Solution 1:[1]
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()
thresholdImage = cv2.threshold(differenceImage,25,255,cv2.THRESH_BINARY)
should be:
_ ,thresholdImage = cv2.threshold(differenceImage,25,255,cv2.THRESH_BINARY)
Solution 2:[2]
_ ,thresholdImage = cv2.threshold(differenceImage,25,255,cv2.THRESH_BINARY)
could also be
thresholdImage = cv2.threshold(differenceImage,25,255,cv2.THRESH_BINARY)**[1]**
Solution 3:[3]
_,img_otsu = cv.threshold(img_2,127,255, cv.THRESH_BINARY+cv.THRESH_OTSU)
use this also
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Keiwan |
Solution 2 | Richard |
Solution 3 | Suraj Rao |