我对函数 cvCreateTrackbar的回调参数有疑问。这是我得到的错误:
C:\Users\XELTINFO\ProjetVision\moyenetmedian.cpp:28: erreur : argument of type 'void (MoyenEtMedian::)(int)' does not match 'CvTrackbarCallback {aka void (*)(int)}'
这是该类的代码:
int g_switch_value = 0;
int filterInt = 0;
int lastfilterInt = -1;
void MoyenEtMedian::switch_callback(int position)
{
filterInt = position;
}
void MoyenEtMedian::exec(void)
{
const char* name = "Filtres";
IplImage* img = cvLoadImage( "image.png" );
IplImage* out = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 3 );
cvNamedWindow( name, 1 );
cvShowImage(name, out);
// Create trackbar
cvCreateTrackbar( "Filtre", name, &g_switch_value, 1,switch_callback );
while( 1 ) {
switch( filterInt ){
case 0:
cvSmooth( img, out, CV_BLUR, 7, 7 );
break;
case 1:
cvSmooth( img, out, CV_MEDIAN, 7, 7 );
break;
}
if(filterInt != lastfilterInt){
cvShowImage(name, out);
lastfilterInt = filterInt;
}
if( cvWaitKey( 15 ) == 27 )
break;
}
cvReleaseImage( &img );
cvReleaseImage( &out );
cvDestroyWindow( name );
}
我打算通过插槽将 exec 功能连接到按钮。