Programming/openCV2015. 10. 5. 11:35

대충 이렇게 쓰면 되려나?

void CallBackFunc_Mouse(int event, int x, int y, int flags, void* userdata)

{

switch(event)

{

case EVENT_MOUSEMOVE:

//x,y

break;

case EVENT_LBUTTONDOWN:

case EVENT_LBUTTONUP:

case EVENT_RBUTTONDOWN:

case EVENT_RBUTTONUP:

case EVENT_MBUTTONDOWN:

case EVENT_MBUTTONUP:

case EVENT_LBUTTONDBLCLK:

case EVENT_RBUTTONDBLCLK:

case EVENT_MBUTTONDBLCLK:


// case EVENT_MOUSEWHEEL:

// case EVENT_MOUSEHWHEEL:

}

}


setMouseCallback("My Window", CallBackFunc_Mouse, NULL); 


2.4.1 에서는 마우스 휠 이벤트가 없다. 3.0.0 부터 지원하는 듯

error: ‘EVENT_MOUSEWHEEL’ was not declared in this scope

error: ‘EVENT_MOUSEHWHEEL’ was not declared in this scope


---



enum   cv::MouseEventFlags

  cv::EVENT_FLAG_LBUTTON = 1, 

  cv::EVENT_FLAG_RBUTTON = 2, 

  cv::EVENT_FLAG_MBUTTON = 4, 

  cv::EVENT_FLAG_CTRLKEY = 8, 

  cv::EVENT_FLAG_SHIFTKEY = 16, 

  cv::EVENT_FLAG_ALTKEY = 32 

}

 

enum   cv::MouseEventTypes

  cv::EVENT_MOUSEMOVE = 0, 

  cv::EVENT_LBUTTONDOWN = 1, 

  cv::EVENT_RBUTTONDOWN = 2, 

  cv::EVENT_MBUTTONDOWN = 3, 

  cv::EVENT_LBUTTONUP = 4, 

  cv::EVENT_RBUTTONUP = 5, 

  cv::EVENT_MBUTTONUP = 6, 

  cv::EVENT_LBUTTONDBLCLK = 7, 

  cv::EVENT_RBUTTONDBLCLK = 8, 

  cv::EVENT_MBUTTONDBLCLK = 9, 

  cv::EVENT_MOUSEWHEEL = 10, 

  cv::EVENT_MOUSEHWHEEL = 11 

}


[링크 : http://docs.opencv.org/master/d7/dfc/group__highgui.html#gsc.tab=0] 


void CallBackFunc(int event, int x, int y, int flags, void* userdata)

{

     if  ( event == EVENT_LBUTTONDOWN )

     {

          cout << "Left button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;

     }

     else if  ( event == EVENT_RBUTTONDOWN )

     {

          cout << "Right button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;

     }

     else if  ( event == EVENT_MBUTTONDOWN )

     {

          cout << "Middle button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;

     }

     else if ( event == EVENT_MOUSEMOVE )

     {

          cout << "Mouse move over the window - position (" << x << ", " << y << ")" << endl;


     }

}


setMouseCallback("My Window", CallBackFunc, NULL);


[링크 : http://opencv-srf.blogspot.kr/2011/11/mouse-events.html] 


void onMouse( int event, int x, int y, int, void* )

[링크 : https://github.com/Itseez/opencv/blob/master/samples/cpp/ffilldemo.cpp]

    [링크 : http://docs.opencv.org/modules/highgui/doc/user_interface.html#setmousecallback] 

 

2015/09/25 - [Programming/openCV] - opencv2 마우스 이벤트 / 클릭 위치


Posted by 구차니