1 | initial version |
Might be not the source of your problem and you might be already doing this, but you need to initialize the windows where you want to display the images in advance:
VideoCapture capture("768x576.avi");
/* Initialize the windows */
namedWindow("first_frame");
namedwindow("current_frame");
Mat first_frame;
Mat current_frame;
//Mat diff;
capture>>first_frame;
while( (char)keyboard != 'q' && (char)keyboard != 27 ){
capture >> current_frame;
//cv::absdiff(current_frame, first_frame, diff);
imshow("first_frame", first_frame);
imshow("current_frame", current_frame);
keyboard = waitKey( 30 );
}
2 | No.2 Revision |
After reading your comment the "inspiration" came to me... I think that your problem is that first_frame and current_frame are pointing to the same data (for better performance the opperation capture>>first_frame
does not copy the data, only returns a pointer. And the data pointed by that pointer will be overwritten with the brand new frame instead of allocating new memory)
what you need to do is to copy first_frame
to a local variable. Like this, for example:
Mat tmp;
Mat first_frame;
capture >> tmp;
first_frame = tmp.clone();
Might be not the source of your problem and you might be already doing this, but you need to initialize the windows where you want to display the images in advance:
VideoCapture capture("768x576.avi");
/* Initialize the windows */
namedWindow("first_frame");
namedwindow("current_frame");
Mat first_frame;
Mat current_frame;
//Mat diff;
capture>>first_frame;
while( (char)keyboard != 'q' && (char)keyboard != 27 ){
capture >> current_frame;
//cv::absdiff(current_frame, first_frame, diff);
imshow("first_frame", first_frame);
imshow("current_frame", current_frame);
keyboard = waitKey( 30 );
}
3 | No.3 Revision |
After reading your comment the "inspiration" came to me... I think that your problem is that first_frame and current_frame are pointing to the same data (for better performance the opperation capture>>first_frame
does not copy the data, only returns a pointer. And the data pointed by that pointer will be overwritten with the brand new frame instead of allocating new memory)
what you need to do is to copy first_frame
to a local variable. Like this, for example:
VideoCapture capture("768x576.avi");
/* Initialize the windows */
namedWindow("first_frame");
namedwindow("current_frame");
Mat tmp;
Mat first_frame;
capture >> tmp;
Mat current_frame;
//Mat diff;
capture>>tmp;
first_frame = tmp.clone();
while( (char)keyboard != 'q' && (char)keyboard != 27 ){
capture >> current_frame;
//cv::absdiff(current_frame, first_frame, diff);
imshow("first_frame", first_frame);
imshow("current_frame", current_frame);
keyboard = waitKey( 30 );
}
Might be not the source of your problem and you might be already doing this, but you need to initialize the windows where you want to display the images in advance:
VideoCapture capture("768x576.avi");
/* Initialize the windows */
namedWindow("first_frame");
namedwindow("current_frame");
Mat first_frame;
Mat current_frame;
//Mat diff;
capture>>first_frame;
while( (char)keyboard != 'q' && (char)keyboard != 27 ){
capture >> current_frame;
//cv::absdiff(current_frame, first_frame, diff);
imshow("first_frame", first_frame);
imshow("current_frame", current_frame);
keyboard = waitKey( 30 );
}