opencv 滚动条


参数介绍:
 createTrackbar( trackbarname , "hello" , &alpha_slider ,alpha_max ,  on_trackbar )  ;
在标签中显示的文字(提示滑动条的用途) TrackbarName
创建的滑动条要放置窗体的名字 “hello”
滑动条的取值范围从 0 到 alpha_max (最小值只能为 zero).
滑动后的值存放在 alpha_slider 变量里
每当滑动条的值改变, 就会调用 on_trackbar 回调函数



#include <iostream>
#include <string>
#include <string.h> 

#include <cv.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp> 
#include <opencv2/imgproc/imgproc.hpp>

using namespace std ;
using namespace cv  ;

const  int  alpha_max = 100 ;
Mat mtbaidu  ,  mtgoogle  , ans  ;

double  alpha , bate ;
int     alpha_slider ;

void   on_trackbar(int ,  void *){
	   alpha = (double)alpha_slider / alpha_max ; 
	   bate = 1.0 - alpha ; 
	   addWeighted(mtbaidu , alpha , mtgoogle , bate , 0.0 , ans) ;
	   imshow("hello" , ans ) ;
}

int  main(){

	 mtbaidu = imread("baidu.jpg" , 1) ;
	 mtgoogle = imread("google.jpg" , 1) ;
	 if(mtbaidu.empty() || mtgoogle.empty()){
		 puts("open error!") ; 
		 return -1 ; 
	 }
	 namedWindow("hello") ;
     char  trackbarname[50] ;
	 sprintf( trackbarname, "%d", alpha_max );

	 createTrackbar( trackbarname , "hello" , &alpha_slider ,alpha_max ,  on_trackbar )  ;
	 on_trackbar( alpha_slider, 0 );

	 waitKey(0) ; 

	 return  0 ; 
}

opencv 滚动条_第1张图片


你可能感兴趣的:(opencv 滚动条)