
- OpenCV Python Tutorial
- OpenCV Python - Home
- OpenCV Python - Overview
- OpenCV Python - Environment
- OpenCV Python - Reading Image
- OpenCV Python - Write Image
- OpenCV Python - Using Matplotlib
- OpenCV Python - Image Properties
- OpenCV Python - Bitwise Operations
- OpenCV Python - Shapes and Text
- OpenCV Python - Mouse Events
- OpenCV Python - Add Trackbar
- OpenCV Python - Resize and Rotate
- OpenCV Python - Image Threshold
- OpenCV Python - Image Filtering
- OpenCV Python - Edge Detection
- OpenCV Python - Histogram
- OpenCV Python - Color Spaces
- OpenCV Python - Transformations
- OpenCV Python - Image Contours
- OpenCV Python - Template Matching
- OpenCV Python - Image Pyramids
- OpenCV Python - Image Addition
- OpenCV Python - Image Blending
- OpenCV Python - Fourier Transform
- OpenCV Python - Capture Videos
- OpenCV Python - Play Videos
- OpenCV Python - Images From Video
- OpenCV Python - Video from Images
- OpenCV Python - Face Detection
- OpenCV Python - Meanshift/Camshift
- OpenCV Python - Feature Detection
- OpenCV Python - Feature Matching
- OpenCV Python - Digit Recognition
- OpenCV Python Resources
- OpenCV Python - Quick Guide
- OpenCV Python - Resources
- OpenCV Python - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
OpenCV Python - Add Trackbar
Trackbar in OpenCV is a slider control which helps in picking a value for the variable from a continuous range by manually sliding the tab over the bar. Position of the tab is synchronised with a value.
The createTrackbar() function creates a Trackbar object with the following command −
cv2.createTrackbar(trackbarname, winname, value, count, TrackbarCallback)
In the following example, three trackbars are provided for the user to set values of R, G and B from the grayscale range 0 to 255.
Using the track bar position values, a rectangle is drawn with the fill colour corresponding to RGB colour value.
Example
Following program is for adding a trackbar −
import numpy as np import cv2 as cv img = np.zeros((300,400,3), np.uint8) cv.namedWindow('image') def nothing(x): pass # create trackbars for color change cv.createTrackbar('R','image',0,255,nothing) cv.createTrackbar('G','image',0,255,nothing) cv.createTrackbar('B','image',0,255,nothing) while(1): cv.imshow('image',img) k = cv.waitKey(1) & 0xFF if k == 27: break # get current positions of four trackbars r = cv.getTrackbarPos('R','image') g = cv.getTrackbarPos('G','image') b = cv.getTrackbarPos('B','image') #s = cv.getTrackbarPos(switch,'image') #img[:] = [b,g,r] cv.rectangle(img, (100,100),(200,200), (b,g,r),-1) cv.destroyAllWindows()
Output

Advertisements