Hi folks,
I want to display the video being captured by the webcam in C++. I've found this code, that uses OpenCV and it's very simple:
Code:
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include "cvcam.h"
#include "cv.h"
#include "highgui.h"

int main( int argc, char** argv )
{
  IplImage* frame = 0;
  CvCapture* capture = 0;
  capture = cvCaptureFromCAM(1);
  frame = cvQueryFrame( capture );
  if( !capture )
  {
    fprintf(stderr,"Could not initialize capturing...\n");
    return -1;
  }
  cvNamedWindow( "in", 0 );
  for(;;)
  {
    if(!cvGrabFrame(capture)) 
      break;
    frame = cvRetrieveFrame(capture);
    cvShowImage("in", frame );
    if( cvWaitKey(10) >= 0 )
      break;
  }
  cvReleaseCapture( &capture );
  cvDestroyWindow("in");
  return 0;
}
However, I don't know why it fails (in the "if (!capture)", it always enters - capture is null), and I don't know how to fix it.
I don't know if there is anyone here that could help me with that OpenCV issue. However, if there isn't, if you tell me another way to grab the camera input (and display it in a window) would be great!
I'm using Windows XP, if that matters.