2

I have a project where I need to detect motion in a video stream. When motion is detected further processing is done. There is no need for detection of an area where the motion was detected or more detailed information. I only need to measure the percentage of changed pixels between two images or something similar as a trigger for further processing.

My idea was to take the absolute difference of the two images, threshold it and count pixels. I'm using cv::absdiff, cv::threshold and cv::countNonZero. This calculation takes about 10 ms for a full HD image. At 30 fps this adds up to 10 * 30 = 300 ms on a single core.

This doesn't yet include grayscale conversion for the image which takes roughly 2-3 times compared to the difference image calculation. So I can process about 10 fps in full HD on a single core.

I'm now looking for a way to speed up grayscale conversion/motion detection in a significant way. What would be the fastest way of motion detection in an RGB video stream in terms of computation power?

2 Answers 2

1

If you are completely constrained to a single core, this doesn't apply. However, if you have a good video card, you can use gpu:: or ocl:: functions. By using these you can speed up the operation 3-30x! I know for a fact that gpu::threshold is much faster than cpu version. I can thresh a 1080p picture in 0.001 seconds on an geForce gtx660. Further examples of my GPU times on the same size image: masking - .002, LBP classifying - .053, morphological .002.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm not constrained to a single core. Calculation relative to a single CPU serves as an indication for myself how many instances I can run in parallel. gpu:: only supports nvidia devices. I'm stuck with some intel gpu so only ocl:: is available to me. How much time will it take to copy my image data to gpu memory?
1
  1. Resize the image down before processing
  2. Apply a blur before testing as this decreases noise.

opencv has methods for comparing mats together, e.g. cv::compare which has overloaded the relative operators.

Also, there's a huge difference in terms of speed between the debug opencv libraries and the release libraries, to the point, before you fret about speeds, do a release compile using the release libraries of opencv.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.