Tuesday, 19 February 2013


Program to open your Web Cam using Open Cv Programming:

We previously wrote a program to load an image(Link) using open computer vision now let us see how to capture image from your webcam.


Program:


//webcam

#include<opencv\highgui.h>
///////////////////////////////////  C LIBRARIES/////////////////
#include<stdio.h>
///////////////////////////////////////////////////////////////
int main(int argc,char* argv){ 
CvCapture* capWebcam;                /// we will assign web cam to this later
 IplImage* webcam_img; char charchecksEnter;                // enter closes the program capWebcam = cvCaptureFromCAM(0); // for mutiple it will be 0 and 1 and so on......///
if(capWebcam == NULL ){  
printf("Error: capturing is NULL. \n"); 
 getchar(); 
 return(-1);                    /////**** Exit programme ***/////////
 }
 cvNamedWindow("Original",CV_WINDOW_AUTOSIZE); 
while(1){ 
 webcam_img = cvQueryFrame(capWebcam);           /// assigning webcam_img to continues
                                                                                        ///  frames of images from web cam   ///
  if(webcam_img == NULL){ 
  printf("Error:frame is NULL\n");
 getchar();
  

 break; 
  } 
cvShowImage("original",webcam_img); 
charchecksEnter = cvWaitKey(10);   // waits for 10 ms. // 
if(charchecksEnter == 13)break;      // when enter key pressed. Program Breaks.. //
  } 
 cvReleaseCapture(&capWebcam);  
cvDestroyWindow("Original");  
return(0);
 }

ENjoy.. :D