学习OpenCV——鼠标事件 输出鼠标坐标&区域亮化

 

#include 
#include 
#include 
#include 

templateT sqr(T x){return x*x;};

CvPoint Point;
bool Drawing=false;

void onMouse(int event,int x,int y,int flags,void* param );

void Draw(IplImage* img0,CvPoint point)
{
	for(int r=0;rheight;r++)
	{
		for(int c=0;cwidth;c++)
		{
			double s=cvGetReal2D(img0,r,c);
			double d=log(sqrt((double)sqr(r-point.y)+sqr(c-point.x)))/4;
			cvSetReal2D(img0,r,c,s/d);
		}
	}
}

int main(int argc, char** argv)  
{  
	Point=cvPoint(0,0);
	IplImage* img0=cvLoadImage("D:/0_1_1696_RC.png",-1);
	IplImage *img=cvCreateImage(cvGetSize(img0),IPL_DEPTH_8U,1);
	cvNamedWindow("Webcam",1);
	cvSetMouseCallback("Webcam",onMouse,(void*)img0);
	//cvZero(img0);
	IplImage* temp=cvCloneImage(img0);

	while(true)
	{	
		cvCopyImage(img,temp);
		//if(Drawing)
			//Draw(temp,Point);
		cvShowImage("Webcam",img0);
			
			if(cvWaitKey(100)==27)
			break;
	}
	
	cvReleaseImage(&img0);
	cvDestroyWindow("Webcam");
	return 0;
}
void onMouse(int event,int x,int y,int flags,void* param )
{
	IplImage*img=(IplImage*)param;
	 switch(event)
     {
		 case CV_EVENT_LBUTTONUP:
         {
             Point=cvPoint(x,y);
         }
		 Draw(img,Point);
         break;
	 }

printf("( %d, %d) ",x,y);
printf("The Event is : %d ",event);
printf("The flags is : %d ",flags);
printf("The param is : %d\n",param);
}


 

你可能感兴趣的:(OpenCV,学习OpenCV,include,c)