关于opencv采集usb摄像头,采集一帧效率低的解决办法
#include "opencv2/opencv.hpp"#include "opencv2/highgui/highgui_c.h"#include <Windows.h>#include <time.h>#include <stdio.h>using namespace cv;const char *g_szTitle = "Camera"...
·
#include "opencv2/opencv.hpp"
#include "opencv2/highgui/highgui_c.h"
#include <Windows.h>
#include <time.h>
#include <stdio.h>
using namespace cv;
const char *g_szTitle = "Camera";
int _tmain(int argc, _TCHAR* argv[])
{
/*opencv 2.4.1*/
VideoCapture cap2(CV_CAP_DSHOW+1);
/*
用dshow采集USS摄像头的时候,CV_CAP_PROP_FPS一定要先设置,否则后设置会导致采取(1280*720)一帧 时间大概在80ms
*/
cap2.set(CV_CAP_PROP_FPS, 30);
cap2.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M','J','P','G'));
cap2.set(CV_CAP_PROP_FRAME_WIDTH, 1280);
cap2.set(CV_CAP_PROP_FRAME_HEIGHT, 720);
//cap2.set(CV_CAP_PROP_FPS, 30); 后设置帧率貌似不起作用啊!! 晕菜
if (!cap2.isOpened())
{
return -1;
}
for (;;)
{
clock_t stime = clock();
Mat imgRGB2;
cap2 >> imgRGB2;
clock_t endtime = clock();
double dtimetmp =(double) (endtime - stime);
printf("cap——time #%Lf's.\n", dtimetmp);
imshow(g_szTitle, imgRGB2);
if (cvWaitKey(30) == 'q')
{
break;
}
}
cvDestroyWindow(g_szTitle);
return 0;
}
更多推荐
所有评论(0)