在头文件中声明变量

时间:2013-02-08 22:30:57

标签: c++ opencv

我正在尝试为几个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);

1 个答案:

答案 0 :(得分:2)

OpenCV文档中,您需要添加highgui.h

#include "cv.h"
#include "highgui.h"