OpenCV videoInput - eiichiromomma/CVMLAB GitHub Wiki

(OpenCV) videoInput

videoInputを使って複数台の動画像処理

videoInputの導入

ヘッダファイルとライブラリファイルを参照可能な状態にするだけで良い。

OpenCV/videoInput Libraryによるビデオキャプチャ - Point at infinity に詳しい解説がある。

構成

  1. QCamPro for Notebooks
  2. Vaioの内蔵カメラ
  3. Elecomの古いUSBカメラ

の3台を同時に表示。

videoInputの出力は以下の通り。

***** VIDEOINPUT LIBRARY - 0.198 - TFW07 *****
VIDEOINPUT SPY MODE!

SETUP: Looking For Capture Devices.
SETUP: 0) Qcam Pro for Notebooks
SETUP: 1) Sony Visual Communication Camera VGP-VCC7
SETUP: 2) Trust Webcam 14823
SETUP: 3 Device(s) found

SETUP: Setting up device 0
SETUP: Qcam Pro for Notebooks
SETUP: Couldn't find preview pin using SmartTee
SETUP: Setting capture size to 640 by 480
SETUP: Media Type is RGB24 no conversion needed.
SETUP: Device 0 is ready, setup complete

SETUP: Setting up device 1
SETUP: Sony Visual Communication Camera VGP-VCC7
SETUP: Couldn't find preview pin using SmartTee
SETUP: Default Format is set to 640 by 480
SETUP: Device 1 is ready, setup complete

SETUP: Setting up device 2
SETUP: Trust Webcam 14823
SETUP: Couldn't find preview pin using SmartTee
SETUP: Default Format is set to 320 by 240
SETUP: Device 2 is ready, setup complete

サンプルソース

何も考えずに10msごとに更新を確認して順次描画をさせるだけ。 結構快適なスピードで動作。

VI.setupDeviceの解像度やgetPixcelsのflipとRGBの選択は各デバイスに依存する。

videoInput.hのサンプルを少し弄った程度。

    #include <cv.h>
    #include <highgui.h>
    #include <videoInput.h>

    void main(void)
    {
        //create a videoInput object
      videoInput VI;
      
      //Prints out a list of available devices and returns num of devices found
      int numDevices = VI.listDevices();  
      
      int device1 = 0;  //this could be any deviceID that shows up in listDevices
      int device2 = 1;  //this could be any deviceID that shows up in listDevices
      int device3 = 2;  //this could be any deviceID that shows up in listDevices
      
      //setup the first device - there are a number of options:
      
      VI.setupDevice(device1,640,480);               //setup the first device with the default settings
      //VI.setupDevice(device1, VI_COMPOSITE);         //or setup device with specific connection type
      //VI.setupDevice(device1, 320, 240);          //or setup device with specified video size
      //VI.setupDevice(device1, 320, 240, VI_COMPOSITE);  //or setup device with video size and connection type

      //VI.setFormat(device1, VI_NTSC_M);          //if your card doesn't remember what format it should be
                                //call this with the appropriate format listed above
                                //NOTE: must be called after setupDevice!
      
      //optionally setup a second (or third, fourth ...) device - same options as above
      VI.setupDevice(device2);
      VI.setupDevice(device3);

      //As requested width and height can not always be accomodated
      //make sure to check the size once the device is setup


      IplImage *src1 = cvCreateImage(cvSize(VI.getWidth(device1),VI.getHeight(device1)),IPL_DEPTH_8U,3);
      IplImage *src2 = cvCreateImage(cvSize(VI.getWidth(device2),VI.getHeight(device2)),IPL_DEPTH_8U,3);
      IplImage *src3 = cvCreateImage(cvSize(VI.getWidth(device3),VI.getHeight(device3)),IPL_DEPTH_8U,3);

      
      char * yourBuffer1 = src1->imageData;
      char * yourBuffer2 = src2->imageData;
      char * yourBuffer3 = src3->imageData;
      //same applies to device2 etc
      
      //to get a settings dialog for the device
    //  VI.showSettingsWindow(device1);
    //  VI.showSettingsWindow(device2);

      
      //to get the data from the device first check if the data is new
      if(VI.isFrameNew(device1)){
        VI.getPixels(device1, (unsigned char*)yourBuffer1, false, true);
      }
      if(VI.isFrameNew(device2)){
        VI.getPixels(device2, (unsigned char*)yourBuffer2, false, true);
      }
      if(VI.isFrameNew(device3)){
        VI.getPixels(device3, (unsigned char*)yourBuffer3, false, true);
      }
      

      cvNamedWindow("device1",1);
      cvNamedWindow("device2",1);
      cvNamedWindow("device3",1);
      cvShowImage("device1",src1);
      cvShowImage("device2",src2);
      cvShowImage("device3",src3);
      while(cvWaitKey(10)!=27){
        if(VI.isFrameNew(device1)){
          VI.getPixels(device1, (unsigned char*)yourBuffer1, false, true);
        }
        if(VI.isFrameNew(device2)){
          VI.getPixels(device2, (unsigned char*)yourBuffer2, false, true);
        }
        if(VI.isFrameNew(device3)){
          VI.getPixels(device3, (unsigned char*)yourBuffer3, false, true);
        }

        cvShowImage("device1",src1);
        cvShowImage("device2",src2);
        cvShowImage("device3",src3);
      }
      
      //Shut down devices properly
      VI.stopDevice(device1);
      VI.stopDevice(device2);
      VI.stopDevice(device3);

    }
⚠️ **GitHub.com Fallback** ⚠️