学习使用videoInput(一)

  1. 建立工程
  2. 从下载的压缩包里找到 libs 和 requiredLibs两个文件夹(如下图所示),添加到工程所在文件夹下。

  3. 修改工程属性

链接器依赖项加入所需要的lib:比如 videoInput.lib 以及opencv常用的libs

  1. 写代码

    就一个main函数,直接贴代码~

    #define POINTER_64 __ptr64    // avoid PVOID64 errors

    #include <iostream>

    #include <stdint.h>

    #include "videoInput.h"

    #include "opencv2/opencv.hpp"

     

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

     

    using namespace cv;

    using namespace std;

     

    int main()

    {    

        videoInput VI;

     

        int numDevices = VI.listDevices(false);

        if (numDevices < 1)

        {

            cout << "no camera available" << endl;

            return 0;

        }

     

        // getDeviceName

        //cout << "getDeviceName" << endl;

        //for (int i = 0; i < numDevices; i++)

        //{

        //    cout << "\tdevice: " << i << "\tname: " << VI.getDeviceName(i) << endl;

        //}

     

        // set frame rate (default is 30)

        VI.setIdealFramerate(0, 25);

     

        // start Camera with resolution 1280 by 720

        VI.setupDevice(0, 1280, 720);

        //VI.showSettingsWindow(0);

        int width = VI.getWidth(0);

        int height = VI.getHeight(0);

        int size =VI.getSize(0);    // formate is BGR, size = width * height * 3

        cout << "====================================" << endl;

        cout << "width : " << width << " height : " << height << endl;

        cout << "size : " << size << endl;

     

        namedWindow("normal");

     

        uint8_t* pImg = new uint8_t[size];

     

        while(1)

        {

            if (VI.isFrameNew(0))

            {

                VI.getPixels(0, pImg, false, true);

                imshow("normal", Mat(Size(width, height), CV_8UC3, pImg, 3 * width));

     

                if (waitKey(1) >= 0) break;

            }

        }

    }

 

至此,videoInput库的helloWorld程序写完。

  1. 一些问题:
    1. 如何设置获取图片的格式? 我想采yuv420p的图片
    2. videoInput的库是vs2008建立的,用vs2010编译时链接有警告,不知道以后会不会遇到问题。
posted @ 2013-04-26 15:02  chsin  阅读(2404)  评论(0编辑  收藏  举报