环境: opencv使用的是2010下编译的库,版本号243
硬件: usb免驱摄像头或者笔记本自带的摄像头;
1:首先设置库和头文件
2:设置好后,就可以进行简单的读取操作了.
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>
int main()
{
cv::VideoCapture cap;
//cv::VideoCapture cap("bike.avi"); 可直接读取文件
cv::Mat frame;
if(!cap.open())
return false;
for(int i=;i<;i++)
cap>>frame;
int width = cap.get(CV_CAP_PROP_FRAME_WIDTH );//获取默认宽高
int height = cap.get(CV_CAP_PROP_FRAME_HEIGHT );
std::cout<< "width:" << width << std::endl;
std::cout<< "height:" << height << std::endl;
cap.set(CV_CAP_PROP_FRAME_WIDTH,);//设置宽高及其他参数,具体可参考set的说明
cap.set(CV_CAP_PROP_FRAME_HEIGHT,);
IplImage pFrame;
bool stop = false;
while(!stop)
{
//cap>>frame;
cv::waitKey();//帧率控制
cap.read(frame);
pFrame = frame;
cvShowImage("video", &pFrame);//显示
saveBmpImage(pFrame);
if(cv::waitKey() >=)
stop = true;
}
//memcpy(rgbData, pFrame.imageData, pFrame.imageSize);
//rgbSize = pFrame.imageSize;
//循环读取
/*double fps;
char string[50]; // 用于存放帧率的字符串
double t = 0;
IplImage pFrame;
bool stop = false;
while(!stop)
{
//cap>>frame;
t = (double)cv::getTickCount();
cv::waitKey(25);//帧率控制
cap.read(frame);
pFrame = frame;
cvShowImage("video", &pFrame);
saveBmpImage(pFrame);
if(cv::waitKey(25) >=0)
stop = true;
}*/
}