Illegal call of non-static member function in C++ OpenCV
Asked Answered
F

0

0

I'm trying to use this function, but I cannot find any examples. So I tried every possible way that I can think of, and each time I get a different error :

cv::Mat salMap;
cv::saliency::StaticSaliencySpectralResidual::computeSaliency(img, salMap);

this causes in error :

'cv::saliency::Saliency::computeSaliency': illegal call of non-static member function

Then I tried to instantiate the class like this :

cv::saliency::StaticSaliencySpectralResidual myObj;
myObj.computeSaliency(grayImg, salMap); // also tried "->" instead of "."

and here is the error I got :

Error   LNK2001 unresolved external symbol "public: bool __cdecl cv::saliency::Saliency::computeSaliency(class cv::_InputArray const &,class cv::_OutputArray const &)" (?computeSaliency@Saliency@saliency@cv@@QEAA_NAEBV_InputArray@3@AEBV_OutputArray@3@@Z)

Error   LNK2001 unresolved external symbol "public: virtual __cdecl cv::saliency::Saliency::~Saliency(void)" (??1Saliency@saliency@cv@@UEAA@XZ)

So how can I use this class?

Thanks for any help !

Flagstad answered 6/10, 2015 at 20:19 Comment(7)
You need to link the according library, your second attempt is correct otherwise.Foist
@UlrichEckhardt thanks, but I already included #include <opencv2/saliency.hpp> so the namespace is referenced correctly I guess. Visual Studio autocompletes all the class and fnnction names.Flagstad
possible duplicate of What is an undefined reference/unresolved external symbol error and how do I fix it?Premonitory
@halilpazarlama linking is not directly related to code but to your project setup. You have to setup your project accordingly. Crudly spoken, your compiler (linker to be more precise) is lacking the implementation for the given symbols. Similiar on how you have to setup include paths for header files, you must point your linker to where he can find the (precompiled) implementations. You should read up this question #6264749 to get a better grasp on the topic.Wanitawanneeickel
Have you recompiled opencv with contrib modules?Several
opencv_contrib readmeMetaphysic
Sorry for the late reply. Yes I have linked OpenCV from the project properties, other OpenCV functions are working correctly. But I have manually copy-pasted 3 .hpp files (from here) related to saliency. So probably that was my fault. But OpenCV did not have them as default. So I wonder what was the correct way for this..Flagstad

© 2022 - 2024 — McMap. All rights reserved.