Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add Track-bar in OpenCV using C++?
Track-bars are controllable bars which are used to control various parameters in OpenCV. Using track-bars, we can make it easier and change the parameters graphically. Track-bar removes this limitation and enables to create of dynamic effects using OpenCV.
The following program demonstrates how to add track-bars in OpenCV using C++.
Example
#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);
}
Output

Advertisements