时间:2010-07-24 14:58:55

标签: c opencv webcam

4 个答案:

答案 0 :(得分:2)

答案 1 :(得分:1)

我在尝试阅读LearningOpenCV一书的例子2-9时遇到了同样的问题。

我在VM中的Win7-Prof上使用VS13 Ultimate进行编码;来自Host-PC的WebCam是BisonCam,NB Pro;我尝试了cvCreateCameraCapture的不同变体,它总是返回NULL;我甚至成功地使用VLC-Player测试了WebCam,因为我不确定它是否因VM而起作用。

我的解决方案是使用类 VideoCapture ,它将捕获的图像存储在类 Mat 中,因此转换为结构IplImage是必要的。 (找到here

我的解决方案是:

#include "opencv\cv.h"
#include "opencv\highgui.h"
#include <iostream>
#include <string.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace cv;
...
void Run_with_WebCAM(){
   std::string WindowName = "WebCam_Example";
   VideoCapture webcam;
   webcam.open(0);
   Mat m_frame;
   if (webcam.isOpened()){
       // create a window
       cvNamedWindow(WindowName.c_str(), CV_WINDOW_AUTOSIZE);
       IplImage* frame;
       while (1) {
           // update frame and display it:
           webcam >> m_frame;

           // convert captured frame to a IplImage
           frame = new IplImage(m_frame);
           if (!frame) break;
           cvShowImage(WindowName.c_str(), frame);

           // Do some processing...

           delete frame;

           // some abort condition...
       }
       // release memory and destroy all windows
       cvDestroyWindow(WindowName.c_str());
       ...
    }
 }

答案 2 :(得分:0)

答案 3 :(得分:0)