1

I am trying to execute the following program using openCV 2.4.3 on Ubuntu 12.04 LTS. But I get "camera not initialized as the output" Can anybody help me.

here is the code:

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;

 }

Please help me!

Thanks, Kushal

user891558
  • 23
  • 1
  • 3

2 Answers2

2

try the following...

#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;
}
rotating_image
  • 3,046
  • 4
  • 28
  • 46
  • Thanks for your suggestions. The camera driver was not installed. Then I installed some GLX driver using sudo apt-get mesa utils. But still no luck. now I get Segmentation fault (core dumped). I wanted to test my webcam software, so I tested with a s/w camorama. That is working fine.Your helpf is very appreciated. I am stuck. Thanks all. – user891558 Dec 10 '12 at 14:45
1

did u check the default capture device? by default it is 0

VideoCapture cap(0);
isrish
  • 692
  • 6
  • 12
  • Thanks for your suggestions. The camera driver was not installed. Then I installed some GLX driver using sudo apt-get mesa utils. But still no luck. now I get Segmentation fault (core dumped). I wanted to test my webcam software, so I tested with a s/w samorama. That is working fine.Your helpf is very appreciated. I am stuck. Thanks all. – user891558 Dec 10 '12 at 14:43
  • can you debug to know in which line where the Segmentation fault (core dumped) happen? – isrish Dec 10 '12 at 19:26