【OpenCV】视频取坐标

今天实现了视频播放以后暂停获取鼠标点击处坐标的功能。

#include 
#include 
#include 
#include 
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, 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);  
        putText(frame,temp, pt, CV_FONT_HERSHEY_COMPLEX, 1, Scalar(255, 255, 255,0));  
        circle( frame, pt, 2,cvScalar(255,0,0,0) ,CV_FILLED, CV_AA, 0 );  
        imshow( "Movie", frame );  
    }   
}

int main()  
{
    VideoCapture capture("D:\\test.wmv");  
    double rate = capture.get(CV_CAP_PROP_FPS);  
    cout<<"帧率为:"<= 0)  
        {   
            cvSetMouseCallback( "Movie", on_mouse, 0 );
            imshow("Movie",frame);
            int controlkey = waitKey(0);
            if((char) controlkey == 27) 
            {  
                break;
            }
        }        
    }


    capture.release();  
    return 0;  
}

你可能感兴趣的:(开发语言)