How can I set the default position of a trackbar in OpenCV?
<p>In OpenCV, using the createTrackbar function, how can someone set the default slider position to a maximum?</p>

<p>I have several sliders, some representing minimum values, and some representing maximum values. It would be nice, if the sliders for a max value, started out at the maximum (255), rather than the minimum (0). </p>

<p>I have looked around on the <a href="http://docs.opencv.org/2.4/modules/highgui/doc/user_interface.html" rel="nofollow">OpenCV documentation pages</a>, but I have not located a solution.</p>

<pre><code>import cv2
import numpy as np

def nothing(x):
    pass

# Create a black image, a window
#img = np.zeros((300,512,3), np.uint8)
cv2.namedWindow('image')
cv2.namedWindow('hsv')
cv2.namedWindow('masq')
cap = cv2.VideoCapture(0)

# create trackbars for color change
cv2.createTrackbar('R-low','image',0,255,nothing)
cv2.createTrackbar('R-high','image',0,255,nothing)

cv2.createTrackbar('G-low','image',0,255,nothing)
cv2.createTrackbar('G-high','image',0,255,nothing)

cv2.createTrackbar('B-low','image',0,255,nothing)
cv2.createTrackbar('B-high','image',0,255,nothing)


while(1):
    ret, img = cap.read()
    # Convert BGR to HSV
    hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

    cv2.imshow('image',img)
    k = cv2.waitKey(1) &amp; 0xFF
    if k == 27:
        break

    # get current positions of four trackbars
    rl = cv2.getTrackbarPos('R-low','image')
    rh = cv2.getTrackbarPos('R-high','image')

    gl = cv2.getTrackbarPos('G-low','image')
    gh = cv2.getTrackbarPos('G-high','image')

    bl = cv2.getTrackbarPos('B-low','image')
    bh = cv2.getTrackbarPos('B-high','image')

    lower = np.array([rl,gl,bl])
    upper = np.array([rh,gh,bh])

    print(rl)

    img[:] = [bl,gl,rl]

    # Threshold the HSV image to get only certain colors
    mask = cv2.inRange(hsv, lower, upper)    


    res = cv2.bitwise_and(img,img, mask= mask)

    cv2.imshow('image',img)
    cv2.imshow('masq',mask)
    cv2.imshow('hsv',hsv)


cv2.destroyAllWindows()
</code></pre>

<p>On load, it ends up looking like this:</p>

<p><a href="http://i.stack.imgur.com/6psbg.png" rel="nofollow"><img src="http://i.stack.imgur.com/6psbg.png" alt="enter image description here"></a></p>

<p>Just use the value field:</p>

<blockquote>
  <p>Python: cv.CreateTrackbar(trackbarName, windowName, value, count,
  onChange) â None </p>
  
  <p>Parameters:<br>
     trackbarname â Name of the created trackbar. </p>
  
  <p>winname â Name of the window that will be used as a parent
  of the created trackbar. </p>
  
  <p>value â Optional pointer to an integer
  variable whose value reflects the position of the slider. Upon
  creation, the slider position is defined by this variable.</p>
  
  <p>count â
  Maximal position of the slider. The minimal position is always 0.</p>
  
  <p>onChange â Pointer to the function to be called every time the slider
  changes position. </p>
  
  <p>This function should be prototyped as void
  Foo(int,void*); , where the first parameter is the trackbar position
  and the second parameter is the user data (see the next parameter). If
  the callback is the NULL pointer, no callbacks are called, but only
  value is updated. userdata â User data that is passed as is to the
  callback. It can be used to handle trackbar events without using
  global variables.</p>
</blockquote>

<p><a href="http://docs.opencv.org/2.4/modules/highgui/doc/user_interface.html" rel="nofollow">Source</a></p>

python opencv