Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++VS2010OpenCV
Iam trying to draw circles on points where the user clicks on the image..below is my code..it doesn't draws the circle when clicked on the image.But when i add
cvCircle(shape,cvPoint(100,100),10,CV_RGB(0,255,0),-1);
inside main function it just draws the circle...(here i have given the x,y coordinates manually)
 
 
IplImage* shape;
 
void mouseHandler(int event, int x, int y, int flags, void* param)
  {
    switch(event){
      case CV_EVENT_LBUTTONDOWN:
          printf("Left button clicked %i\ %i \n",x,y);
           cvCircle(shape,cvPoint(x,y),10,CV_RGB(0,255,0),-1);
 
          break;
 
      case CV_EVENT_RBUTTONDOWN:
        printf("Right BUTTON Clicked\n");
        break;
 
    }
}
 
int _tmain(int argc, _TCHAR* argv[])
{
   
    cvNamedWindow("Shapes",CV_WINDOW_AUTOSIZE);
     
    shape=cvLoadImage("bb.jpg");
    
      cvSetMouseCallback("Shapes",mouseHandler,0);
 
     
    cvShowImage("Shapes",shape);
    
    cvWaitKey(0);
   
    cvReleaseImage(&shape);
    cvDestroyAllWindows();
 
    return 0;
}
 
Does anyone know the reason?
Thankyou
Posted 25-Feb-13 4:24am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

i have found the solution myself..Hope this will help....
 
int xC,yC;
int *Xvalues = new int[15];
int *Yvalues = new int[15];
int count = 0;
bool drawing_circle = false;
 

 

void draw_circle(IplImage* img, int x,int y)
  {
         cvCircle(img,cvPoint(x,y),1,CV_RGB(0,255,0),-1);
	 Xvalues[count] = x;
	 Yvalues[count] = y;
	 count++;
 
    }
}
 
void my_mouse_callback( int event, int x, int y, int flags, void* param ){
	IplImage* image = (IplImage*) param;
 
	switch( event ){
 
		case CV_EVENT_LBUTTONDOWN:
			drawing_circle = true;
			xC = x;
			yC = y;
			break;
	}
}
 
int _tmain(int argc, _TCHAR* argv[])
{
 
    cvNamedWindow("Shapes",CV_WINDOW_AUTOSIZE);
 
    shape=cvLoadImage("bb.jpg");
 
    cvSetMouseCallback( name, my_mouse_callback, (void*) image);
 

    cvShowImage("Shapes",shape);
    
      while( 1 ){
		
		if( drawing_box ) 
		{
			draw_circle( image, xC,yC );
			
		}
    cvWaitKey(0);
 
    cvReleaseImage(&shape);
    cvDestroyAllWindows();
 
    return 0;
}
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Guruprasad.K.Basavaraju 450
1 Sergey Alexandrovich Kryukov 370
2 Shai Vashdi 318
3 OriginalGriff 265
4 Peter Leow 171
0 Sergey Alexandrovich Kryukov 9,109
1 OriginalGriff 5,290
2 Peter Leow 4,010
3 Maciej Los 3,535
4 Abhinav S 3,263


Advertise | Privacy | Mobile
Web04 | 2.8.140415.2 | Last Updated 2 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid