void mouseHandler(int event,int x,int y, int flags, void *param) { //printf("function "); switch( event) { case CV_EVENT_LBUTTONDOWN: if( flags & CV_EVENT_FLAG_CTRLKEY ) { printf("lbutton down and ctrl pressed!"); printf("%d %d ",x,y); } break; case CV_EVENT_LBUTTONUP: printf("left button up "); break; } printf("%d ",*(int *)param); } void trackBarHandler(int pos) { printf("Trackbar position:%d ",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()中的第三个参数是可选的。