作者:gnuhpc
出处:http://www.cnblogs.com/gnuhpc/
#include <iostream> #include <cv.h> #include <highgui.h> void TrackBarFunc(int val); struct _TrackBarData { char *Name; //trackbar的名字 int Pos; //trackbar的初始位置 int MaxValue; //上限値 }; _TrackBarData TBData={"TrackBar",127,255}; IplImage *imgA = cvCreateImage(cvSize(300,300),IPL_DEPTH_8U,3); int main( int argc, char **argv) { cvSet (imgA, CV_RGB(0,255,0) ); cvNamedWindow("OpenCV",CV_WINDOW_AUTOSIZE); cvCreateTrackbar( TBData.Name, "OpenCV", &TBData.Pos, TBData.MaxValue , TrackBarFunc); cvWaitKey(0); cvReleaseImage(&imgA); cvDestroyAllWindows(); return 0; } void TrackBarFunc(int val) { std::cout << "now : " << val << "/n"; cvSet (imgA, CV_RGB(0,val,0) ); cvShowImage("OpenCV",imgA); }