<h5 dir="auto">System information (version)</h5>
<ul dir="auto">
<li>OpenCV =&gt; 4.5.3</li>
<li>Operating System / Platform =&gt; Windows 64 Bit</li>
<li>Compiler =&gt; VSC</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">I've been trying to create a trackbar. I've also tried the solutions provided in Github by Berak (<a href="https://www.gitmemory.com/issue/opencv/opencv/20408/880533612" rel="nofollow">https://www.gitmemory.com/issue/opencv/opencv/20408/880533612</a>) but I am still getting the same errors.</p>
<h5 dir="auto">Steps to reproduce</h5>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import cv2
import numpy as np

lowH = 0
highH = 180

lowS = 0
highS = 255

lowV = 0
highV = 255

cap = cv2.VideoCapture(0)
cv2.createTrackbar(&quot;l-h&quot;, &quot;frame&quot;, lowH, 180, lambda x:x)
cv2.createTrackbar(&quot;h-h&quot;, &quot;frame&quot;, highH, 180, lambda x:x)
cv2.createTrackbar(&quot;l-s&quot;, &quot;frame&quot;, lowS, 255, lambda x:x)
cv2.createTrackbar(&quot;h-s&quot;, &quot;frame&quot;, highS, 255, lambda x:x)
cv2.createTrackbar(&quot;l-v&quot;, &quot;frame&quot;, lowV, 255, lambda x:x)
cv2.createTrackbar(&quot;h-v&quot;, &quot;frame&quot;, highV, 255, lambda x:x)"><pre class="notranslate"><code class="notranslate">import cv2
import numpy as np

lowH = 0
highH = 180

lowS = 0
highS = 255

lowV = 0
highV = 255

cap = cv2.VideoCapture(0)
cv2.createTrackbar("l-h", "frame", lowH, 180, lambda x:x)
cv2.createTrackbar("h-h", "frame", highH, 180, lambda x:x)
cv2.createTrackbar("l-s", "frame", lowS, 255, lambda x:x)
cv2.createTrackbar("h-s", "frame", highS, 255, lambda x:x)
cv2.createTrackbar("l-v", "frame", lowV, 255, lambda x:x)
cv2.createTrackbar("h-v", "frame", highV, 255, lambda x:x)
</code></pre></div>
<h5 dir="auto">System information (version)</h5>
<ul dir="auto">
<li>OpenCV == 4.5.3.56 (latest)</li>
<li>Operating System / Platform =&gt; Windows 10 Pro</li>
<li>Compiler =&gt; Python 3.7</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">After updating to the most recent version of <code class="notranslate">opencv-contrib-python</code>, now when creating a trackbar using</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="cv2.createTrackbar(TRACKBAR_NAME, WINDOW_NAME, 0, MAX_VAL, on_trackbar_foo)"><pre class="notranslate"><span class="pl-s1">cv2</span>.<span class="pl-en">createTrackbar</span>(<span class="pl-v">TRACKBAR_NAME</span>, <span class="pl-v">WINDOW_NAME</span>, <span class="pl-c1">0</span>, <span class="pl-v">MAX_VAL</span>, <span class="pl-s1">on_trackbar_foo</span>)</pre></div>
<p dir="auto">the following warning is printed in the terminal:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="[ WARN:0] global C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-_xlv4eex\opencv\modules\highgui\src\window.cpp (704) cv::createTrackbar UI/Trackbar(Source@Navigation controls): Using 'value' pointer is unsafe and deprecated. Use NULL as value pointer. To fetch trackbar value setup callback"><pre class="notranslate">[ WARN:0] global C:<span class="pl-cce">\U</span>sers<span class="pl-cce">\r</span>unneradmin<span class="pl-cce">\A</span>ppData<span class="pl-cce">\L</span>ocal<span class="pl-cce">\T</span>emp<span class="pl-cce">\p</span>ip-req-build-_xlv4eex<span class="pl-cce">\o</span>pencv<span class="pl-cce">\m</span>odules<span class="pl-cce">\h</span>ighgui<span class="pl-cce">\s</span>rc<span class="pl-cce">\w</span>indow.cpp (704) cv::createTrackbar UI/Trackbar(Source@Navigation controls): Using <span class="pl-s"><span class="pl-pds">'</span>value<span class="pl-pds">'</span></span> pointer is unsafe and deprecated. Use NULL as value pointer. To fetch trackbar value setup callback</pre></div>
<p dir="auto">I'm not exactly sure what that means in the context of the Python API.</p>
<p dir="auto">Furthermore, if I then try to dynamically change the maximum value of the trackbar like this</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="cv2.setTrackbarMax(TRACKBAR_NAME, WINDOW_NAME, N)"><pre class="notranslate"><span class="pl-s1">cv2</span>.<span class="pl-en">setTrackbarMax</span>(<span class="pl-v">TRACKBAR_NAME</span>, <span class="pl-v">WINDOW_NAME</span>, <span class="pl-v">N</span>)</pre></div>
<p dir="auto">the trackbar itself is now stuck at 0 (or whatever the minimum is set to) and cannot be moved with the mouse cursor.</p>
<p dir="auto">This used to be fine in the previous versions. For example, it works fine in <strong>4.5.2.52</strong>.</p>
<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">Just creating a trackbar in Python using a most recent version of OpenCV, e.g. in my case:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import cv2
from functools import partial

def on_trackbar_class(value, param):
    param['current_class'] = int(value)
    param['CHANGED_CLASS'] = True       # signal that the class-trackbar was moved

# ...

# this gets the list of classes from the dataset metadata
# CLASSES = dataset.get_classes()
CLASSES = [&quot;head&quot;, &quot;left_hand&quot;, &quot;right_hand&quot;, &quot;right_leg&quot;, &quot;left_leg&quot;]

# this data is modified via the trackbar and then used elsewhere
current_class = 0 # this is passed down as a function argument from elsewhere, use '0' here for testing
trackbar_data = {'current_class': current_class}

# create window
WINDOW_NAME = &quot;Navigation controls&quot;
cv2.namedWindow(WINDOW_NAME, cv2.WINDOW_AUTOSIZE)

# create trackbar
TRACKBAR_NAME = 'Class'
max_classes = (len(CLASSES) - 1) if len(CLASSES) &gt; 1 else 1
cv2.createTrackbar(TRACKBAR_NAME, WINDOW_NAME, 0, max_classes, partial(on_trackbar_class, param=trackbar_data))

# the length of the CLASSES might change at some point
# this actually happens elsewhere, but I'm putting this in the same function right here
cv2.setTrackbarMax(TRACKBAR_NAME, WINDOW_NAME, len(CLASSES) - 1) 

# keep the window opened for testing
cv2.waitKey(0)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">cv2</span>
<span class="pl-k">from</span> <span class="pl-s1">functools</span> <span class="pl-k">import</span> <span class="pl-s1">partial</span>

<span class="pl-k">def</span> <span class="pl-en">on_trackbar_class</span>(<span class="pl-s1">value</span>, <span class="pl-s1">param</span>):
    <span class="pl-s1">param</span>[<span class="pl-s">'current_class'</span>] <span class="pl-c1">=</span> <span class="pl-en">int</span>(<span class="pl-s1">value</span>)
    <span class="pl-s1">param</span>[<span class="pl-s">'CHANGED_CLASS'</span>] <span class="pl-c1">=</span> <span class="pl-c1">True</span>       <span class="pl-c"># signal that the class-trackbar was moved</span>

<span class="pl-c"># ...</span>

<span class="pl-c"># this gets the list of classes from the dataset metadata</span>
<span class="pl-c"># CLASSES = dataset.get_classes()</span>
<span class="pl-v">CLASSES</span> <span class="pl-c1">=</span> [<span class="pl-s">"head"</span>, <span class="pl-s">"left_hand"</span>, <span class="pl-s">"right_hand"</span>, <span class="pl-s">"right_leg"</span>, <span class="pl-s">"left_leg"</span>]

<span class="pl-c"># this data is modified via the trackbar and then used elsewhere</span>
<span class="pl-s1">current_class</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span> <span class="pl-c"># this is passed down as a function argument from elsewhere, use '0' here for testing</span>
<span class="pl-s1">trackbar_data</span> <span class="pl-c1">=</span> {<span class="pl-s">'current_class'</span>: <span class="pl-s1">current_class</span>}

<span class="pl-c"># create window</span>
<span class="pl-v">WINDOW_NAME</span> <span class="pl-c1">=</span> <span class="pl-s">"Navigation controls"</span>
<span class="pl-s1">cv2</span>.<span class="pl-en">namedWindow</span>(<span class="pl-v">WINDOW_NAME</span>, <span class="pl-s1">cv2</span>.<span class="pl-v">WINDOW_AUTOSIZE</span>)

<span class="pl-c"># create trackbar</span>
<span class="pl-v">TRACKBAR_NAME</span> <span class="pl-c1">=</span> <span class="pl-s">'Class'</span>
<span class="pl-s1">max_classes</span> <span class="pl-c1">=</span> (<span class="pl-en">len</span>(<span class="pl-v">CLASSES</span>) <span class="pl-c1">-</span> <span class="pl-c1">1</span>) <span class="pl-k">if</span> <span class="pl-en">len</span>(<span class="pl-v">CLASSES</span>) <span class="pl-c1">&gt;</span> <span class="pl-c1">1</span> <span class="pl-k">else</span> <span class="pl-c1">1</span>
<span class="pl-s1">cv2</span>.<span class="pl-en">createTrackbar</span>(<span class="pl-v">TRACKBAR_NAME</span>, <span class="pl-v">WINDOW_NAME</span>, <span class="pl-c1">0</span>, <span class="pl-s1">max_classes</span>, <span class="pl-en">partial</span>(<span class="pl-s1">on_trackbar_class</span>, <span class="pl-s1">param</span><span class="pl-c1">=</span><span class="pl-s1">trackbar_data</span>))

<span class="pl-c"># the length of the CLASSES might change at some point</span>
<span class="pl-c"># this actually happens elsewhere, but I'm putting this in the same function right here</span>
<span class="pl-s1">cv2</span>.<span class="pl-en">setTrackbarMax</span>(<span class="pl-v">TRACKBAR_NAME</span>, <span class="pl-v">WINDOW_NAME</span>, <span class="pl-en">len</span>(<span class="pl-v">CLASSES</span>) <span class="pl-c1">-</span> <span class="pl-c1">1</span>) 

<span class="pl-c"># keep the window opened for testing</span>
<span class="pl-s1">cv2</span>.<span class="pl-en">waitKey</span>(<span class="pl-c1">0</span>)</pre></div>
<h5 dir="auto">Issue submission checklist</h5>
<ul dir="auto">
<li>[ * ] I report the issue, it's not a question</li>
<li>[ * ] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found solution</li>
<li>[ * ] I updated to latest OpenCV version and the issue is still there</li>
<li>[ * ] There is reproducer code and related data files: videos, images, onnx, etc</li>
</ul>