How to organize the implementation of dependencies and the use of templates in C++?

There is code like this:

struct Object {}

template<class img>
class IImageRecognizer {
 virtual ~IImageRecognizer() {}
 virtual Object recognize(Img* img) = 0;

template<class img>
OpenCVRecognizer class: public IImageRecognizer<img> {
 Object recognize(Img* img);

class App {
 App(IImageRecognizer<cv::mat>* recognizer);
 IImageRecognizer<cv::mat>* recognizer;

IImageRecognizer<cv::mat>* recognizer = new OpenCVRecognizer<cv::mat>();
App* App = new App(recognizer);</cv::mat></cv::mat></cv::mat></cv::mat></class></class>

May be minor bugs as the code was written on the knee. In General, there is immediately visible problem: the App class shouldn't know anything about the internal implementation of the class responsible for image recognition, but in this case he has information that the class uses cv::Mat. Generally, in this case, I use templates to recognize the method in different subclasses, you can pass different parameters, but something went wrong. How best to organize code in this way?
July 4th 19 at 23:42
1 answer
July 4th 19 at 23:44
Templates are not needed here. You can enter your image class UniversalImage that automatically converts images between all formats and gives the necessary:

class UniversalImage {
 boost::variant<cv::mat, anotherimage> internalImg_;
 UniversalImage(const cv::Mat& img);
 UniversalImage(AnotherImage const& img);
 cv::Mat asCVMat() const;
 AnotherImage asAnotherImage() const;

With this UniversalImage we can come up with a hierarchy of processors images.

Find more questions by tags C++