I am working on creating my own algorithm inheriting from cv::Algorithm using the reference from the OpenCV docs. I have created my own classes that inherit from cv::Algorithm with success but I am having difficulty with this one since it has a member m_model
which is a stuct from a library that can't be modified because the MyAlgorithm
class is wrapping the functionality in this struct.
Anyways, I am trying to reference a member within the struct that is a `uchar[3] so I wrapped it in a cv::Ptr. When I compile my program without and getters or setters on the addParam method
obj.info()->addParam<uchar[3]>(obj, "arrPtr", *arrPtr, false);
the code compiles fine but I get a runtime error when I try to write
an MyAlgorithm object to file because it can't get the data. It is looking for a member variable with the arr
name but it doesn't exist. So I defined some getter and setter methods for the arr
parameter within the m_model
class member.
However, I am not sure how to pass the member function pointers into the addParams method. I know that I can't just pass them into the addParams method like a function like I am currently doing in the code below. I have also tried the following:
obj.info()->addParam<uchar[3]>(obj, "arr", *arrPtr, false, &MyAlgorithm::getArr, &MyAlgorithm::setArr);
but I get a compile error:
cannot convert parameter 5 from 'cv::Ptr<_Tp> (__thiscall MyAlgorithm::* )(void)' to 'cv::Ptr<_Tp> (__thiscall cv::Algorithm::* )(void)'
Below is a stripped down sample of my source code. Any help would be greatly appreciated.
my_algorithm.h
class MyAlgorithm : public cv::Algorithm {
public:
//Other class logic
cv::Ptr<uchar[3]> getArr();
void setArr(const cv::Ptr<uchar[3]> &arrPtr);
virtual cv::AlgorithmInfo* info() const;
protected:
//define members such as m_model
};
cv::Algorithm* createMyAlgorithm();
cv::AlgorithmInfo& MyAlgorithm_info();
my_algorithm.cpp
cv::Algorithm* createMyAlgorithm()
{
return new MyAlgorithm();
}
cv::AlgorithmInfo& MyAlgorithm_info()
{
static cv::AlgorithmInfo MyAlgorithm_info_var("MyAlgorithm", createMyAlgorithm);
return MyAlgorithm_info_var;
}
cv::AlgorithmInfo* MyAlgorithm::info() const
{
static volatile bool initialized = false;
if( !initialized )
{
initialized = true;
MyAlgorithm obj;
cv::Ptr<uchar[3]> *arrPtr = new cv::Ptr<uchar[3]>(&(obj.m_model->arr));
obj.info()->addParam<uchar[3]>(obj, "arr", *arrPtr, false, &getArr, &setArr);
}
return &MyAlgorithm_info();
}
cv::Ptr<uchar[3]> MyAlgorithm::getArr(){
//Logic to get arr
}
void MyAlgorithm::setModMin(const cv::Ptr<uchar[3]> &arrPtr){
//Logic to set arr
}