Capture video from USB by using OpenCV videoInput

来源:互联网 发布:alias软件购买 编辑:程序博客网 时间:2024/06/06 02:51

 

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;

}