/* Capture video input from AVI or camera, public domain. */ #include "cv.h" #include "highgui.h" #include #include IplImage *image = 0; #define WINDOWNAME "Camera" typedef unsigned char byte; int main(int argc, char** argv) { CvCapture *capture = 0; if (argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0]))) { capture = cvCaptureFromCAM(argc == 2 ? argv[1][0] - '0' : 0); } else if (argc == 2) { capture = cvCaptureFromFile(argv[1]); } if (!capture) { printf("Could not initialize capturing...\n"); return -1; } cvNamedWindow(WINDOWNAME, 1); for(;;) { image = cvQueryFrame(capture); if (!image) { break; } /* Pixel data is BGR, mask out B and G components. */ for (int y = 0; y < image->height; y++) { for (int x = 0; x < image->width; x++) { byte *p = (byte *) &image->imageData[y*image->widthStep+x*image->nChannels]; p[0] = 0; p[1] = 0; } } cvShowImage(WINDOWNAME, image); char c = cvWaitKey(1); if (c == 27) { break; } } cvReleaseCapture(&capture); cvDestroyWindow(WINDOWNAME); return 0; }