国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

《OpenCV》Part10 OpenCV3.1.0 openCV讀取攝像頭并保存為.avi視頻

2019-11-14 09:33:26
字體:
來源:轉載
供稿:網友

《OpenCV》Part10 OpenCV3.1.0 openCV讀取攝像頭并保存為.avi視頻

#include <opencv2/core.hpp>#include <opencv2/opencv.hpp>#include <opencv2/highgui.hpp>#include <opencv2/videoio.hpp>//for camera#include <opencv2/video.hpp>#include <opencv2/imgPRoc//imgproc.hpp>#include <opencv2/ml/ml.hpp>#include "opencv2/imgproc/imgproc.hpp"#include "opencv2/ml/ml.hpp"#include <time.h>#include <ctime>#include <iostream>#include <string>using namespace std;using namespace cv;int main(int argc, char ** argv){	char filename[1024];	if (argc == 1)		sprintf(filename, "%s", "camera.avi");	if (argc == 2)		sprintf(filename, "%s", "123");	VideoCapture capture;	capture.open(0);	if (!capture.isOpened())	{		cout << "Could not initialize capturing.../n" << endl;		return -1;	}	//按時間格式命名	time_t now = time(NULL);////獲取1970.1.1至當前秒數time_t	struct tm * timeinfo = localtime(&now);	//創建TimeDate,并轉化為當地時間,	//struct tm * timeinfo = gmtime ( &currTime );	 //創建TimeDate,并轉化為GM時間,	char path[60];	strftime(path, 60, "%Y_%m_%d_%H_%M_%S", timeinfo);	char strPath[100];	sprintf(strPath, "%s.avi", path);//將創建文件的命令存入cmdchar中	//保存為avi格式視頻	Mat frame;	VideoWriter writer;	writer.open(strPath, CV_FOURCC('X', 'V', 'I', 'D'), 25, Size(640, 480), true);//Size(640, 480)//Size(frame.rows, frame.cols)//"cam.avi"	int n = 1;	while (true)	{		capture >> frame;		char* cstr = new char[120];				sprintf(cstr, "%s%d%s", "D://OpenCVWorkSpace//saveCamAsVideo//saveCamAsVideo//savedPic//Pic", n++, ".jpg");		imwrite(cstr, frame);		imshow("Video_Capture", frame);		if (frame.empty())		{			break;		}		writer << frame;		waitKey(3);	}	//return 0;}該程序功能為讀取攝像頭后將視頻存儲為avi格式。

其中的waitKey(3)如果沒有的話程序容易未響應。CV_FOURCC('P','I','M','1') = MPEG-1 codecCV_FOURCC('M','J','P','G') = motion-jpeg codecCV_FOURCC('M', 'P', '4', '2') = MPEG-4.2 codecCV_FOURCC('D', 'I', 'V', '3') = MPEG-4.3 codecCV_FOURCC('D', 'I', 'V', 'X') = MPEG-4 codecCV_FOURCC('U', '2', '6', '3') = H263 codecCV_FOURCC('I', '2', '6', '3') = H263I codecCV_FOURCC('F', 'L', 'V', '1') = FLV1 codec


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 绍兴县| 泾川县| 道真| 绵竹市| 读书| 景东| 恩平市| 彩票| 阿巴嘎旗| 广州市| 衡南县| 南昌市| 福安市| 安泽县| 潼关县| 团风县| 永吉县| 名山县| 新郑市| 苗栗县| 砀山县| 甘孜| 明星| 平原县| 金山区| 洪湖市| 巧家县| 西乌| 富蕴县| 五原县| 望城县| 桂东县| 安化县| 海伦市| 宝鸡市| 池州市| 咸阳市| 高雄县| 沈阳市| 南城县| 大方县|