I ve created a method in a class that returns a vector in a opencv project. Class cpp and header code:
Detection::Detection(){}
vector<Rect> detection(string fileName)
{
Mat image, gray_image;
string path = "C:\\"+ fileName;
image = imread( fileName, 1 );
//create a vector array to store the face found
vector<Rect> faces;
while(true)
{
...
}
return faces;
}
Header file:
class Detection
{
public:
Detection();
vector<Rect> detection(string fileName);
};
In main function which is in another cpp file I include "Detection.h", create an object of detection and a Rect vector, when I am trying to assign them I ve got the error
error LNK2019: unresolved external symbol "public: class std::vector<class cv::Rect_<int>,class std::allocator<class cv::Rect_<int> > > __thiscall Detection::detection(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?detection@Detection@@QAE?AV?$vector@V?$Rect_@H@cv@@V?$allocator@V?$Rect_@H@cv@@@std@@@std@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@@Z) referenced in function _main
Main function code:
vector<Rect> detections;
Detection object;
detections = object.detection("C:\\opencvAssets/BioID_0102.pgm");
// ALTERNATIVES
//object.detection("C:\\opencvAssets/BioID_0102.pgm").swap(detections);
//detections(object.detection("C:\\opencvAssets/BioID_0102.pgm"));
What I am missing in my code???
Did you mean to implement the member method:
vector<Rect> Detection::detection(string fileName)
{
//...
}
instead of the free function
vector<Rect> detection(string fileName)
?
Note that if you reached the linking stage without any compiler errors, it means that detection
can probably be marked as static
or even be a free function, as it doesn't appear to be directly tied with a single Detection
object.
Also, consider passing fileName
by const
reference.