Last Updated: February 25, 2016
· dlion

Capture frames with OpenCV

#include <highgui.h>

int main(int argc, char *argv[])
    CvCapture *cattura;
    IplImage *frame;
    char tasto;

    cvNamedWindow("Prima prova", CV_WINDOW_AUTOSIZE);
    cattura = cvCaptureFromCAM(0);

        frame = cvQueryFrame(cattura);
        if(!frame) break;

        cvShowImage("Prima prova", frame);
         tasto = cvWaitKey(10);
        if(tasto == 'h') break;
    cvDestroyWindow("Prima prova");
    return 0;

This snippet allow to capture frames from the webcam and put this into a gui until we press "h" from the keyboard.
This snippet use the OpenCV libraries and if you want compile it you have to do:
g++ pkg-config --cflags --libs opencv source.c -o binary

Filed Under