gpt4 book ai didi

c++ - 在头文件中声明变量

转载 作者:太空狗 更新时间:2023-10-29 21:46:34 26 4
gpt4 key购买 nike

我正在尝试为几个 opencv 相机编写包装器,但我收到错误:命名空间“cv”中的“VideoCapture”未命名类型。我想这是因为我没有在头文件中正确声明 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

立体声.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:

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++ - 在头文件中声明变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14782416/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com