I am trying to make a motion detector but at last when i tying to counter the boject it gives me a Type Error, I don,t know much about open cv, I tried to find the solution on in ternet but there was no solution to this
The code is as follows:
import cv2
vedio = cv2.VideoCapture(0)
first_frame = None
while True:
check , frame = vedio.read()
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray,(21,21),0)
if first_frame is None:
first_frame=gray
continue
new_frame = cv2.absdiff(first_frame,gray)
thresh_frame = cv2.threshold(new_frame, 30 ,255, cv2.THRESH_BINARY)[1]
thresh_frame = cv2.dilate(thresh_frame,None,iterations = 2)
(__,cnts__,) = cv2.findContours(thresh_frame.copy(),cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
for contour in (__,cnts__,):
if cv2.contourArea(contour) < 1000:
continue
(x,y,w,h) = cv2.boundingRect(contour)
cv2.rectangle(frame, (x,y), (x + w+ y + h), (0,255,0),3)
cv2.imshow("thresh",thresh_frame)
cv2.imshow("Capture",gray)
key = cv2.waitKey(1)
if key == ord('g'):
break
print(a)
vedio.release()
cv2.destroyAllWindows()
The error i get is :
Traceback (most recent call last):
File "E:\Python\Python\open cv\vedio.py", line 30, in <module>
if cv2.contourArea(contour) < 1000:
TypeError: Expected cv::UMat for argument 'contour'
[ WARN:0] terminating async callback
What I have tried:
I tried stackoverflow but there was no proper answer for this..