Detect Slow Gradual Change in Background with Live Video and Python 3?

asked 2018-05-11 20:37:59 -0600

masterenol gravatar image

Hello everyone. How can I go about detecting slow gradual change in a live video? I am experienced with writing Python OpenCV code for motion detection, but not for slow gradual change in live video. I would like to write a Python OpenCV script to detect smoke build-up in a home.

Here is what I think I need help with:

  1. Create and initialize a bool variable "frameChange = False"
  2. Recognize and remember the initial frames of the live video from cv2.VideoCapture().
  3. Read the current frame, and compare to the initial frames.
  4. If the initial frame and the current frame differ by 25%, then frameChange = True.

I'm thinking I can get the average pixel value for the initial frame, and compare that value to the average pixel value of the current frame. If there are any other ideas, I'd be very grateful.

edit retag flag offensive close merge delete

Comments

Are you familiar with the absdiff function?

sjhalayka gravatar imagesjhalayka ( 2018-05-11 20:42:06 -0600 )edit

Hello sjhalayka. So I'm thinking I can do something like: absdiff(initialFrame, currentFrame) . Is this correct?

masterenol gravatar imagemasterenol ( 2018-05-11 21:04:08 -0600 )edit

Actually, absdiff takes three parameters in C++:

absdiff(initialFrame, currentFrame, out);

For Python, it's

out = cv2.absdiff(initialFrame, currentFrame)
sjhalayka gravatar imagesjhalayka ( 2018-05-12 06:29:35 -0600 )edit