windows上的opencv鼠标处理表单应用程序vc ++

时间:2012-04-11 11:19:37

标签: visual-c++ opencv opencvdotnet

我无法在vc ++ windows窗体应用程序中执行opencv鼠标处理。我收到了以下错误

错误29错误C3867:'touch_gui_trial1 :: Form1 :: mouseHandler':函数调用缺少参数列表;使用'& touch_gui_trial1 :: Form1 :: mouseHandler'创建指向成员的指针c:\ users \ mridul \ documents \ visual studio 2010 \ projects \ touch_gui_trial1 \ Form1.h 104 1 touch_gui_trial1

代码段如下

            public ref class Form1 : public System::Windows::Forms::Form
        {
    public:

    int i,cntr2,count,camno,cntr,ch,prev,flag_camno,hand_thresh_area;
    static int handthresharea=0,flagroi=0,drag; 
    static Point sz,point;

            void mouseHandler(int event, int x, int y, int flags, void* param)
    {
        IplImage* img0;

        img0=(IplImage *)param;
            /* user press left button */
        if (event == CV_EVENT_LBUTTONDOWN && !drag)
        {
            point = Point(x, y);
            drag  = 1;
        }

        /* user drag the mouse */
        if (event == CV_EVENT_MOUSEMOVE && drag)
        {
            img1 = cvCloneImage (img0);

            cvRectangle(
                img1,
                point,
                cvPoint(x, y),
                CV_RGB(255, 0, 0),
                1, 8, 0
            );

                        cvShowImage("Image taken", img1);
        }

        /* user release left button */
        if (event == CV_EVENT_LBUTTONUP && drag)
        {
            img1 = cvCloneImage(img0);

            cvSetImageROI(img1,cvRect(point.x,point.y,x - point.x,y - point.y));
            sz.x=x - point.x;
            sz.y=y - point.y;
            //cvNot(img1, img1);    // or do whatever with the ROI

            //cvResetImageROI(img1);
            cvNamedWindow("the roi",1); cvShowImage("the roi", img1);
            flagroi=1;
            drag = 0;
        }

        /* user click right button: reset all */
        if (event == CV_EVENT_RBUTTONUP)
        {
            //cvShowImage("Image taken", img0);
            drag = 0;
        }
    }
    int select_roi()
    {
        CvCapture *frame;
        IplImage* img0;
        IplImage* img1;

        frame=cvCaptureFromCAM(0);
        cvNamedWindow( "ROI Selection", CV_WINDOW_AUTOSIZE );
        if ( !frame ) 
        {
            fprintf( stderr, "ERROR: capture is NULL \n" );
            getchar();
            return -1;
        }
        img0= cvQueryFrame(frame);
        cvShowImage("ROI Selection", img0);
        cvSetMouseCallback("ROI Selection", ::mouseHandler, img0);
                    **//error is in the above line**

        return 0;
    }

// rest是调用select roi的GUi部分。

1 个答案:

答案 0 :(得分:1)

您的代码有两个问题:

  • 您似乎有2个mouseHandler()方法具有完全相同的签名;

  • 使用方法作为回调时,您需要确保它们是static方法:

    static void mouseHandler(int event, int x, int y, int flags, void* param) { ... }
    

当你指定回调到cvSetMouseCallback()时,你应该这样做:

cvSetMouseCallback("ROI Selection", &Form1::mouseHandler, img0);