I'm coming across the problem where subtracting two subsequent webcam frames gives a completely black image - I would have thought that it would leave a non blank image when there is movement in the video stream, but I always get a blank image. I think the problem could be that the two frames are identical, but I think this is highly unlikely because the camera is (at a guess, v4l2 doesn't support FPS property) at 20 fps tops. Here is the code I'm using:
#include <iostream>
#include <opencv2/opencv.hpp>
int main() {
cv::VideoCapture input(0);
cv::namedWindow("last_frame", cv::WINDOW_AUTOSIZE);
cv::namedWindow("current_frame", cv::WINDOW_AUTOSIZE);
cv::namedWindow("difference", cv::WINDOW_AUTOSIZE);
for(;;) {
cv::Mat last_frame;
input >> last_frame;
cv::Mat current_frame;
input >> current_frame;
cv::Mat difference;
cv::subtract(current_frame, last_frame, difference);
cv::imshow("last_frame", last_frame);
cv::imshow("current_frame", current_frame);
cv::imshow("difference", difference);
if(cv::waitKey(10) >= 0) break;
}
return 0;
}