-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
Handling of 'value' in cv2.createTrackbar in Python #20408
Copy link
Copy link
Closed
Milestone
Description
System information (version)
- OpenCV == 4.5.3.56 (latest)
- Operating System / Platform => Windows 10 Pro
- Compiler => Python 3.7
Detailed description
After updating to the most recent version of opencv-contrib-python, now when creating a trackbar using
cv2.createTrackbar(TRACKBAR_NAME, WINDOW_NAME, 0, MAX_VAL, on_trackbar_foo)the following warning is printed in the terminal:
[ 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 callbackI'm not exactly sure what that means in the context of the Python API.
Furthermore, if I then try to dynamically change the maximum value of the trackbar like this
cv2.setTrackbarMax(TRACKBAR_NAME, WINDOW_NAME, N)the trackbar itself is now stuck at 0 (or whatever the minimum is set to) and cannot be moved with the mouse cursor.
This used to be fine in the previous versions. For example, it works fine in 4.5.2.52.
Steps to reproduce
Just creating a trackbar in Python using a most recent version of OpenCV, e.g. in my case:
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 = ["head", "left_hand", "right_hand", "right_leg", "left_leg"]
# 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 = "Navigation controls"
cv2.namedWindow(WINDOW_NAME, cv2.WINDOW_AUTOSIZE)
# create trackbar
TRACKBAR_NAME = 'Class'
max_classes = (len(CLASSES) - 1) if len(CLASSES) > 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)Issue submission checklist
- [ * ] I report the issue, it's not a question
- [ * ] I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found solution
- [ * ] I updated to latest OpenCV version and the issue is still there
- [ * ] There is reproducer code and related data files: videos, images, onnx, etc
Reactions are currently unavailable