Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Open CV
  • scikit-image
  • pycairo
  • Pyglet
  • Python
  • Numpy
  • Pandas
  • Python Database
  • Data Analysis
  • ML Math
  • Machine Learning
  • NLP
  • Deep Learning
  • Deep Learning Interview Questions
  • ML Projects
  • ML Interview Questions
  • 100 Days of Machine Learning
Open In App
Next Article:
Python OpenCV setTrackbarMax() Method
Next article icon

Python OpenCV - setTrackbarPos() Function

Last Updated : 03 Jan, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

setTrackbarPos() function sets the position of the specified trackbar in the specified window. It does not return anything. setTrackbarPos() takes three arguments. The first is for the trackbar name and the second one is the window name which is the parent of the trackbar and the third one is for the new value of the position that is to be set to the trackbar. It returns None.

Syntax:

cv.setTrackbarPos( trackbarname, winname, pos)

Parameters:

  • trackbarname - Name of trackbar.
  • winname - Name of the window that is the parent of the trackbar.
  • pos - New position.

Return:

None

To create Track bars first import all the required libraries and create a window. Now create track bar(s) and add code to change or work as per their movement.

When we move the slider of any of the trackbar its corresponding getTrackbarPos() values changes and it returns the position of the specific slider. Through which we change the behavior accordingly. 

Example: Using setTrackbarPos() function to change colors in a window

Python3
# Demo Trackbar # importing cv2 and numpy import cv2 import numpy   def nothing(x):     pass   # Creating a window with black image img = numpy.zeros((300, 512, 3), numpy.uint8) cv2.namedWindow('image')  # creating trackbars for red color change cv2.createTrackbar('R', 'image', 0, 255, nothing)  # creating trackbars for Green color change cv2.createTrackbar('G', 'image', 0, 255, nothing)  # creating trackbars for Blue color change cv2.createTrackbar('B', 'image', 0, 255, nothing)  # setting position of 'G' trackbar to 100 cv2.setTrackbarPos('G', 'image', 100)  while(True):     # show image     cv2.imshow('image', img)     # for button pressing and changing     k = cv2.waitKey(1) & 0xFF     if k == 27:         break      # get current positions of all Three trackbars     r = cv2.getTrackbarPos('R', 'image')     g = cv2.getTrackbarPos('G', 'image')     b = cv2.getTrackbarPos('B', 'image')      # display color mixture     img[:] = [b, g, r]  # close the window cv2.destroyAllWindows() 

Output:


Next Article
Python OpenCV setTrackbarMax() Method

R

rushi_javiya
Improve
Article Tags :
  • Python
  • OpenCV
  • Python-OpenCV
Practice Tags :
  • python

Similar Reads

  • Python OpenCV - selectroi() Function
    In this article, we are going to see an interesting application of the OpenCV library, which is selectROI(). With this method, we can select a range of interest in an image manually by selecting the area on the image. Syntax:  cv2.selectROI(Window_name, source image) Parameter: window_name:  name of
    3 min read
  • Python OpenCV setTrackbarMax() Method
    In this article, we will cover how to setTrackbarMax() python in OpenCV. A GUI element that let the user select a specific value within a range of values by sliding a slider linearly is known as a trackbar. This element is similar to scrolling but it lets the user select a specific value with its mi
    3 min read
  • Python OpenCV - setTrackbarMin()
    In this article, we will discuss how to set the minimum position of the trackbar. The minimum value of the track bar can be achieved using the function setTrackbarMin() from the OpenCV package in python. This function sets the minimum position of the specified trackbar in the specified window after
    4 min read
  • Python OpenCV - startWindowThread() Function
    This article will discuss how to use the python OpenCV startWindowThread() function. Do you want to display images and videos using a simplified interface through an OpenCV code? Then, you must check out the OpenCV startWindowsThread() function, which lets you use the high GUI windows, i.e., a simpl
    3 min read
  • Python OpenCV - setWindowTitle() Function
    Python OpenCV setWindowTitle() method used for giving the title of the windows. It takes 2 parameters that are windows name and the title that needs to be given. Both the parameters are expected to be of string type. Syntax: cv2.setWindowTitle( winname, title )  Parameters: winname: windows nametitl
    1 min read
  • Python OpenCV - resizeWindow() Function
    resizeWindow() method in Python OpenCV is used to resize window displaying images/videos to a specific size. The specified window size is for images excluding toolbars. This only works for created windows having flags other than CV_WINDOW_AUTOSIZE. Syntax: cv2.resizeWindow(window_name, width, height
    1 min read
  • Python OpenCV – cv2.transpose() method
    OpenCV is a library of programming functions mainly aimed at real-time computer vision. cv2.transpose() method is used to transpose a 2D array. The function cv::transpose rotate the image 90 degrees Counter clockwise. Syntax: cv2.cv.transpose( src[, dst] ) Parameters: src: It is the image whose matr
    1 min read
  • Python OpenCV Cheat Sheet
    The Python OpenCV Cheat Sheet is your complete guide to mastering computer vision and image processing using Python. It's designed to be your trusty companion, helping you quickly understand the important ideas, functions, and techniques in the OpenCV library. Whether you're an experienced developer
    15+ min read
  • Python | OpenCV BGR color palette with trackbars
    OpenCV is a library of programming functions mainly aimed at real-time computer vision. In this article, Let's create a window which will contain RGB color palette with track bars. By moving the trackbars the value of RGB Colors will change b/w 0 to 255. So using the same, we can find the color with
    2 min read
  • Python OpenCV - moveWindow() Function
    When we show the image using the imshow() function output window will open at the center or default position of a computer screen. Even if there are multiple image windows all windows will be displayed at the same position and we have to move windows manually. If we want to show image windows at a s
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences