2013-02-08 121 views
3

我想爲幾個opencv相機編寫一個包裝,但是我得到錯誤:‘VideoCapture’ in namespace ‘cv’ does not name a type。我認爲這是因爲我沒有在頭文件中正確聲明cv::VideoCapture leftcv::VideoCapture right在頭文件中聲明變量

stereo.h:

#ifndef _GUARD_STEREO_GUARD_ 
#define _GUARD_STEREO_GUARD_ 

#include "cv.h" 

class Stereo { 

public: 
Stereo(int, int); 
cv::Mat getLeft(); 
cv::Mat getRight(); 

private: 
cv::VideoCapture left; 
cv::VideoCapture right; 

}; 

#endif 

Stereo.cpp:

#include "cv.h" 
#include <iostream> 

#include "stereo.h" 

using namespace cv; 

Stereo::Stereo(int leftId, int rightId) { 
    left = VideoCapture(leftId); 
    right = VideoCapture(rightId); 

    if (!left.opened() || !right.opened()) { 
      std::cerr << "Could not open camera!" << std::endl; 
    } 
} 

Mat Stereo::getLeft() { 
    Mat frame; 
    left >> frame; 
    return frame; 
} 

Mat Stereo::getRight() { 
    Mat frame; 
    right >> frame; 
    return frame; 
} 

我可以,但是,成功使用VideoCapture like this

cv::VideoCapture capLeft; // open the Left camera 
cv::VideoCapture capRight; // open the Right camera 

capLeft = cv::VideoCapture(0); 
capRight = cv::VideoCapture(1); 
+0

我們可以看到'VideoCapture'的定義嗎? – 0x499602D2 2013-02-08 22:32:00

+0

@David:它由OpenCV定義。我爲這個問題添加了一個(成功的)示例用法。 – alexdavey 2013-02-08 22:37:17

+0

您確定包含正確的.h或.cpp文件嗎? – 0x499602D2 2013-02-08 22:41:39

回答

2

OpenCV文件,你需要包括highgui.h

#include "cv.h" 
#include "highgui.h" 
+0

這真是愚蠢的我......謝謝。 – alexdavey 2013-02-08 22:56:08