Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8258781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:39:50+00:00 2026-06-08T02:39:50+00:00

I am writing a small script (in Python) that generates and updates a running

  • 0

I am writing a small script (in Python) that generates and updates a running average of a camera feed. When I call cv.RunningAvg it returns:

cv2.error: func != 0

Where am I stumbling in implementing cv.RunningAvg? Script follows:

import cv

feed = cv.CaptureFromCAM(0)
frame = cv.QueryFrame(feed)
moving_average = cv.QueryFrame(feed)
cv.NamedWindow('live', cv.CV_WINDOW_AUTOSIZE)

def loop():
    frame = cv.QueryFrame(feed)
    cv.ShowImage('live', frame)
    c = cv.WaitKey(10)

    cv.RunningAvg(frame, moving_average, 0.020, None)

while True:
    loop()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T02:39:52+00:00Added an answer on June 8, 2026 at 2:39 am

    I am not sure about the error, but check out the documentation for cv.RunningAvg

    It says destination should be 32 or 64-bit floating point.

    So I made a small correction in your code and it works. I created a 32-bit floating point image to store running average values, then another 8 bit image so that I can show running average image :

    import cv2.cv as cv
    
    feed = cv.CaptureFromCAM(0)
    frame = cv.QueryFrame(feed)
    moving_average = cv.CreateImage(cv.GetSize(frame),32,3) # image to store running avg
    avg_show = cv.CreateImage(cv.GetSize(frame),8,3) # image to show running avg
    
    def loop():
        frame = cv.QueryFrame(feed)
        c = cv.WaitKey(10)
    
        cv.RunningAvg(frame, moving_average, 0.1, None)
        cv.ConvertScaleAbs(moving_average,avg_show) # converting back to 8-bit to show
    
        cv.ShowImage('live', frame)
        cv.ShowImage('avg',avg_show)
    
    while True:
        loop()
    
    cv.DestroyAllWindows()
    

    Now see the result :

    At a particular instant, I saved a frame and its corresponding running average frame.

    Original frame :

    enter image description here

    You can see the obstacle (my hand) blocks the objects in behind.

    Now running average frame :

    enter image description here

    It almost removed my hand and shows objects in background.

    That is how it is a good tool for background subtraction.

    One more example from a typical traffic video :

    enter image description here enter image description here

    You can see more details and samples here : http://opencvpython.blogspot.com/2012/07/background-extraction-using-running.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a small script for watchr that runs my PHP unit tests.
I'm writing a small C application that launchs a Matlab script (.m file). I
So, I'm writing a chunked file transfer script that is intended to copy files--small
I'm currently writing a small python app that embeds cherrypy and django using py2app.
So I'm writing a python script that is updating values in a mysql table.
I currently have a small Python script that I'm using to spawn multiple executables,
I'm writing a small Python script which requires resolving hosts IPs or domain names.
I am in the process of writing a small(er) Python script to automate a
I'm writing a small script that will match a shoe size from a shoe
i'm writing a small script that parse an rss using xmllint. Now i fetch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.