opencv mouse event example code


...
void CallBackFunc(int event, int x, int y, int flags, void* userdata)
{
 if (event == EVENT_LBUTTONDOWN)
 {
  printf("lLBUTTONDOWN down %d, %d \n", x, y);

  //circle( (*(Mat*)userdata), Point(x, y), 2, CV_RGB(255, 0, 0), 3);
 }
 else if (event == EVENT_RBUTTONDOWN)
 {
  printf("RBUTTONDOWN down %d, %d \n", x, y);
 }
 else if (event == EVENT_MBUTTONDOWN)
 {
  printf("MBUTTONDOWN down %d, %d \n", x, y);
 }
 else if (event == EVENT_MOUSEMOVE)
 {
  printf("move %d, %d \n", x, y);
 }
 
 //imshow("img", (*(Mat*)userdata)); //show
}


int main(int, char)
{
 namedWindow("img", 0);
 
 Mat img = imread("gh.jpg");
 

 setMouseCallback("img", CallBackFunc, &img);

 imshow("img", img); //show
 waitKey(0);


 /*
 while (1)
 {
  imshow("img", img); //show
  if (waitKey(10) > 0)
   break;
 }
 */

 destroyAllWindows();

 return 0;
}

...



Comments

Popular posts from this blog

(OpenCV Study) Background subtractor MOG, MOG2, GMG example source code (BackgroundSubtractorMOG, BackgroundSubtractorMOG2, BackgroundSubtractorGMG)

OpenCV Stitching example (Stitcher class, Panorama)

AMP dose run on my pc?, AMP(Accelerated Massive Parallelism)

Example source code of extract HOG feature from images, save descriptor values to xml file, using opencv (using HOGDescriptor )

Optical Flow sample source code using OpenCV

Real-time N camera stitching Class.

OpenCV meanShiftFiltering example source code ( cpu: pyrMeanShiftFiltering, gpu:meanShiftFiltering, gpu:meanShiftSegmentation )

8 point algorithm (Matlab source code) / The method to get the Fundamental Matrix and the Essential matrix

Image warping (using opencv findHomography, warpPerspective)

Video Stabilization example source code, (using cvFindHomography, cvWarpPerspective functions in openCV)