今天实现了视频播放以后暂停获取鼠标点击处坐标的功能。
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std; Mat frame; 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, , , CV_AA); if( event == CV_EVENT_LBUTTONDOWN )
{
CvPoint pt = cvPoint(x,y);
char temp[];
sprintf(temp,"(%d,%d)",pt.x,pt.y);
putText(frame,temp, pt, CV_FONT_HERSHEY_COMPLEX, , Scalar(, , ,));
circle( frame, pt, ,cvScalar(,,,) ,CV_FILLED, CV_AA, );
imshow( "Movie", frame );
}
} int main()
{
VideoCapture capture("D:\\test.wmv");
double rate = capture.get(CV_CAP_PROP_FPS);
cout<<"帧率为:"<<rate<<endl;
namedWindow("Movie");
int delay = /rate;
bool isStart = ; while()
{
if(!capture.read(frame))
{
cout<<"读取视频失败"<<endl;
return -;
} imshow("Movie",frame);
if (!isStart)
{
waitKey();
isStart = ;
} int c = waitKey(delay); if((char) c == )
{
break;
} else if( c >= )
{
cvSetMouseCallback( "Movie", on_mouse, );
imshow("Movie",frame);
int controlkey = waitKey();
if((char) controlkey == )
{
break;
}
}
} capture.release();
return ;
}
参考代码:
【OpenCV之利用鼠标获取坐标】:http://blog.sina.com.cn/s/blog_6646924501018fpz.html
主要就是将其中的旧版代码修改为了新版本,如putText,circle等。
修改参照:
【我的OpenCV学习笔记(七):绘图操作】:http://blog.csdn.net/thefutureisour/article/details/7523925
【opencv 中的 cvPutText() 函数的使用】:http://blog.csdn.net/longzaitianya1989/article/details/8121286
下一步就是要实现追踪了。