2012-02-20 57 views
3

次のように私のコードは、私はOpenCVののVideoCaptureクラスの「ラッパー」を作成しようとしているが、私はそれが正常に働いて得ることができない。OpenCVのVideoCaptureラッパークラス

#include "opencv2/opencv.hpp" 
#include "opencv2/highgui/highgui.hpp" 

class wrapper 
{ 
    private: 
     cv::VideoCapture cap; 
     int device_id; 

    public: 
     wrapper(); 
     ~wrapper(); 

     void setup(int _device_id); 
}; 

// wrapper.cpp 

wrapper::wrapper() 
{ 
    device_id = 0; 
} 

wrapper::~wrapper() 
{ 
    cap.release(); 
} 

wrapper::setup(int _device_id) 
{ 
    device_id = _device_id; 
    cap = cv::VideoCapture(device_id); 

    cout << "Checking device" << endl; 
    if(!cap.isOpened()) 
    { 
     cout << "Couldn't open device" << endl; 
     return; 
    } 
    else 
    { 
     cout << "Device opened " << endl; 
    } 
} 

問題がありますデバイスが開かないことを確認します。私はstarter_video.exe(OpenCVの例)で私のデバイスをチェックして、それが開きます。

どのような考えですか?

+0

ところで 'する#include 'すべてのものを含んでいることで

cap = cv::VideoCapture(device_id); 

: 、ラインを交換してみてください。コアのみをインクルードする場合は、#include または#including highguiは必要ありません。 –

答えて

4

私は決してあなたのようにビデオキャプチャを割り当てようとはしません。

cap.open(device_id); 
+0

ありがとう、それは働いた – JohnnyAce

+0

また、とにかくそれが解放され、あなたがデストラクタを許したので、cap.release()は必要ではありません。 –

関連する問題