Capture video from USB by using OpenCV videoInput

    技术2025-12-27  5

     

    1. OS: Win7

        IDE: VS2010

     

    2. Include Directories: ....../OpenCV2.2/include

                                        ....../OpenCV2.2/include/opencv

                                        ....../OpenCV2.2/3rdparty/include

        Library Directories: ....../OpenCV2.2/lib

                                       ....../OpenCV2.2/3rdparty/lib

        Additional Dependencies: opencv_core220d.lib, opencv_highgui220d.lib, videoInput.lib

     

    3. Code:

     

     

     

    #include "stdafx.h"

     

    #include <cxcore.h>

    #include <cv.h>

    #include <highgui.h>

    #include <videoInput.h>

    // If fatal error LNK1104: cannot open file 'atlthunk.lib'

    #pragma comment(linker, "/NODEFAULTLIB:atlthunk.lib")

     

    int _tmain(int argc, _TCHAR* argv[])

    {

    int key = 0; // Key value

    int width = 640; // Video width

    int height = 480;// Video Height

    // Create IplImage and Window

    IplImage *image = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);

    cvNamedWindow("USB Capture");

    // Capture video from device(USB)

    videoInput video;

    video.setupDevice(0, width, height);

    while(key != '/x1b'){ // ESC quit

    // Capture the new frame

    video.getPixels(0, (unsigned char *)image->imageData, false, true);

    // Show the frame

    cvShowImage("USB Capture", image);

    key = cvWaitKey(1);

    }

    // Release IplImage and Window

    cvReleaseImage(&image);

    cvDestroyWindow("USB Capture");

     

    return 0;

    }

     

    最新回复(0)