I have a bunch of different Feature classes which calculate image features.
I have to extract from these classes “key features” that will be used packed together as a search key.
And I will also store parts of the Feature classes. I can’t store entire feature classes because that would be quite inefficient.
Now, what I have thought of is writing a Stored_features class that puts together the “key features”.
My layout is:
Facial_features
| | |
| V |
| .---Feature1 V <|-- Abstract_feature
| | .---Feature2 <|---'
V V V
Stored_features
My problem is that such a Stored_features class would have a lot of getters and setters and as far as I know, getters and setters indicate bad design. Is there an easily maintainable way to avoid too many getters and setters here?
The point is I see my code get here very tightly coupled with this layout 🙁
EDIT:
My code extract as requested.
#include <opencv2/core/core.hpp>
class Abstract_feature{
public:
virtual void calculate()=0;
virtual void draw(cv::Mat& canvas)=0;
/// to put values into Stored_features
virtual void registrate_key_values(Stored_features&) const=0;
};
class Facial_features : Abstract_feature{
public:
virtual void calculate()
{
es.calculate; sc.calculate;
/*etc but iterating over a list of Abstract_feature's*/
}
Stored_features get_stored_features() const
{
return sf.clone();
}
private:
Stored_features sf;
Head_size es;
Skin_color sc;
};
class Head_size : public Abstract_feature{
//you can guess the impl.
};
class Stored_features{
public:
typedef enum{SKIN_COLOR=0, HEAD_SIZE_WIDTH,HEAD_SIZE_HEIGHT} Name;
public:
void set_key_feature(Name, double value);
cv::Mat get_feature_vector() const {return key_values;}
private:
cv::Mat key_values;
// and here would come other features eg.
cv::Rect head_roi; // I don't search based on these. (So I should not use getters/setters?)
};
Added opencv for it is an opencv-based project anyway.
The size of a class should be its own issue.
In this case I discovered that all I need is a
pack()function for each feature class that removes all the data I do not want to store. Then I can store the classes as they are and don’t have to care about their sizes.