accumulateWeighted code problem
The following code is not doing what is expected. If i copy the original code from here it doesnt work at all.
In this state I get three windows from my webcam showing me, but when i wave my hand it doesn't disappear, as expected. I've moved things round to get something working, but I'm stuck now
Any pointers would be welcomed :)
import cv2
import numpy as np
c=cv2.VideoCapture(0)
while(1):
x,f=c.read()
avg1=np.float32(f)
avg2=np.float32(f)
if x==True:
#print ("x is true")
#x,f=c.read()
cv2.accumulateWeighted(f, avg1, 1)
cv2.accumulateWeighted(f, avg2, 1)
res1=cv2.convertScaleAbs(avg1)
res2=cv2.convertScaleAbs(avg2)
cv2.imshow('avg1', res1)
cv2.imshow('avg2', res2)
cv2.imshow('f',f)
k=cv2.waitKey(20)
if k==27:
break
cv2.destroyAllWindows()
c.release()
your code works fine here.
can it be , that you're using an older webcam, that needs a 'warmup, and delivers empty frames in the meantime ? (so avg1 would be empty, and f and avg1 do not have the same size.)
also, note this pythonic antipattern: throwing away important result values:
you should check '_' for True, not ignore it ! (or throw it away)
check c.isOpened() as well
same result for last 2 comments.
at least you know now, that the capture is your problem, not accumulateWeighted
I took the spaces out of the = and it appears to be working eg a = b to a=b but each screen is the same, and not as expected.
aww, cmon, rather apply occam's razor, than the voodoo above.
as long as your imshow() stays black, still a capture prob.
My three windows are not black, they show me sat in front of the laptop. When I wave at myself, I'm expecting the different alpha values, currently set to one, to make my moving hand disappear (depending on the differential alpha values I set). I get the same result if I set the alpha values to 0.1 and 0.01. Could it still be a capture problem if I can see three moving video feeds of my ugly mug?
but if I set them to 0.1 and 0.01, to make the forground disapear (depending on the alpha values i set)