cvCreateTrackbar 用进度条做按钮

核心函数:

cvCreateTrackbar

程序:

wKioL1PsYIuRNcwhAAFaxDp4B_M745.jpg

代码:

#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include <iostream>
int ButtonValue=-1;
IplImage* src=cvLoadImage("e:\\picture\\11.jpg");
void ButtonCallback(int position)  //回调函数
{
if(position==0)
{
cvShowImage("src",src);
std::cout<<"off"<<std::endl;
}
else
{
IplImage* gray=cvCreateImage(cvGetSize(src),8,1);
cvCvtColor(src,gray,CV_BGR2GRAY);
cvShowImage("src",gray);
std::cout<<"on"<<std::endl;
}
}
int button(int argc,char** argv)
{
cvNamedWindow("src",0);
cvCreateTrackbar("button","src",&ButtonValue,1,ButtonCallback); //创建按钮,并且注册回调函数
cvShowImage("src",src);
cvWaitKey(0);
cvDestroyWindow("src");
cvReleaseImage(&src);
return 0;
}


你可能感兴趣的:(按钮,进度条,opencv)