แทร็กบาร์เป็นแถบควบคุมได้ซึ่งใช้เพื่อควบคุมพารามิเตอร์ต่างๆ ใน OpenCV เมื่อใช้แทร็กบาร์ เราสามารถทำให้มันง่ายขึ้นและเปลี่ยนพารามิเตอร์แบบกราฟิกได้ Track-bar ลบข้อจำกัดนี้ และทำให้สามารถสร้างเอฟเฟกต์ไดนามิกโดยใช้ OpenCV
โปรแกรมต่อไปนี้สาธิตวิธีเพิ่มแทร็กบาร์ใน OpenCV โดยใช้ C++
ตัวอย่าง
#include<iostream>
#include<opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main() {
Mat original;//Declaring a matrix//
original = imread("sky.jpg");//loading the image in the matrix//
namedWindow("Slider");//Declaring window to show the image//
int light = 50;//starting value of the trackbar//
createTrackbar("Brightness", "Slider", &light, 100);//creating a trackbar//
int contrast = 50;//starting value of the trackbar//
createTrackbar("Contrast", "Slider", &contrast, 100);//creating a trackbar//
while (true) {
Mat edit;//declaring a matrix//
int Brightness = light - 50;//interaction with trackbar//
double Contrast = contrast / 50.0;//interaction with trackbar//
original.convertTo(edit, -1, Contrast, Brightness);//implement the effect of change of trackbar//
waitKey(50);
}
return(0);
} ผลลัพธ์
