When I create trackbar by this code
createTrackbar( "Canny thresh:", source_window, &thresh, thresh_max, thresh_callback );
Below warning is reported:
[ WARN:0@0.030] global D:\projects\opencv-src\modules\highgui\src\window.cpp (697) createTrackbar UI/Trackbar(Canny thresh:@Source ): Using ‘value’ pointer is unsafe and deprecated. Use NULL as value pointer. To fetch trackbar value setup callback.
Seems it suggest this way
createTrackbar( "Canny thresh:", source_window, nullptr, thresh_max, thresh_callback );
But I can’t set trackbar’s initial position by this.
Is there other ways to set trackbar position?
1 Like
berak
February 22, 2022, 7:09am
2
use a pattern like:
createTrackbar( "Canny thresh:", source_window, nullptr, thresh_max, thresh_callback );
setTrackbarPos( "Canny thresh:", source_window, thresh);
also, docs:
https://docs.opencv.org/4.x/d7/dfc/group__highgui.html#ga67d73c4c9430f13481fd58410d01bd8d
2 Likes
As your message is first answer in google I give history
opencv:master
← alalek:highgui_backends
opened 09:59PM - 18 May 21 UTC
Goals:
- make external dependencies optional
- allow to select or disable U/I … backend in runtime (to avoid conflicts with application libraries)
- on-demand loading of U/I libraries
<cut/>
```
force_builders=Custom,Linux AVX2,Linux32
build_image:Linux AVX2=ubuntu:20.04
build_image:Custom=qt:16.04
buildworker:Custom=linux-1,linux-2,linux-4,linux-6
```
opened 03:49PM - 25 May 21 UTC
closed 08:18PM - 29 May 21 UTC
bug
category: highgui-gui
Verified in code of master branch, IMHO relevant to most current releases.
Ac… cording to the documentation of [`createTrackbar`](https://docs.opencv.org/4.5.2/d7/dfc/group__highgui.html#gaf78d2155d30b728fc413803745b67a9b) the third parameter to the function is an "Optional pointer to an integer". I read that as "you can pass a nullptr here".
Some HighGUI backends handle this scenario correctly:
* Win32 -- https://github.com/opencv/opencv/blame/master/modules/highgui/src/window_w32.cpp#L2368
* GTK -- https://github.com/opencv/opencv/blob/master/modules/highgui/src/window_gtk.cpp#L1421
* Cocoa -- https://github.com/opencv/opencv/blob/master/modules/highgui/src/window_cocoa.mm#L949
Some consider it an error:
* Qt -- https://github.com/opencv/opencv/blob/master/modules/highgui/src/window_QT.cpp#L1222 (invoked from https://github.com/opencv/opencv/blob/master/modules/highgui/src/window_QT.cpp#L605)
And some apparently dereference it without even checking:
* WINRT -- https://github.com/opencv/opencv/blob/master/modules/highgui/src/window_winrt_bridge.cpp#L274 (invoked from https://github.com/opencv/opencv/blob/master/modules/highgui/src/window_winrt.cpp#L115)
----
Code that should reproduce this (works on Windows, don't have means to test other backends):
```
#include <opencv2/opencv.hpp>
void on_trackbar(int pos, void* userdata)
{
}
int main()
{
auto window_name("Test Window");
cv::namedWindow(window_name);
cv::createTrackbar("Trackbar", window_name, nullptr, 100, on_trackbar);
cv::Mat temp = cv::Mat::zeros(256, 256, CV_8UC1);
cv::imshow(window_name, temp);
cv::waitKey();
return 0;
}
```
----
Reference: https://stackoverflow.com/q/67690257/3962537
and
c++, opencv