Mouse handler - Help please

View: New views
5 Messages — Rating Filter:   Alert me  

Mouse handler - Help please

by Mike12312312312 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

The code below shows my attempt to detect mouse clicks on an image. I am using VC++ 2008 and when I run it I get the following error:

Error 4 error C3867: 'CGlaucomaApp::MouseHandler': function call missing argument list; use '&CGlaucomaApp::MouseHandler' to create a pointer to member c:\Users\TEst\Documents\MScWork\Project\Glaucoma\Glaucoma\Glaucoma.cpp 304 Glaucoma

If I do what it says and change MouseHandler to '&CGlaucomaApp::MouseHandler' I get this error:

Error 4 error C2664: 'cvSetMouseCallback' : cannot convert parameter 2 from 'void (__thiscall CGlaucomaApp::* )(int,int,int,int,void *)' to 'CvMouseCallback' c:\Users\TEst\Documents\MScWork\Project\Glaucoma\Glaucoma\Glaucoma.cpp 304 Glaucoma

If anyone can help I would be incredibly grateful as this is very important to me and I am completely stuck.

Thanks

Mike



void CGlaucomaApp::OnAnnotateStart()
{    
   
    currentImg = origImg;
    // create a window
    cvvNamedWindow( "Current Image", 1 );
    // display the image on window
    cvvShowImage("Current Image", currentImg );
    annotation = 1;

    //start mouse listener
    int mouseParam = 5;
    cvSetMouseCallback("Current Image", MouseHandler, &mouseParam);    //The problem is here
}

void CGlaucomaApp::MouseHandler(int event, int x, int y, int flags, void* param)
{
    if (annotation == 1)
    {
        switch(event)
        {
        case CV_EVENT_LBUTTONUP:
              CvPoint* p = new CvPoint();
         
            printf("Left button up\n");
            p->x = x;
            p->y = y;
         
        break;
        }
    }
}

Re: Mouse handler - Help please

by jimbos :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Mike12312312312 wrote:
Hello,

The code below shows my attempt to detect mouse clicks on an image. I am using VC++ 2008 and when I run it I get the following error:

Error 4 error C3867: 'CGlaucomaApp::MouseHandler': function call missing argument list; use '&CGlaucomaApp::MouseHandler' to create a pointer to member c:\Users\TEst\Documents\MScWork\Project\Glaucoma\Glaucoma\Glaucoma.cpp 304 Glaucoma

If I do what it says and change MouseHandler to '&CGlaucomaApp::MouseHandler' I get this error:

Error 4 error C2664: 'cvSetMouseCallback' : cannot convert parameter 2 from 'void (__thiscall CGlaucomaApp::* )(int,int,int,int,void *)' to 'CvMouseCallback' c:\Users\TEst\Documents\MScWork\Project\Glaucoma\Glaucoma\Glaucoma.cpp 304 Glaucoma

If anyone can help I would be incredibly grateful as this is very important to me and I am completely stuck.

Thanks

Mike



void CGlaucomaApp::OnAnnotateStart()
{    
   
    currentImg = origImg;
    // create a window
    cvvNamedWindow( "Current Image", 1 );
    // display the image on window
    cvvShowImage("Current Image", currentImg );
    annotation = 1;

    //start mouse listener
    int mouseParam = 5;
    cvSetMouseCallback("Current Image", MouseHandler, &mouseParam);    //The problem is here
}

void CGlaucomaApp::MouseHandler(int event, int x, int y, int flags, void* param)
{
    if (annotation == 1)
    {
        switch(event)
        {
        case CV_EVENT_LBUTTONUP:
              CvPoint* p = new CvPoint();
         
            printf("Left button up\n");
            p->x = x;
            p->y = y;
         
        break;
        }
    }
}
The problem is in your attempt to use class member function as callback function. An easiest way to fix the problem is to use such standalone function as mouse handler:

void MouseHandler(int event, int x, int y, int flags, void* param)
{
    if (annotation == 1)
    {
        switch(event)
        {
        case CV_EVENT_LBUTTONUP:
              CvPoint* p = new CvPoint();
         
            printf("Left button up\n");
            p->x = x;
            p->y = y;
         
        break;
        }
    }
}

To access CGlaucomaApp class members from MouseHandler() you can pass pointer to CGlaucomaApp class through void* param parameter:

// .. insert these lines into MouseHandler body
CGlaucomaApp* pGlaucomaApp = (CGlaucomaApp*)param;

// do something with CGlaucomaApp
pGlaucomaApp->DoSomething();

Another, more complicated way is to use some techniques to override limitation of using class member functions as callbacks. For example, see this: http://www.codeproject.com/KB/cpp/Ellipses.aspx

Re: Mouse handler - Help please

by Mike12312312312 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the response but I think you may have missed the problem or maybe I didn't explain it well enough. Calling CGlaucomaApp class members from MouseHandler() isn't a problem the error arises when I try to pass the MouseHandler() to the opencv function cvSetMouseCallback() as the second argument; CvMouseCallback on_mouse. This is what all the examples I have seen suggest I do but I am getting the errors stated earlier.



jimbos wrote:
Mike12312312312 wrote:
Hello,

The code below shows my attempt to detect mouse clicks on an image. I am using VC++ 2008 and when I run it I get the following error:

Error 4 error C3867: 'CGlaucomaApp::MouseHandler': function call missing argument list; use '&CGlaucomaApp::MouseHandler' to create a pointer to member c:\Users\TEst\Documents\MScWork\Project\Glaucoma\Glaucoma\Glaucoma.cpp 304 Glaucoma

If I do what it says and change MouseHandler to '&CGlaucomaApp::MouseHandler' I get this error:

Error 4 error C2664: 'cvSetMouseCallback' : cannot convert parameter 2 from 'void (__thiscall CGlaucomaApp::* )(int,int,int,int,void *)' to 'CvMouseCallback' c:\Users\TEst\Documents\MScWork\Project\Glaucoma\Glaucoma\Glaucoma.cpp 304 Glaucoma

If anyone can help I would be incredibly grateful as this is very important to me and I am completely stuck.

Thanks

Mike



void CGlaucomaApp::OnAnnotateStart()
{    
   
    currentImg = origImg;
    // create a window
    cvvNamedWindow( "Current Image", 1 );
    // display the image on window
    cvvShowImage("Current Image", currentImg );
    annotation = 1;

    //start mouse listener
    int mouseParam = 5;
    cvSetMouseCallback("Current Image", MouseHandler, &mouseParam);    //The problem is here
}

void CGlaucomaApp::MouseHandler(int event, int x, int y, int flags, void* param)
{
    if (annotation == 1)
    {
        switch(event)
        {
        case CV_EVENT_LBUTTONUP:
              CvPoint* p = new CvPoint();
         
            printf("Left button up\n");
            p->x = x;
            p->y = y;
         
        break;
        }
    }
}
The problem is in your attempt to use class member function as callback function. An easiest way to fix the problem is to use such standalone function as mouse handler:

void MouseHandler(int event, int x, int y, int flags, void* param)
{
    if (annotation == 1)
    {
        switch(event)
        {
        case CV_EVENT_LBUTTONUP:
              CvPoint* p = new CvPoint();
         
            printf("Left button up\n");
            p->x = x;
            p->y = y;
         
        break;
        }
    }
}

To access CGlaucomaApp class members from MouseHandler() you can pass pointer to CGlaucomaApp class through void* param parameter:

// .. insert these lines into MouseHandler body
CGlaucomaApp* pGlaucomaApp = (CGlaucomaApp*)param;

// do something with CGlaucomaApp
pGlaucomaApp->DoSomething();

Another, more complicated way is to use some techniques to override limitation of using class member functions as callbacks. For example, see this: http://www.codeproject.com/KB/cpp/Ellipses.aspx

Re: Mouse handler - Help please

by Nils Hasler-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sunday 22 June 2008 17:27, Mike12312312312 wrote:
> Thanks for the response but I think you may have missed the problem or
> maybe I didn't explain it well enough. Calling CGlaucomaApp class members
> from MouseHandler() isn't a problem the error arises when I try to pass the
> MouseHandler() to the opencv function cvSetMouseCallback() as the second
> argument; CvMouseCallback on_mouse. This is what all the examples I have
> seen suggest I do but I am getting errors stated earlier.

Actually, I believe that jimbo is right. The problem you don't seem to see is
that a class member function always expects an implicit argument (this). so
the parameters expected for the callback don't match. one solution is to pull
the callback function out of the class as suggested by jimbo. An other
solution is to make it static.

cheers,
nils

> >> Error 4 error C2664: 'cvSetMouseCallback' : cannot convert parameter 2
> >> from 'void (__thiscall CGlaucomaApp::* )(int,int,int,int,void *)' to
> >> 'CvMouseCallback'
> >> c:\Users\TEst\Documents\MScWork\Project\Glaucoma\Glaucoma\Glaucoma.cpp
> >> 304 Glaucoma
> >>
> >> If anyone can help I would be incredibly grateful as this is very
> >> important to me and I am completely stuck.
> >>
> > The problem is in your attempt to use class member function as callback
> > function. An easiest way to fix the problem is to use such standalone
> > function as mouse handler:
> >
> > void MouseHandler(int event, int x, int y, int flags, void* param)
> > {
> >     if (annotation == 1)
> >     {
> >         switch(event)
> >         {
> >         case CV_EVENT_LBUTTONUP:
> >               CvPoint* p = new CvPoint();
> >
> >             printf("Left button up\n");
> >             p->x = x;
> >             p->y = y;
> >
> >         break;
> >         }
> >     }
> > }
> >
> > To access CGlaucomaApp class members from MouseHandler() you can pass
> > pointer to CGlaucomaApp class through void* param parameter:
> >
> > // .. insert these lines into MouseHandler body
> > CGlaucomaApp* pGlaucomaApp = (CGlaucomaApp*)param;
> >
> > // do something with CGlaucomaApp
> > pGlaucomaApp->DoSomething();
> >
> > Another, more complicated way is to use some techniques to override
> > limitation of using class member functions as callbacks. For example, see
> > this: http://www.codeproject.com/KB/cpp/Ellipses.aspx

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Opencvlibrary-devel mailing list
Opencvlibrary-devel@...
https://lists.sourceforge.net/lists/listinfo/opencvlibrary-devel

Re: Mouse handler - Help please

by Mike12312312312 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok thanks, sorry am a bit new to this. Could give me an example of how to implement jimbo's solution because I'm not really sure what he means. Also tried declaring it as static and got this error:

Error 7 error LNK2001: unresolved external symbol "public: static void __cdecl CGlaucomaApp::MouseHandler(int,int,int,int,void *)" (?MouseHandler@CGlaucomaApp@@SAXHHHHPAX@Z) Glaucoma.obj Glaucoma

Thanks

Mike

Nils Hasler-2 wrote:
On Sunday 22 June 2008 17:27, Mike12312312312 wrote:
> Thanks for the response but I think you may have missed the problem or
> maybe I didn't explain it well enough. Calling CGlaucomaApp class members
> from MouseHandler() isn't a problem the error arises when I try to pass the
> MouseHandler() to the opencv function cvSetMouseCallback() as the second
> argument; CvMouseCallback on_mouse. This is what all the examples I have
> seen suggest I do but I am getting errors stated earlier.

Actually, I believe that jimbo is right. The problem you don't seem to see is
that a class member function always expects an implicit argument (this). so
the parameters expected for the callback don't match. one solution is to pull
the callback function out of the class as suggested by jimbo. An other
solution is to make it static.

cheers,
nils

> >> Error 4 error C2664: 'cvSetMouseCallback' : cannot convert parameter 2
> >> from 'void (__thiscall CGlaucomaApp::* )(int,int,int,int,void *)' to
> >> 'CvMouseCallback'
> >> c:\Users\TEst\Documents\MScWork\Project\Glaucoma\Glaucoma\Glaucoma.cpp
> >> 304 Glaucoma
> >>
> >> If anyone can help I would be incredibly grateful as this is very
> >> important to me and I am completely stuck.
> >>
> > The problem is in your attempt to use class member function as callback
> > function. An easiest way to fix the problem is to use such standalone
> > function as mouse handler:
> >
> > void MouseHandler(int event, int x, int y, int flags, void* param)
> > {
> >     if (annotation == 1)
> >     {
> >         switch(event)
> >         {
> >         case CV_EVENT_LBUTTONUP:
> >               CvPoint* p = new CvPoint();
> >
> >             printf("Left button up\n");
> >             p->x = x;
> >             p->y = y;
> >
> >         break;
> >         }
> >     }
> > }
> >
> > To access CGlaucomaApp class members from MouseHandler() you can pass
> > pointer to CGlaucomaApp class through void* param parameter:
> >
> > // .. insert these lines into MouseHandler body
> > CGlaucomaApp* pGlaucomaApp = (CGlaucomaApp*)param;
> >
> > // do something with CGlaucomaApp
> > pGlaucomaApp->DoSomething();
> >
> > Another, more complicated way is to use some techniques to override
> > limitation of using class member functions as callbacks. For example, see
> > this: http://www.codeproject.com/KB/cpp/Ellipses.aspx

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Opencvlibrary-devel mailing list
Opencvlibrary-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opencvlibrary-devel
LightInTheBox - Buy quality products at wholesale price