I have been searching but could not find something clear for my doubt.
I am trying to define my own class in c++, my class uses the libraries from opencv.
I create a file.h file where I just declare the functions, with its guards.
I create a file.cpp file where I explain how the functions look like. In this program I used all the includes I would use in a normal opencv program. (I thought it was right) + the include file.h.
Normally I compile my opencv programs like:
g++ -o program.cpp `pkg-config --cflags opencv` `pkg-config --libs opencv`
Now I try to compile my file.cpp by the same way in order to use the class in oder main file but I obtain an error.
The next step, once I would have the compiled class would be:
g++ -o programMain.cpp compiledClass.o `pkg-config --cflags opencv` `pkg-config --libs opencv`
Any help/advice would be nice since it is the first time I am managing with such a big program.
#ifndef _NAMES_H
#define _NAMES_H
class segmentator {
public:
void search(Mat img,
vector<std::vector<cv::Point> >&contours,
vector<int>&similarity);
void similar(vector<std::vector<cv::Point> >&contours,
vector<std::vector<cv::Point> >&contours2,
vector<int>&similarity);
vector<Mat*> separate(Mat img,
Mat img2,
vector<std::vector<cv::Point> >&contours,
vector<std::vector<cv::Point> >& contours2,
vector<int> idx);
};
#endif
This is my file segmentator.h.
In segmentator.c I have:
#include <stdio.h>
#include <stdlib.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <sstream>
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "segmentator.h"
void segmentator::search(/*parameters*/){/*CODE*/}
void segmentator::similar(/*parameters*/){/*CODE*/}
vector<Mat*> separate(/*parameters*/){/*CODE*/}
And then I am compiling like this
g++ -o segmentator.cpp `pkg-config --cflags opencv`
and it is not recognising the extensions of opencv library.
I moved the question with the new problem that appeared to: Not possible to compile. Headers files.Enclosed own objects definition
Typically, you would first compile file.cpp into an object file:
This produces
file.o, which you then use to compile and link the main:You should limit the includes in
file.hto those you strictly need. Likewise forfile.cpp.Edit: looking at your code, you need to do the following:
cv::Matandcv::Pointinsegmentator.h. I assume these would beopencv2/core/core.hppalthough for meopencv/cv.his fine on OpenCV 2.3.1.vectorinsegmantator.hsegmentator.ccontains amainfunction, you need to link in the OpenCV libraries, soif your
segmentator.cdoes not have amain, i.e cannot be an executable, you can compile it into an object file, that you can use later to build applications: