================================================
啊
1 #include <iostream> 2 #include <opencv2/opencv.hpp> 3 4 using namespace std; 5 using namespace cv; 6 7 8 int Test1() 9 { 10 Mat img; 11 VideoCapture video(0); 12 if (!video.isOpened()) 13 { 14 cout << "Video Camera,Open Failed! " << endl; 15 16 return 1; 17 } 18 19 video >> img; 20 if (img.empty()) 21 { 22 cout << "No Image!" << endl; 23 24 return 2; 25 } 26 27 bool isColor=img.type() == CV_8UC3; 28 29 VideoWriter writer; 30 writer.open("live.avi",VideoWriter::fourcc('M', 'J', 'P', 'G'),25.0,img.size(),isColor); 31 if (!writer.isOpened()) 32 { 33 cout << "Illegal input" << endl; 34 35 return 3; 36 } 37 38 while (1) 39 { 40 if (!video.read(img)) 41 { 42 cout << "Break or Done"; 43 break; 44 } 45 46 writer.write(img); 47 imshow("Live", img); 48 49 if (waitKey(50)==27) 50 { 51 break; 52 } 53 } 54 55 } 56 57 int main() 58 { 59 Test1(); 60 61 return 0; 62 }
啊