OpenCv学习笔记(三)------highgui模块

包含头文件#include
文档只讲了一个函数cv::createTrackbar,创建一个Trackbar,用来查看不同的参数效果的时候很有用。

createTrackbar( TrackbarName, "Linear Blend", &alpha_slider, alpha_slider_max, on_trackbar );

Our Trackbar has a label TrackbarName
The Trackbar is located in the window named Linear Blend
The Trackbar values will be in the range from 0 to alpha_slider_max (the minimum limit is always zero).
The numerical value of Trackbar is stored in alpha_slider
Whenever the user moves the Trackbar, the callback function on_trackbar is called

#include 
#include 
#include 
#include 
using namespace std;
using namespace cv;
const int alpha_slider_max = 100;
int alpha_slider;
double alpha, beta;
Mat src1, src2, dst;

//Trackbar变化时的回调函数
static void on_trackbar(int, void*){ 
    alpha = (double)alpha_slider / alpha_slider_max;
    beta = 1 - alpha;
    addWeighted(src1, alpha, src2, beta, 0, dst);
    imshow("Linear Blend", dst);
}

int main(){
    src1 = imread("/home/yijiull/pic/daxuecheng.jpg");
    src2 = imread("/home/yijiull/pic/hanyu.jpg");
    resize(src1, src1, Size(300, 400));  //设置图像大小,头文件,Size指定col和row
    resize(src2, src2, Size(300, 400));
    cout<0;
    namedWindow("Linear Blend", WINDOW_AUTOSIZE);
    char TrackbarName[50];
    sprintf(TrackbarName, "Alphs x %d", alpha_slider_max);

    //参数依次是:进度条名字,进度条依附的窗口名,进度条的值,进度条的最大范围(默认从0到最大值),回调函数
    createTrackbar(TrackbarName, "Linear Blend", &alpha_slider, alpha_slider_max, on_trackbar);
    on_trackbar(alpha_slider, 0);
    waitKey(0);
    return 0;

}

你可能感兴趣的:(OpenCV)