I think that this question is not specifically on OpenCV , it seems more an include problem, so please read it even if you don't know the library.
There is an old version of a library (OpenCV) that's installed in /usr/local
on the remote machine where I'm working on and where I don't have sudo
access.
I've installed an updated version in my local environment /home/spm1428/local
and I'm compiling it by using -I/home/spm1428/local/include/opencv
and -I/home/spm1428/local/include/opencv2
.
However, in a file where #include "opencv/opencv.hpp"
I get this error:
In file included from /usr/local/include/opencv2/opencv.hpp:77:0,
from /home/spm1428/CloudCache/Utilities/Utility.hpp:11,
from ../Descriptors/Descriptor.cpp:17:
/usr/local/include/opencv2/highgui/highgui.hpp:165:25: error: redeclaration of ‘IMREAD_UNCHANGED’
It's an error given by the old version of the library installed in /usr/local
, but I told him to use the local version using -I
!
So it seems that the compiler ignores my -I
directives and instead gives the priority to /usr/local/include
Why this happens?
If you wonder the whole compiling command is:
g++ -DCC_DISABLE_CUDA -I/home/spm1428/CloudCache -I/home/spm1428/local/include/opencv -I/home/spm1428/local/include/opencv2 -I/usr/include/boost -I/home/spm1428/vlfeat -O3 -g -Wall -c -fopenmp -std=c++11 -c -o Descriptor.o ../Descriptors/Descriptor.cpp
This error happens both using #include <opencv2/core.hpp>
and include "opencv2/core.hpp"
.
UPDATE OF NEW ERROR:
Changing: #incldue <opencv2/opencv.hpp>
to #include "opencv2/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
solved the problem for some reason. However, now when I compile:
g++ -DCC_DISABLE_CUDA -I/home/spm1428/local/include -I/home/spm1428/CloudCache -I/home/spm1428/local/include/opencv -I/home/spm1428/local/include/opencv2 -I/usr/include/boost -I/home/spm1428/vlfeat -O3 -g -Wall -c -fopenmp -std=c++11 -c -o SIFTOpenCV.o ../Descriptors/SIFTOpenCV.cpp
I get this error:
../Descriptors/SIFTOpenCV.cpp:31:9: error: ‘class cv::Feature2D’ has no member named ‘detectAndCompute’
sift->detectAndCompute(img, cv::Mat(), pts, descriptors);
SIFTOpenCV.cpp
includes SIFTOpenCV.hpp
, which includes #include "opencv2/xfeatures2d.hpp"
. I think that this error is related somehow to the previous one.
The weirdest thing is that this compiles correctly on my local machine (where I have sudo
access and I installed it /usr/local
)
This is the class SIFTOpenCV.hpp
:
#include "Descriptors/Descriptor.hpp"
#include <opencv2/xfeatures2d.hpp>
namespace cc{
class SIFTOpenCV : public Descriptor{
public:
SIFTOpenCV(int nFeatures=0, int nOctaveLayers=3, double contrastThreshold=0.04, double edgeThreshold=10, double sigma=1.6);
void mapParams(std::vector<std::pair<std::string,std::string>> ¶ms);
void ComputeDescriptors(cv::Mat &img, cv::Mat1f &descriptors);
private:
cv::Ptr<cv::xfeatures2d::SIFT> sift;
int nFeatures, nOctaveLayers;
double contrastThreshold, edgeThreshold, sigma;
};
}
While Descriptor.hpp
:
#include "opencv2/core.hpp"
#include <string>
#include <map>
namespace cc{
class Descriptor{
public:
virtual void mapParams(std::vector<std::pair<std::string,std::string>> ¶ms) = 0;
virtual void ComputeDescriptors(cv::Mat &img, cv::Mat1f &descriptors) = 0;
virtual void ComputeDescriptors(const std::string &fileName, const std::string &imgExt, cv::Mat1f &descriptor);
virtual void ComputeDescriptors(const std::string &dirPath, const std::string &imgExt, std::vector<cv::Mat1f> &descriptors);
void setResizeDim(const size_t resizeDim);
void setSamples (const size_t samples);
void setOMP(const bool omp);
virtual ~Descriptor();
private:
void ComputeDescriptorsRange(const std::vector<std::string> &files, std::vector<cv::Mat1f> &descriptors, const int start, const int finish, size_t errors);
size_t resizeDim = 0; //comput full-size image
int samples = 0;
bool omp = true;
};
}
I found the solution by myself: executing cpp -v
returned me:
/usr/local/include
/usr/include
/home/spm1428/local/include
...
This means that using -I/home/spm1428/local/include
was ignored because already included, but the priority was given to the old version in /usr/local/include
.
Installing OpenCV in a new local directory and include it with -I
gave the priority to the new version and solved the problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.