opencv cvSetMouseCallback 和

void mouseHandler(int event,int x,int y, int flags, void *param)
{
    //printf("function\n");
    switch( event) 
    {
    case CV_EVENT_LBUTTONDOWN:
        if( flags & CV_EVENT_FLAG_CTRLKEY )
        {    
            printf("lbutton down and ctrl pressed!");
            printf("%d %d\n",x,y);
        }
        break;
    case CV_EVENT_LBUTTONUP:
        printf("left button up\n");
        break;
    }
    printf("%d\n",*(int *)param);
}
void trackBarHandler(int pos)
{
    printf("Trackbar position:%d\n",pos);
}
int main()
{
    int mouseParam = 5;
    int trackBarVal = 23;
    int maxVal = 100;
    IplImage *img = cvLoadImage("C:\\Users\\JunXing\\Desktop\\tmp.jpg");    
    cvNamedWindow("win",CV_WINDOW_AUTOSIZE);
    cvSetMouseCallback("win",mouseHandler,&mouseParam);
    cvCreateTrackbar("bar1","win",&trackBarVal,maxVal,trackBarHandler);
    cvSetTrackbarPos("bar1","win",90);//设置拖动条的位置
    int pos = cvGetTrackbarPos("bar1","win1");//得到当前拖动条的位置
    cvShowImage("win",img);
    cvWaitKey(0);
    
    //vector<int > tmp;
    return 0;
}

 

 

 

 cvSetMouseCallback()中的第三个参数是可选的。

posted on 2014-03-28 09:37  jesse_deng  阅读(683)  评论(0编辑  收藏  举报

导航