callback functions with openCV

I wrote a program in c++, now I'm trying to clean it up and put it in to a more object oriented style.

The code you are looking at below are three simple callback functions and the top few lines of another function which called these slidebar callback.

Originally these were functions in the main program. The only difference is now they are both functions in a class called coriolus.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
void coriolus::vertoffset_callback(int position){
    vertoffset = position;
}
void coriolus::oddoffset_callback(int position){
    oddoffset = position;
}

void coriolus::offsetAdjust(){
    IplImage * logo = cvLoadImage(LOGO_IMG,0);
    int maxvertoffset = 100*numja*numjets/inputimage->height/3;                            ///check numbers
    vertoffset = maxvertoffset-verticaloffsetbuffer;
    cout <<"Maximum Vertical Offset Adjusted to " << maxvertoffset << "%"<<endl;
cvNamedWindow(PANEL,1);
cvMoveWindow(PANEL,0,0);
cvCreateTrackbar(H_SPC_TBARNAME,PANEL,&h_spc,3000,h_spc_callback);
cvCreateTrackbar(VERTOFFSET_TBARNAME,PANEL,&vertoffset,maxvertoffset-verticaloffsetbuffer,vertoffset_callback);
cvCreateTrackbar(ODDOFFSET_TBARNAME,PANEL,&oddoffset,100-oddoffsetbuffer,oddoffset_callback);

if(prev_mode==0){
 cvNamedWindow( H_SPC_PREVIEW_WINDOW_NAME,1);
}
if(prev_mode==1){
  cvNamedWindow( H_SPC_PREVIEW_WINDOW_NAME,0);
  cvResizeWindow(H_SPC_PREVIEW_WINDOW_NAME,PREV_RES,PRIEVIEW_WINDOW_HEIGHT);
}



When I try to debug I get the error message:

1
2
3
4
C:\Users\APRUser\Dropbox\code\oop\coriolus\main.cpp||In member function 'void coriolus::offsetAdjust()':|
C:\Users\APRUser\Dropbox\code\oop\coriolus\main.cpp|158|error: argument of type 'void (coriolus::)(int)' does not match 'CvTrackbarCallback {aka void (*)(int)}'|
C:\Users\APRUser\Dropbox\code\oop\coriolus\main.cpp|159|error: argument of type 'void (coriolus::)(int)' does not match 'CvTrackbarCallback {aka void (*)(int)}'|
C:\Users\APRUser\Dropbox\code\oop\coriolus\main.cpp|160|error: argument of type 'void (coriolus::)(int)' does not match 'CvTrackbarCallback {aka void (*)(int)}'|


It seems like it's telling me that it doesn't like my callbacks, but the only thing that has changed is that they are now both in a new class?
should this matter?
Pointers to non-static member functions is not the same as pointers to regular functions. They work differently so you can't mix them easily.
If your callback functions are not static class members they require an object that will be used to call these functions. It seems that your arguments were converted to

void ( coriolus::* )(int )


insetad of

void ( * )( int )

as you supposed.
Last edited on
Can I make them static class members since the values in the function will be changing?

Could someone direct me to an example of using an object to call a function like this?

Thanks
If you have book "Exceptional C++ Style" by Herb Sutter then you will find there an example of template class Callback which encapsulates an object and a member function of another class that to pass only an object of class Callback instead of the callback function and the corresponding object.

Last edited on
Topic archived. No new replies allowed.