my_mouse_callback”: 函数调用缺少参数列表


我在学习OpenCV时,有一节介绍鼠标点击事件,我试着编译书上面的代码,但是会出现错误。代码如下:

void CMyVideoDlg::draw_rect(IplImage* img,CvRect rect)
{
cvRectangle(img,cvPoint(rect.x,rect.y),cvPoint(rect.x + rect.width,rect.y + rect.height),cvScalar(0xff,0x00,0x00));
}
void CMyVideoDlg::my_mouse_callback(int event,int x,int y,int flags,void* param)
{
IplImage* image = (IplImage*)param;


switch (event)
{
case CV_EVENT_MOUSEMOVE:
{
if (drawing_rect)
{
rect.width = x - rect.x;
rect.height = y - rect.y;
}
}
break;
case CV_EVENT_LBUTTONDOWN:
{
drawing_rect = true;
rect = cvRect(x,y,0,0);
}
break;
case CV_EVENT_LBUTTONUP:
{
drawing_rect = false;
if (rect.width < 0)
{
rect.x += rect.width;
rect.width *= -1;
}
if (rect.height < 0)
{
rect.y += rect.height;
rect.height *= -1;
}
draw_rect(image,rect);
}
break;
}
}


void CMyVideoDlg::OnBnClickedBtndrawrect()
{
// TODO: 在此添加控件通知处理程序代码
rect = cvRect(-1,-1,0,0);


IplImage* image = cvCreateImage(cvSize(200,200),IPL_DEPTH_8U,3);
cvZero(image);


IplImage* temp = cvCloneImage(image);


cvNamedWindow("Rectangle Example");


cvSetMouseCallback("Rectangle Example", my_mouse_callback,(void*)image);


while(1)
{
cvCopyImage(image,temp);
if (drawing_rect)
{
draw_rect(temp,rect);
}


cvShowImage("Rectangle Example",temp);


if (cvWaitKey(33) == 27)
{
break;
}
}


cvReleaseImage(&image);
cvReleaseImage(&temp);
cvDestroyWindow("Rectangle Example");
}


编译时出现error C3867: “CMyVideoDlg::my_mouse_callback”: 函数调用缺少参数列表;请使用“&CMyVideoDlg::my_mouse_callback”创建指向成员的指针

无法生成,求真相。

你可能感兴趣的:(c,image,callback)