Since I got some negative comments on my system design on this question (concerning the implementation of such system), I hope that if I present the problem I could get some better suggestions.
I am trying to design a modular application to be used for feature matching in video frames (e.g. matching on very close frames of a movie or a video, like "the product" in this article by Sivic, Zisserman).
The idea is to allow for an easy switch between different feature detection algorithms as well as different matching procedures. Additionally, from my research, my understanding is that there is only a few basic matching procedures, while new matching methods mainly focus on additional pruning procedures for bad matches (e.g. spatial consistency in the same article). All the pruning procedures require for the initial matching to be done, and then do some additional work on the extracted features from the base and query images coupled by the matching, rejecting the bad matches.
The idea I had for the design is as follows:
- implement a base interface
featureDetector
- all concrete feature detection algorithms inherit from
featureDetector
interface (e.g.siftDetector
) - implement a base interface
featureMatcher
- all concrete matching methods inherit from the
featureMatcher
interface (e.g.class bruteForceMatcher
or wrappers for OpenCV matchers likecvMatcher
) - implement a base interface
imageMatcher
implementing a Strategy pattern to allow for a choice offeatureDetector
andfeatureMatcher
- for all the matching pruning procedures, implement a Decorator interface that inherits the base matching interface:
class matcherDecorator : public imageMatcher
- each additional pruning / filtering procedure implements the
matcherDecorator
interface (e.g.spatialConsistencyFilter
) and contains only the constructor withimageMatcher*
as the (only) argument (representing the component to be decorated)
The problems pointed out to me in this question arise from the specific results of the feature detection and matching process, and they concern the Decorator part of the design. Each imageMatcher
should hold extracted features from both of the images (base and query), as well as the matches between the extracted features. The internal representation of features is slightly different from the feature descriptors offered to the user via the public access function of imageMatcher
:
class imageMatcher{
private: // or protected:
...
...
std::vector <internalFeatureDescriptor> feats[2];
// no more than 500 - 1000 features can be expected
std::vector <std::pair <int, int> > matches;
// size is the same order of magnitude as the number of features
...
public:
std::vector <userFriendlyFeatures> getFeatures(int baseOrQuery);
const std::vector <std::pair<int, int> > &getMatches();
...
};
Now, since the feature vectors (as well as the matches vector) are quite "heavy", I would not like to copy them in to each one of the nested decorators (filters) when I use them. I do not have any problems with the matches
vector, since it offers a public interface for the user allowing the decorator access to the reference and omitting the need to copy the data. feats
vectors, on the other hand, do not offer such an interface, and their access function requires me to do not only copying, but also recalculation of features' internal representation. This in turn results in the need for the decorator to access the private (or protected) variables of the inner superclass pointer.
I managed to grant my self access to the needed vectors without violating any privacy constraints (I (think) I'm not doing anything evil implementationaly), but it has been suggested that the very idea of accessing the private members of the superclass violates the idea of the Decorator pattern.
All that said, I am interested in any suggestions about how to refactor my code, comments on my current implementation and anything else concerning the design of my application.