http://www.opencv.org.cn/forum.php?mod=viewthread&tid=33957
视频地址
链接: http://pan.baidu.com/s/1kV5xKDh 密码: abd2 //pan,baidu.com/文章附件 test.avi
本帖最后由 OpenCV_Westin 于 2015-1-18 14:47 编辑 代码: #include <opencv2corecore.hpp> #include <opencv2highguihighgui.hpp> #include <opencv2imgprocimgproc.hpp> #include <iostream> using namespace std; using namespace cv; int main(int argc, char** argv) { cv::VideoCapture cap("test.avi"); if(!cap.isOpened()) { cout << "Failed!" << endl; return -1; } Mat result,mask; cv::namedWindow("Result",1); cv::namedWindow("Frame",1); int i = 0; for(;;) { Mat frame; cap >> frame; if(!frame.data) { cout << "Over!" << endl; break; } if(i <= 30) //看视频,自己调试确定这个值,二十几帧之后左上角那个小图才出来,所以选了30 { if(i == 30) { mask = frame; cv::cvtColor(mask,mask,CV_BGR2GRAY); imshow("Frame",frame); imshow("Result",mask); //waitKey(); } } else { cv::cvtColor(frame,result,CV_BGR2GRAY); cv::bitwise_and(result,mask,mask); imshow("Frame",frame); imshow("Result",mask); //waitKey(); if(cv::waitKey(33) >= 0) break; } i++; } waitKey(); return 0; } |