13,596,891 members
See more:
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);

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

## 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);

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;
}```
v2

Top Experts
Last 24hrsThis month
 OriginalGriff 160 Richard MacCutchan 110 Peter_in_2780 80 Gerry Schmitz 55 CPallini 20
 OriginalGriff 4,640 Jochen Arndt 2,747 Maciej Los 2,046 ppolymorphe 1,969 Thaddeus Jones 1,783