Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring variables in header files

Tags:

c++

opencv

I'm trying to write a wrapper for a couple of opencv cameras, but I get the error: ‘VideoCapture’ in namespace ‘cv’ does not name a type. I assume it is because I am not declaring cv::VideoCapture left and cv::VideoCapture right correctly in the header file?

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;
}

I can, however, successfully use 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);
like image 531
alexdavey Avatar asked Jun 16 '26 23:06

alexdavey


1 Answers

From OpenCV document, you need to include highgui.h

#include "cv.h"
#include "highgui.h"
like image 83
billz Avatar answered Jun 18 '26 12:06

billz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!