Click here to Skip to main content
13,141,068 members (50,921 online)
Rate this:
 
Please Sign up or sign in to vote.
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;


<pr>


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
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.170915.1 | Last Updated 2 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100