[英]Accessing Webcam using OpenCV - C++
#include <opencv2/core/core.hpp>
#include<opencv2/objdetect/objdetect.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include<iostream>
using namespace cv;
void load(CascadeClassifier &a)
{
try{
a.load("F:/Projects/workspace/dispimage/src/lbpcascade_frontalface.xml");
}
catch(cv::Exception &e) {
std::cout<<"Cannot load the qwespecified file";
}
if ( a.empty() ){
std::cout << "ERROR: Couldn't load Face Detector (";
std::cout<<")!";
exit(1);
}
}
void open(VideoCapture &camera)
{
camera.open(0);
if(!camera.isOpened())
{
std::cout<<"Camera did not open";
exit(1);
}
camera.set(CV_CAP_PROP_FRAME_WIDTH, 640);
camera.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
}
int main() {
CascadeClassifier a;
VideoCapture camera;
namedWindow("CamerOP",CV_WINDOW_AUTOSIZE);
bool b =0;
load(a);
open(camera);
while (true)
{
// Grab the next camera frame.
Mat cframe;
b=camera.read(cframe);
if (!b)
{
std::cerr << "ERROR: Couldn't grab a camera frame." <<std::endl;
exit(1);
}
imshow("CamerOP",cframe);
}
std::cout<<"Haillo";
return 1;
}
I am trying to access my webcam using opencv. 我正在尝试使用opencv访问我的网络摄像头。 The imagewindow i created opens up and resizes itself to 640*480, then it just goes not responding with the content area being all gray.
我创建的图像窗口打开,并将其大小调整为640 * 480,然后内容区域全是灰色,则它没有响应。 I am not able to figure it out as i have seen several howtos on this and more or less every place has done the same thing.
我无法弄清楚,因为我已经看到了一些方法,并且每个地方或多或少都做了同样的事情。
Heres a Screenshot - 继承人截图-
在循环内添加cv::waitKey(30)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.