I'm a beginner with open CV and am struggling to understand the below code:
import cv2
import numpy as np
c = cv2.VideoCapture(0)
_,f = c.read()
avg1 = np.float64(f)
avg2 = np.float64(f)
while(c.isOpened):
_,f = c.read()
cv2.accumulateWeighted(f,avg1, 0.1)
cv2.accumulateWeighted(f,avg2, 0.01)
res1 = cv2.convertScaleAbs(avg1)
res2 = cv2.convertScaleAbs(avg2)
cv2.imshow('avg1',res1)
cv2.imshow('avg2',res2)
k = cv2.waitKey(10)
if k == 27:
break
cv2.destroyAllWindows()
c.release()
But I get the error:
OpenCV Error: Assertion failed (dst.size == src.size && dst.channels() == cn) in accumulateWeighted, file C:\OpenCV-2.4.2\sources\modules\imgproc\src\accum.cpp, line 430
Traceback (most recent call last):
File "C:\Users\dom\Dropbox\eclipse_luna\testpythen\background extraction_1.py", line 20, in <module>
cv2.accumulateWeighted(f,avg1, 0.1)
cv2.error: C:\OpenCV-2.4.2\sources\modules\imgproc\src\accum.cpp:430: error: (-215) dst.size == src.size && dst.channels() == cn in function accumulateWeighted
I think the error originates from the line : cv2.accumulateWeighted(f,avg1, 0.1)
but am struggling to get it working.
I know from a previous post that the code is opencv 2 compatible, so could someone please give me an idea why this code isn't working.