RenHao

20130515_Lab_MouseDetect

May 14th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #include "cv.h"
  5. #include "highgui.h"
  6.  
  7. IplImage* img, *img2;
  8.  
  9.  
  10. void on_mouse( int event, int x, int y, int flags, void* param )
  11. {
  12.      printf("event = %08X x=%4d y=%4d flags =%08X\n",
  13.                    event, x,    y,    flags);
  14.      if (flags!=0)
  15.        cvCircle(
  16.                img,//CvArr* img,
  17.                cvPoint(x, y),  // CvPoint center,
  18.                rand()%30, //int radius,
  19.                cvScalar(rand()%255, rand()%255, rand()%255, 0),  //CvScalar color,
  20.                1, 8 , 0 //   int thickness=1, int line_type=8, int shift=0 );
  21.               );
  22.      cvShowImage("Fig", img);
  23.    
  24. }
  25.    
  26. int main(int argc, char *argv[])
  27. {
  28.  
  29.  
  30.  
  31.   img2 = cvCreateImage(
  32.                        cvSize(1280, 1024), //CvSize size,
  33.                        IPL_DEPTH_8U , //int depth,
  34.                        3  //int channels
  35.   );
  36.  
  37.   img = cvLoadImage("Peppers.BMP", -1);
  38.   if (img==0)
  39.   {
  40.       printf("Error in opening file\n");
  41.       system("PAUSE");        
  42.       return -1;
  43.   }
  44.   printf("Channels %d depth %d \n", img->nChannels, img->depth);
  45.   printf("The image Width by Height is %dX%d \n", img->width,img->height);
  46.   printf("The image WidthStep %d \n", img->widthStep);
  47.  
  48.   cvNamedWindow("Fig", CV_WINDOW_AUTOSIZE  );
  49.  
  50.  
  51.   cvSetMouseCallback("Fig", on_mouse, 0 );
  52.  
  53.   cvShowImage("Fig", img );
  54.  
  55.   cvWaitKey(0);
  56.  
  57.   cvDestroyWindow( "Fig" );
  58.   cvDestroyWindow( "Fig2" );
  59.  
  60.   cvReleaseImage( &img );
  61.   cvReleaseImage( &img2 );
  62.    
  63.   system("PAUSE");      
  64.   return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment