In the computer vision library, the base class DescriptorExtractor (used to extract descriptors from keypoints in one image) is written like that :
class DescriptorExtractor
{
public:
virtual ~DescriptorExtractor();
void compute( const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors ) const;
protected:
virtual void computeImpl(const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors ) const = 0;
};
And for different types of descriptors, like Surf of Sift, we derive from base class:
class SurfDescriptorExtractor : public DescriptorExtractor
{
public:
SurfDescriptorExtractor(..){..}
protected:
virtual void computeImpl(const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors ) const;
SURF surf;
};
And the protected method computeImpl is (re)implemented.
I wrote a new descriptor extractor MyDescriptorExtractor which need current image (as others in opencv) and previous image too like that (?):
class MyDescriptorExtractor: public DescriptorExtractor
{
public:
...
protected:
virtual void computeImpl(const Mat& image, const Mat& prev_image, vector<KeyPoint>& keypoints, Mat& descriptors ) const;
}
I want this new class to be compatible with opencv methods using DescriptorExtractor as argument. What is the best way to do this ? Problem is that base class method compute will not have the same signature …
Thanks
Note that subclassing should still obey the Liskov substitution principle.
Still, the solution is to pass the parameter you need in the constructor of
MyDescriptorExtractor, which allows you to keep the same signature.