永发信息网

OpenCV利用鼠标在如下图所示的MFC视频图像上画直线?

答案:1  悬赏:40  手机版
解决时间 2021-03-25 04:36
  • 提问者网友:抽煙菂渘情少年
  • 2021-03-24 16:49
OpenCV利用鼠标在如下图所示的MFC视频图像上画直线?
最佳答案
  • 五星知识达人网友:蓝房子
  • 2021-03-24 17:39
您好,您这样:
#include
#include
#include
#pragma comment( lib, "cv.lib" )
#pragma comment( lib, "cxcore.lib" )
#pragma comment( lib, "highgui.lib" )
IplImage* src = 0;
IplImage* dst = 0;
void on_mouse( int event, int x, int y, int flags, void* ustc)
{
static CvPoint pre_pt = {-1,-1};
static CvPoint cur_pt = {-1,-1};
CvFont font;
cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5, 0, 1, CV_AA);
char temp[16];

if( event == CV_EVENT_LBUTTONDOWN )
{
cvCopy(dst,src);
sprintf(temp,"(%d,%d)",x,y);
pre_pt = cvPoint(x,y);
cvPutText(src,temp, pre_pt, &font, cvScalar(0,0, 0, 255));
cvCircle( src, pre_pt, 3,cvScalar(255,0,0,0) ,CV_FILLED, CV_AA, 0 );
cvShowImage( "src", src );
cvCopy(src,dst);
}
else if( event == CV_EVENT_MOUSEMOVE && (flags & CV_EVENT_FLAG_LBUTTON))
{
cvCopy(dst,src);
sprintf(temp,"(%d,%d)",x,y);
cur_pt = cvPoint(x,y);
cvPutText(src,temp, cur_pt, &font, cvScalar(0,0, 0, 255));
cvLine(src, pre_pt, cur_pt, cvScalar(0,255,0,0), 1, CV_AA, 0 );
cvShowImage( "src", src );
}
else if( event == CV_EVENT_LBUTTONUP )
{
sprintf(temp,"(%d,%d)",x,y);
cur_pt = cvPoint(x,y);
cvPutText(src,temp, cur_pt, &font, cvScalar(0,0, 0, 255));
cvCircle( src, cur_pt, 3,cvScalar(255,0,0,0) ,CV_FILLED, CV_AA, 0 );
cvLine( src, pre_pt, cur_pt, cvScalar(0,255,0,0), 1, CV_AA, 0 );
cvShowImage( "src", src );
cvCopy(src,dst);
}
}
int main()
{
src=cvLoadImage("lena.jpg",1);
dst=cvCloneImage(src);
cvNamedWindow("src",1);
cvSetMouseCallback( "src", on_mouse, 0 );

cvShowImage("src",src);
cvWaitKey(0);
cvDestroyAllWindows();
cvReleaseImage(&src);
cvReleaseImage(&dst);
return 0;
}追问用点心行吗?百度搜谁不会啊
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯