OpenCV 为程序界面添加滑动条
作者:互联网
1 #include <cv.h> 2 #include <highgui.h> 3 4 using namespace cv; 5 6 /// 全局变量的声明与初始化 7 const int alpha_slider_max = 100; 8 int alpha_slider; 9 double alpha; 10 double beta; 11 12 /// 声明存储图像的变量 13 Mat src1; 14 Mat src2; 15 Mat dst; 16 17 /** 18 * @function on_trackbar 19 * @定义响应滑动条的回调函数 20 */ 21 void on_trackbar( int, void* ) 22 { 23 alpha = (double) alpha_slider/alpha_slider_max ; 24 beta = ( 1.0 - alpha ); 25 26 addWeighted( src1, alpha, src2, beta, 0.0, dst); 27 28 imshow( "Linear Blend", dst ); 29 } 30 31 int main( int argc, char** argv ) 32 { 33 /// 加载图像 (两图像的大小与类型要相同) 34 src1 = imread("../../images/LinuxLogo.jpg"); 35 src2 = imread("../../images/WindowsLogo.jpg"); 36 37 if( !src1.data ) { printf("Error loading src1 \n"); return -1; } 38 if( !src2.data ) { printf("Error loading src2 \n"); return -1; } 39 40 /// 初始化为零 41 alpha_slider = 0; 42 43 /// 创建窗体 44 namedWindow("Linear Blend", 1); 45 46 /// 在创建的窗体中创建一个滑动条控件 47 char TrackbarName[50]; 48 sprintf( TrackbarName, "Alpha x %d", alpha_slider_max ); 49 50 createTrackbar( TrackbarName, "Linear Blend", &alpha_slider, alpha_slider_max, on_trackbar ); 51 52 /// 结果在回调函数中显示 53 on_trackbar( alpha_slider, 0 ); 54 55 /// 按任意键退出 56 waitKey(0); 57 return 0; 58 }
标签:..,slider,int,src2,OpenCV,src1,程序界面,滑动,alpha 来源: https://www.cnblogs.com/ybqjymy/p/12171041.html