当cvSetMouseCallback事件发生时,在IplImage上绘制圆圈 [英] Draw circle on IplImage when cvSetMouseCallback event occures

查看:94
本文介绍了当cvSetMouseCallback事件发生时,在IplImage上绘制圆圈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在用户点击图像的点上绘制圆圈。下面是我的代码..单击图像时没有绘制圆圈。但是当我添加

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

在主函数内部它只绘制圆...(这里我手动给出了x,y坐标) )



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

推荐答案

我自己找到了解决方案..希望这会有所帮助....



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>







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


这篇关于当cvSetMouseCallback事件发生时,在IplImage上绘制圆圈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆