在头文件中声明变量
Declaring variables in header files
我正试图为几个opencv相机编写一个包装器,但我得到了错误:‘VideoCapture’ in namespace ‘cv’ does not name a type
。我想这是因为我没有在头文件中正确声明cv::VideoCapture left
和cv::VideoCapture right
?
立体声.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);
从OpenCV文档中,您需要包含highgui.h
#include "cv.h"
#include "highgui.h"
相关文章:
- 在疯狂的部分中声明变量
- 如何在C++中为高分辨率时钟声明变量?
- 在命名空间中声明变量,在 main 中定义它,使其对所有其他文件可见
- CUDA 的性能取决于声明变量
- 如何在不为其声明变量的情况下获取和使用常量值的地址?
- C++声明变量时自动类型推断而不初始化
- 在不同循环中多次声明变量的优点
- 奇怪的错误 C2131 与 constexpr 声明变量
- 是否可以在 "if" 语句中声明变量?
- 在python-ctypes中声明变量并传递给dll函数
- 在递归函数C++中声明变量
- 只有一个定义/声明时标头声明变量的多堆定义错误
- 奇怪的未声明变量编译器错误
- 我在C++程序中声明变量时遇到问题
- 在命名空间中声明变量
- C++ lambda 按值捕获,而无需更早声明变量
- 声明变量以保存字符串列表时的内存分配
- 如何声明C 变量应突变
- 为什么允许在开关语句中声明变量?但不是声明 初始化
- 在同一命名空间中声明变量和函数是否出错?[C++]