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?