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 6171151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:09:52+00:00 2026-05-23T23:09:52+00:00

Obligatory – I’m a newbie. Have a job that involves programming and I’m teaching

  • 0

Obligatory – I’m a newbie. Have a job that involves programming and I’m teaching myself as I go. Needless to say as a teacher I get things wrong frequently and thoroughly.

Where I’m at right now: I’ve created the class “Graph”, it (surprisingly enough) makes graphs. But now I want to make it so that on a mouse click I modify the graph. But I can’t seem to get a mouse handler to be a member function of the class.

cv::setMouseCallback(windowName, onMouse, 0); // Set mouse handler to be onMouse

Doesn’t work with

cv::setMouseCallback(windowName, Graph::onMouse, 0);

It gives me lack of parameter errors. According to this I can’t make it a member function. After following the answer given, it compiles but my this pointer is nulled. Ugh.

OnMouse looks like this:

void onMouse(int event, int x, int y,int, void*)
{
    if (event == CV_EVENT_LBUTTONDOWN)
    {
        cvMoveWindow("Window", 500, 500); //Just to see if stuff happened
    }
    return;
}

I don’t care about moving the window, I want to modify the graph itself – which is stored as a cv::Mat variable in a Graph object. And I can’t figure out how to do it.

Any help would be appreciated, and I really hope this wasn’t just gibberish.

  • 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-05-23T23:09:53+00:00Added an answer on May 23, 2026 at 11:09 pm

    Yes callback functions in C++ are a joy, aren’t they? You actually have to give OpenCV a function (not a class method) as you’ve already found out. However, you can hack around this awfulness using the following technique:

    class MyClass
    {
    public:
         void realOnMouse(int event, int x, int y, int flags)
         {
             // Do your real processing here, "this" works fine.
         }
    };
    
    // This is a function, not a class method
    void wrappedOnMouse(int event, int x, int y, int flags, void* ptr)
    {
        MyClass* mcPtr = (MyClass*)ptr;
        if(mcPtr != NULL)
            mcPtr->realOnMouse(event, x, y, flags);
    }
    
    int main(int argv, char** argc)
    {
        // OpenCV setup stuff...
    
        MyClass processor;
        cv::setMouseCallback(windowName, wrappedOnMouse, (void*)&processor);
    
        // Main program logic
    
        return 0;
    }
    

    That last parameter on setMouseCallback is quite useful for overcoming some of the problems you usually encounter like this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently learning OpenGL ES programming on Android (2.1). I started with the obligatory
I have an application that calls AlarmManager Intent intent; intent = new Intent(context, MyEventReceiver.class);
I have to implement an algorithm that generates a timetable for a university. I've
Using S#arp Architecture 1.0RC... I have a controller that never seems to update one
I have a bat file that I should use to delete a part of
As a new android programmer I have my obligatory todo app running. It is
Given a ResultMap for an iBatis select query, it seems obligatory that all columns
I have been trying to get middleman, compass and formalize to work together, but
Let's say I have a mysql table full of color values like #EE3AA. And
Now that I've read all the DQL docs I still have some doubts, I'm

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.