[cpp]
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
IplImage* src=0
void on_mouse( int event, int x, int y, int flags, void* ustc)
{
CvFont font
cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5, 0, 1, CV_AA)
if( event == CV_EVENT_LBUTTONDOWN )
{
CvPoint pt = cvPoint(x,y)
char temp[16]
sprintf(temp,"(%d,%d)",pt.x,pt.y)
cvPutText(src,temp, pt, &font, cvScalar(255, 255, 255, 0))
cvCircle( src, pt, 2,cvScalar(255,0,0,0) ,CV_FILLED, CV_AA, 0 )
cvShowImage( "src", src )
}
}
int main()
{
src=cvLoadImage("lena.jpg",1)
cvNamedWindow("src",1)
cvSetMouseCallback( "src", on_mouse, 0 )
cvShowImage("src",src)
cvWaitKey(0)
cvDestroyAllWindows()
cvReleaseImage(&src)
return 0
}
代码二:鼠标移动时显示坐标,点击时不显示坐标
[cpp]
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
IplImage* src=0
IplImage* dst=0
void on_mouse( int event, int x, int y, int flags, void* ustc)
{
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)