1

我正在尝试在 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;

 }

请帮我!

谢谢,库沙尔

4

2 回答 2

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;
}
于 2012-11-28T16:28:06.027 回答
1

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

VideoCapture cap(0);
于 2012-11-28T07:55:43.127 回答