#include <iostream> #include<opencv2/opencv.hpp> using namespace std; using namespace cv; Mat frame; bool save_flag = false; int main() { cv::VideoWriter videoWriter; //原文链接:https ://blog.csdn.net/bloke_come/article/details/79455703 VideoCapture cap(CV_CAP_DSHOW + 0); int w = static_cast<int>(cap.get(CV_CAP_PROP_FRAME_WIDTH)); int h = static_cast<int>(cap.get(CV_CAP_PROP_FRAME_HEIGHT)); cv::Size videoSize(w, h); //time_t t_start = time(0); //char video_name[64]; //strftime(video_name, sizeof(video_name), "%Y-%m-%d %H-%M-%S", localtime(&t_start)); //年-月-日 时-分-秒 //string temp_name = video_name; //String videoPath = "video"+ temp_name + ".mp4"; //videoWriter.open(videoPath, CV_FOURCC('D', 'I', 'V', 'X'), 25, videoSize); //if (!videoWriter.isOpened()) //{ // //MessageBoxA(NULL, "Save Failure", "Save", MB_OK); // cout << "Can't open video!" << endl; // return -1; //} cout << "Main Starting!" << endl; while (cap.isOpened()) { cap.read(frame);//从摄像头中读取当前这一帧 time_t t_t = time(0); char ch[64]; strftime(ch, sizeof(ch), "%Y/%m/%d %H:%M:%S", localtime(&t_t)); //年-月-日 时-分-秒 cv::putText(frame, ch, cv::Point(10, 25), cv::FONT_HERSHEY_SCRIPT_COMPLEX, 1.0, cv::Scalar(0, 255, 255), 2, 8, 0); cv::imshow("Video", frame); int k_value = waitKey(10); if (k_value == 27) { break; } else if (k_value == 's') { if (!save_flag) { time_t t_start = time(0); char video_name[64]; strftime(video_name, sizeof(video_name), "%Y-%m-%d %H-%M-%S", localtime(&t_start)); //年-月-日 时-分-秒 string temp_name = video_name; String videoPath = "video" + temp_name + ".mp4"; videoWriter.open(videoPath, CV_FOURCC('D', 'I', 'V', 'X'), 25, videoSize); if (!videoWriter.isOpened()) { //MessageBoxA(NULL, "Save Failure", "Save", MB_OK); cout << "Can't open video!" << endl; return -1; } save_flag = true; cout << "Start recording to " << videoPath << endl; } else cout << "Video is recording, press 'e' key to end recording!" << endl; } else if (k_value == 'e') { if (save_flag) { cout << "End recording!" << endl; videoWriter.release(); /*写入文件关闭*/ save_flag = false; } else cout << "Video recording is not starting yet!" << endl; } else if(k_value == 'q') { cout << "Key Value: "<<waitKey(1) << endl; } if(save_flag) videoWriter.write(frame); } cap.release(); /*摄像机关闭*/ //videoWriter.release(); /*写入文件关闭*/ cv::destroyWindow("Video"); /*显示窗口销毁*/ return 0; }
本网页所有视频内容由 imoviebox边看边下-网页视频下载, iurlBox网页地址收藏管理器 下载并得到。
ImovieBox网页视频下载器 下载地址: ImovieBox网页视频下载器-最新版本下载
本文章由: imapbox邮箱云存储,邮箱网盘,ImageBox 图片批量下载器,网页图片批量下载专家,网页图片批量下载器,获取到文章图片,imoviebox网页视频批量下载器,下载视频内容,为您提供.
阅读和此文章类似的: 全球云计算