Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8560087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:11:52+00:00 2026-06-11T16:11:52+00:00

I am working on creating my own algorithm inheriting from cv::Algorithm using the reference

  • 0

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::setArr(const cv::Ptr<uchar[3]> &arrPtr){
   //Logic to set arr
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:11:54+00:00Added an answer on June 11, 2026 at 4:11 pm

    I managed to get the setter and getter for the addParam method to work. The issue was that I needed to perform a static_cast to the parent class like so:

    typedef cv::Ptr<uchar[3]> (cv::Algorithm::*ArrGetter)();
    typedef void (cv::Algorithm::*ArrSetter)(const cv::Ptr<uchar[3]> &);
    obj.info()->addParam<uchar[3]>(obj, "arr",  *arrPtr, false, static_cast<ArrGetter>(&MyAlgorithm::getArr), static_cast<ArrSetter>(&MyAlgorithm::setArr));
    

    However, I also found that OpenCV doesn’t know how to handle the read and writes of a uchar[3]. I tried a cv::Vec3b which didn’t seem to work either so I settled on a cv::Mat using the setters and getters. So the final solution looks something like this.

    my_algorithm.h

    class MyAlgorithm : public cv::Algorithm    {
    public:
        typedef cv::Mat (cv::Algorithm::*ArrGetter)();
        typedef void (cv::Algorithm::*ArrSetter)(const cv::Mat &);
    
        //Other class logic
        cv::Mat getArr();
        void setArr(const cv::Mat &arrPtr);
    
        virtual cv::AlgorithmInfo* info() const;
    protected:
        uchar[3] arr;
    };
    cv::Algorithm* createMyAlgorithm();
    cv::AlgorithmInfo& MyAlgorithm_info();
    

    my_algorithm.cpp

    cv::AlgorithmInfo* MyAlgorithm::info() const
    {
        static volatile bool initialized = false;
    
        if( !initialized ) 
        { 
            initialized = true;
            MyAlgorithm obj;
            cv::Vec3b arrVec(arr);
            obj.info()->addParam(obj, "arr",  (cv::Mat)arrVec, false, static_cast<ArrGetter>(&MyAlgorithm::getArr), static_cast<ArrSetter>(&MyAlgorithm::setArr));
        } 
        return &MyAlgorithm_info();
    }
    
    cv::Mat MyAlgorithm::getArr(){
        cv::Vec3b arrVec(arr);
        return (cv::Mat)arrVec;
    }
    void MyAlgorithm::setArr(const cv::Mat &arrMat){
        for (int i = 0; i < 3; i++)
            arr[i] = arrMat.at<uchar>(i);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating my own HTML5 audio player capable of handling playlists. I have created
I'm working on creating my own DI framework that creates delegate factories as a
I have been working through the tutorial at http://bkiers.blogspot.de/2011/03/creating-your-own-programming-language.html . In short, a small
I'm working on creating a windows service that will send emails to a customer
I am working on creating a web app that will query event logs on
I've been working on creating my own IoC container for learning purposes. After asking
I am working on creating a simple contest submission system using django. This is
When creating my own macro, and trying to add it so that anyone can
I am currently working on creating an import-based pipeline for my indie game using
I'm working on creating a Hibernate query engine that can create dynamic queries. Thus

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.