学OpenCV
================================================
简单的看下效果。
================================================
文件后缀和编码要对应。
帧率设置的很小,相当于慢放效果,但视频时间会被拉长。
================================================
1 #include <iostream> 2 3 #include <opencv2/opencv.hpp> 4 #include <opencv2/core/utils/logger.hpp> 5 6 7 void Test1() 8 { 9 cv::Mat frame; 10 cv::VideoCapture camera(0,cv::CAP_DSHOW); 11 if (camera.isOpened() == false) 12 { 13 std::cout << "open camera failed." << std::endl; 14 return; 15 } 16 17 camera >> frame; 18 if (frame.empty()) 19 { 20 std::cout << "no video on camera" << std::endl; 21 return; 22 } 23 24 bool bColor = frame.type() == CV_8UC3; 25 26 cv::VideoWriter writer(R"(C:\ProjectHome\test\LeanOpenCV\Test_SaveVideo\test1.avi)", 27 cv::VideoWriter::fourcc('M', 'J', 'P', 'G'), 28 60, 29 frame.size(), 30 bColor); 31 if (writer.isOpened() == false) 32 { 33 std::cout << "bad video writer" << std::endl; 34 return; 35 } 36 37 for (;;) 38 { 39 if (camera.read(frame) == false) 40 { 41 std::cout << "end of camera input" << std::endl; 42 break; 43 } 44 45 //writer << frame; 46 writer.write(frame); 47 48 cv::imshow("camera realtime", frame); 49 50 char c=cv::waitKey(1); 51 if (c == 27) 52 { 53 break; 54 } 55 } 56 57 camera.release(); 58 writer.release(); 59 } 60 61 int main() 62 { 63 cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_ERROR); 64 65 Test1(); 66 67 cv::waitKey(0); 68 69 return 0; 70 }
标签:视频,cout,frame,保存,camera,include,cv From: https://www.cnblogs.com/wlsandwho/p/18367331