Opencv调用摄像头,显示摄像头图像
2016-10-11 20:23
471 查看
#include<opencv2\opencv.hpp>
#include<opencv2\core.hpp>
#include<iostream>
#include <cstdio>
#include <string>
#include <sstream>
using namespace cv;
using namespace std;
const char*keys = {
"{help h usage?||print this message}"
"{@video||Video file,if not defined try to use webcamera}"
};
int main(int, char**)
{
Mat frame;
//--- INITIALIZE VIDEOCAPTURE
VideoCapture cap;
// open the default camera using default API
cap.open(0);
// OR advance usage: select any API backend
int deviceID = 0; // 0 = open default camera
int apiID = cv::CAP_ANY; // 0 = autodetect default API
// open selected camera using selected API
cap.open(deviceID + apiID);
// check if we succeeded
if (!cap.isOpened()) {
cerr << "ERROR! Unable to open camera\n";
return -1;
}
//--- GRAB AND WRITE LOOP
cout << "Start grabbing" << endl
<< "Press any key to terminate" << endl;
for (;;)
{
// wait for a new frame from camera and store it into 'frame'
cap.read(frame);
// check if we succeeded
if (frame.empty()) {
cerr << "ERROR! blank frame grabbed\n";
break;
}
// show live and wait for a key with timeout long enough to show images
imshow("Live", frame);
if (waitKey(5) >= 0)
break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
#include<opencv2\core.hpp>
#include<iostream>
#include <cstdio>
#include <string>
#include <sstream>
using namespace cv;
using namespace std;
const char*keys = {
"{help h usage?||print this message}"
"{@video||Video file,if not defined try to use webcamera}"
};
int main(int, char**)
{
Mat frame;
//--- INITIALIZE VIDEOCAPTURE
VideoCapture cap;
// open the default camera using default API
cap.open(0);
// OR advance usage: select any API backend
int deviceID = 0; // 0 = open default camera
int apiID = cv::CAP_ANY; // 0 = autodetect default API
// open selected camera using selected API
cap.open(deviceID + apiID);
// check if we succeeded
if (!cap.isOpened()) {
cerr << "ERROR! Unable to open camera\n";
return -1;
}
//--- GRAB AND WRITE LOOP
cout << "Start grabbing" << endl
<< "Press any key to terminate" << endl;
for (;;)
{
// wait for a new frame from camera and store it into 'frame'
cap.read(frame);
// check if we succeeded
if (frame.empty()) {
cerr << "ERROR! blank frame grabbed\n";
break;
}
// show live and wait for a key with timeout long enough to show images
imshow("Live", frame);
if (waitKey(5) >= 0)
break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
相关文章推荐
- asp.net调用opencv类库,实现图像处理显示
- opencv调用是视频图像并且显示
- OpenCV-009:识别摄像头图像中的指定颜色并显示
- OpenCV 学习记录2 图像简单处理及调用摄像头
- OpenCV显示摄像头图像保存成bmp文件
- MFC中使用OpenCV显示摄像头图像
- 关于opencv中imshow()函数在VS中调用不显示图像的问题
- OpenCV编程案例:实现一个双目摄像头图像显示的程序
- vs2008下opencv2.2的环境搭建及无法显示摄像头图像的bug解决
- opencv调用摄像头采集图像+配合canny边缘检测
- Opencv调用摄像头采集图像
- 《OpenCV》Part2 OpenCV3.1.0调用摄像头显示视频并拍照
- OpenCv打开摄像头,显示图像,保存视频
- 笔记:OpenCV 读取摄像头并显示图像的R、G、B三个通道的直方图
- opencv实现摄像头的实时图像采集与显示
- python调用摄像头显示图像的实例
- 在页面中嵌入Applet使用opencv调用摄像头,并显示实时摄像头内容
- opencv调用摄像头在mfc控件中显示黑屏问题的解决
- python调用摄像头显示图像
- 关于opencv摄像头图像显示 经常出现select timeout的问题