本章唯一内容:
添加一个滚动条
-
Adding a Trackbar to our applications!
Compatibility: > OpenCV 2.0
Author: Ana Huamán
We will learn how to add a Trackbar to our applications
还记得前面的线性变换Adding (blending) two images using OpenCV吗?这章通过增加一个滚动条来实现可变参数的叠加效果。
关键内容:
createTrackbar( TrackbarName, "Linear Blend", &alpha_slider, alpha_slider_max, on_trackbar );
添加一个滚动条,参数:
名称,窗口名(这个很奇怪,居然靠窗口名来定位投射窗口),滚动值存储变量(整数),最大值,回调处理函数
其中的细节请自行体会:
- We use the value of alpha_slider (integer) to get a double value for alpha. 滚动条获取整数变量,自行转换数据类型
- alpha_slider is updated each time the trackbar is displaced by the user. 用户在每个刻度对滚动条的修改都立即生效
- We define src1, src2, dist, alpha, alpha_slider and beta as global variables, so they can be used everywhere. 注意对象的声明周期与作用范围。