Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

accumulateWeighted code problem

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.

click to hide/show revision 2
retagged

updated 2015-01-31 11:06:55 -0600

berak gravatar image

accumulateWeighted code problem

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.

accumulateWeighted code problem

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.

If i do this:

import cv2
import numpy as np


#cv2.waitKey(10000) 

c = cv2.VideoCapture(0) #---------------a
_,f = c.read()#-------------------------a


cv2.waitKey(100) 




avg1 = np.float32(f)
avg2 = np.float32(f)


while(1):
#while(c.isOpened):


    _,f = c.read()#----------------------a


    cv2.waitKey(100) 

    if _==True: 


      cv2.imshow('f',f)

      cv2.accumulateWeighted(f,avg1, 0.1)
      cv2.accumulateWeighted(f,avg2, 0.01)

      res1 = cv2.convertScaleAbs(avg1)
      res2 = cv2.convertScaleAbs(avg2)


      #cv2.imshow('avg1test',avg1)
      #print type(avg1) #<type 'numpy.float32'>
      #print (avg1)

      cv2.imshow('avg1',res1)
      cv2.imshow('avg2',res2)


    k = cv2.waitKey(10)

    if k == 27:
        break

cv2.destroyAllWindows()
c.release()

I get three black windows popup but no errors. Does theis mean f is empty?

accumulateWeighted code problem

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.

If i do this:

import cv2
import numpy as np


#cv2.waitKey(10000) 

c = cv2.VideoCapture(0) #---------------a
_,f x,f = c.read()#-------------------------a


cv2.waitKey(100) 




avg1 = np.float32(f)
avg2 = np.float32(f)


while(1):
#while(c.isOpened):


    _,f x,f = c.read()#----------------------a


    cv2.waitKey(100) 

    if _==True: 


      cv2.imshow('f',f)

      cv2.accumulateWeighted(f,avg1, 0.1)
      cv2.accumulateWeighted(f,avg2, 0.01)

      res1 = cv2.convertScaleAbs(avg1)
      res2 = cv2.convertScaleAbs(avg2)


      #cv2.imshow('avg1test',avg1)
      #print type(avg1) #<type 'numpy.float32'>
      #print (avg1)

      cv2.imshow('avg1',res1)
      cv2.imshow('avg2',res2)


    k = cv2.waitKey(10)

    if k == 27:
        break

cv2.destroyAllWindows()
c.release()

I get three black windows popup but no errors. Does theis the mean f is empty?

accumulateWeighted code problem

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.

If i do this:

import cv2
import numpy as np


#cv2.waitKey(10000) 

c = cv2.VideoCapture(0) #---------------a
x,f = c.read()#-------------------------a


cv2.waitKey(100) 




avg1 = np.float32(f)
avg2 = np.float32(f)


while(1):
#while(c.isOpened):
#while(1):
while(c.isOpened):


    x,f = c.read()#----------------------a


    cv2.waitKey(100) 

    if _==True: x==True: 


      cv2.imshow('f',f)

      cv2.accumulateWeighted(f,avg1, 0.1)
      cv2.accumulateWeighted(f,avg2, 0.01)

      res1 = cv2.convertScaleAbs(avg1)
      res2 = cv2.convertScaleAbs(avg2)


      #cv2.imshow('avg1test',avg1)
      #print type(avg1) #<type 'numpy.float32'>
      #print (avg1)

      cv2.imshow('avg1',res1)
      cv2.imshow('avg2',res2)


    k = cv2.waitKey(10)

    if k == 27:
        break

cv2.destroyAllWindows()
c.release()

I get three black windows popup but no errors. Does the mean f is empty?

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 a beginner with open CV and am struggling to understand the below code:stuck now

Any pointers would be welcomed :)

import cv2
import numpy as np

c = cv2.VideoCapture(0)
_,f = c.read()

#print ("cCCC")

#cv2.waitKey(10000) 
c=cv2.VideoCapture(0) #---------------a



 #cv2.waitKey(100) 
#x,f=c.read()#-------------------------a
#while(1):
#avg1=np.float64(f)
#avg2=np.float64(f)

 # 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)
#cv2.waitKey(200) 

while(1):
#while(c.isOpened):

    x,f=c.read()
    avg1=np.float32(f)
    avg2=np.float32(f)
   # cv2.waitKey(200) 


    #avg1=np.float64(f)
    #avg2=np.float64(f)

    #print (avg1)
    #print (avg2)
    #cv2.waitKey(100)   

    if k == 27:
x==True: 
         #print ("x is true")
         #x,f=c.read()#----------------------a


         cv2.accumulateWeighted(f, avg1, 1)
         cv2.accumulateWeighted(f, avg2, 1)
     # cv2.waitKey(100) 

         res1=cv2.convertScaleAbs(avg1)
         res2=cv2.convertScaleAbs(avg2)
     # cv2.waitKey(10) 



      #cv2.imshow('avg1test',avg1)
      #print type(avg1) #<type 'numpy.float32'>


         cv2.imshow('avg1', res1)
         cv2.imshow('avg2', res2)

         cv2.imshow('f',f)

    k=cv2.waitKey(20)

    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.

If i do this:

import cv2
import numpy as np


#cv2.waitKey(10000) 

c = cv2.VideoCapture(0) #---------------a
x,f = c.read()#-------------------------a


cv2.waitKey(100) 




avg1 = np.float32(f)
avg2 = np.float32(f)


#while(1):
while(c.isOpened):


    x,f = c.read()#----------------------a


    cv2.waitKey(100) 

    if x==True: 


      cv2.imshow('f',f)

      cv2.accumulateWeighted(f,avg1, 0.1)
      cv2.accumulateWeighted(f,avg2, 0.01)

      res1 = cv2.convertScaleAbs(avg1)
      res2 = cv2.convertScaleAbs(avg2)


      #cv2.imshow('avg1test',avg1)
      #print type(avg1) #<type 'numpy.float32'>
      #print (avg1)

      cv2.imshow('avg1',res1)
      cv2.imshow('avg2',res2)


    k = cv2.waitKey(10)

    if k == 27:
        break

cv2.destroyAllWindows()
c.release()

I get three black windows popup but no errors. Does the mean f is empty?

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

#print ("cCCC")

#cv2.waitKey(10000) 
c=cv2.VideoCapture(0) #---------------a



 #cv2.waitKey(100) 
#x,f=c.read()#-------------------------a
#while(1):
#avg1=np.float64(f)
#avg2=np.float64(f)

 # avg1 = np.float64(f)
 # avg2 = np.float64(f)
#cv2.waitKey(200) 

while(1):
#while(c.isOpened):

    x,f=c.read()
    avg1=np.float32(f)
    avg2=np.float32(f)
   # cv2.waitKey(200) 


    #avg1=np.float64(f)
    #avg2=np.float64(f)

    #print (avg1)
    #print (avg2)
    #cv2.waitKey(100) avg2=np.float32(f)   

    if x==True: 
         #print ("x is true")
         #x,f=c.read()#----------------------a
#x,f=c.read()


         cv2.accumulateWeighted(f, avg1, 1)
         cv2.accumulateWeighted(f, avg2, 1)
     # cv2.waitKey(100) 

         res1=cv2.convertScaleAbs(avg1)
         res2=cv2.convertScaleAbs(avg2)
     # cv2.waitKey(10) 



      #cv2.imshow('avg1test',avg1)
      #print type(avg1) #<type 'numpy.float32'>


         cv2.imshow('avg1', res1)
         cv2.imshow('avg2', res2)

         cv2.imshow('f',f)

    k=cv2.waitKey(20)

    if k==27:
        break
 
cv2.destroyAllWindows()
c.release()