wawjxa
Last Updated: February 25, 2016
·
1.206K
· dlion
28864ba1e7e4490c3e5e97e095d4b6c7

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);

    while(1)
    {
        frame = cvQueryFrame(cattura);
        if(!frame) break;

        cvShowImage("Prima prova", frame);
         tasto = cvWaitKey(10);
        if(tasto == 'h') break;
    }
    cvReleaseCapture(&cattura);
    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

Say Thanks
Respond