createTrackbar warns that value pointer is deprecated. But is there any other way to set trackbar's initial position?

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

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

and