OpenCV 2.4.3摄像头捕获无法在Ubuntu 12.04上运行

时间:2012-11-28 05:24:46

标签: c++ opencv ubuntu-12.04 cameracapturetask

我试图在Ubuntu 12.04 LTS上使用openCV 2.4.3执行以下程序。 但我得到“相机未初始化为输出”任何人都可以帮助我。

这是代码:

include <iostream>
include "opencv2/imgproc/imgproc.hpp"
include "opencv2/highgui/highgui.hpp"

using namespace cv;
using namespace std;

int main()
{
  VideoCapture cap(1);

  if (!cap.isOpened())
    {
      cout <<"Failed to initialize camera\n";
      return 1;
    }

  namedWindow("CameraCapture");

  Mat frame;
  while (1)
    {
      cap>> frame;
      imshow("cameraCapture",frame);
      if (waitKey(30)>0)break;
    }
  destroyAllWindows();

  return 0;

 }

请帮助我!

谢谢, Kushal

2 个答案:

答案 0 :(得分:2)

尝试以下方法......

#include "iostream"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace std;
using namespace cv;

int main()
{
    CvCapture *webcam = cvCaptureFromCAM(-1);
    IplImage *img = NULL;

    while(true)
    {
        img = cvQueryFrame(webcam);
        cvShowImage("TEST",img);
        cvWaitKey(20);
    }

    return 0;
}

答案 1 :(得分:1)

你检查了默认的捕获设备吗?默认情况下为0

VideoCapture cap(0);