diff --git a/apps/createsamples/utility.cpp b/apps/createsamples/utility.cpp index b57d3fcb81..87ba4eac5a 100644 --- a/apps/createsamples/utility.cpp +++ b/apps/createsamples/utility.cpp @@ -766,7 +766,6 @@ CvBackgroundData* icvCreateBackgroundData( const char* filename, Size winsize ) } if( count > 0 ) { - //rewind( input ); fseek( input, 0, SEEK_SET ); datasize += sizeof( *data ) + sizeof( char* ) * count; data = (CvBackgroundData*) fastMalloc( datasize ); @@ -872,8 +871,6 @@ void icvGetNextFromBackgroundData( CvBackgroundData* data, reader->src = img; - //reader->offset.x = round % data->winsize.width; - //reader->offset.y = round / data->winsize.width; reader->offset = offset; reader->point = reader->offset; reader->scale = MAX( diff --git a/modules/highgui/include/opencv2/highgui.hpp b/modules/highgui/include/opencv2/highgui.hpp index 35b64bceae..dec9af5b46 100644 --- a/modules/highgui/include/opencv2/highgui.hpp +++ b/modules/highgui/include/opencv2/highgui.hpp @@ -531,16 +531,20 @@ control panel. Clicking the label of each trackbar enables editing the trackbar values manually. @param trackbarname Name of the created trackbar. -@param winname Name of the window that will be used as a parent of the created trackbar. -@param 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. -@param count Maximal position of the slider. The minimal position is always 0. -@param onChange Pointer to the function to be called every time the slider changes position. 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. -@param userdata User data that is passed as is to the callback. It can be used to handle trackbar -events without using global variables. +@param winname Name of the window that will contain the trackbar. +@param value Pointer to the integer value that will be changed by the trackbar. +Pass `nullptr` if the value pointer is not used. In this case, manually handle +the trackbar position in the callback function. +@param count Maximum position of the trackbar. +@param onChange Pointer to the function to be called every time the slider changes position. +This function should have the prototype 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 a nullptr, no callbacks are called, but the trackbar's value will still be +updated automatically. +@param userdata Optional user data that is passed to the callback. +@note If the `value` pointer is `nullptr`, the trackbar position must be manually managed. +Call the callback function manually with the desired initial value to avoid runtime warnings. +@see #tutorial_trackbar */ CV_EXPORTS int createTrackbar(const String& trackbarname, const String& winname, int* value, int count, diff --git a/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp b/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp index 82bbb3743a..3650b15dea 100644 --- a/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp +++ b/samples/cpp/tutorial_code/HighGUI/AddingImagesTrackbar.cpp @@ -27,12 +27,12 @@ Mat dst; * @function on_trackbar * @brief Callback for trackbar */ -static void on_trackbar( int, void* ) -{ - alpha = (double) alpha_slider/alpha_slider_max ; - beta = ( 1.0 - alpha ); - addWeighted( src1, alpha, src2, beta, 0.0, dst); - imshow( "Linear Blend", dst ); +static void on_trackbar(int pos, void* userdata) { + (void) userdata; + alpha = (double)pos / alpha_slider_max; + beta = (1.0 - alpha); + addWeighted(src1, alpha, src2, beta, 0.0, dst); + imshow("Linear Blend", dst); } //![on_trackbar] @@ -40,34 +40,35 @@ static void on_trackbar( int, void* ) * @function main * @brief Main function */ -int main( void ) +int main(void) { - //![load] - /// Read images ( both have to be of the same size and type ) - src1 = imread( samples::findFile("LinuxLogo.jpg") ); - src2 = imread( samples::findFile("WindowsLogo.jpg") ); - //![load] + //![load] + /// Read images (both must be of the same size and type) + src1 = imread(samples::findFile("LinuxLogo.jpg")); + src2 = imread(samples::findFile("WindowsLogo.jpg")); + //![load] - if( src1.empty() ) { cout << "Error loading src1 \n"; return -1; } - if( src2.empty() ) { cout << "Error loading src2 \n"; return -1; } + if (src1.empty()) { cout << "Error loading src1 \n"; return -1; } + if (src2.empty()) { cout << "Error loading src2 \n"; return -1; } - /// Initialize values - alpha_slider = 0; + // Initialize trackbar value + alpha_slider = 0; - //![window] - namedWindow("Linear Blend", WINDOW_AUTOSIZE); // Create Window - //![window] + //![window] + namedWindow("Linear Blend", WINDOW_AUTOSIZE); //Create Window + //![window] - //![create_trackbar] - char TrackbarName[50]; - snprintf( TrackbarName, sizeof(TrackbarName), "Alpha x %d", alpha_slider_max ); - createTrackbar( TrackbarName, "Linear Blend", &alpha_slider, alpha_slider_max, on_trackbar ); - //![create_trackbar] + //![create_trackbar] + char TrackbarName[50]; + snprintf(TrackbarName, sizeof(TrackbarName), "Alpha x %d", alpha_slider_max); + // Example userdata: Pass a pointer to an integer as userdata + createTrackbar(TrackbarName, "Linear Blend", &alpha_slider, alpha_slider_max, on_trackbar); + //![create_trackbar] - /// Show some stuff - on_trackbar( alpha_slider, 0 ); + /// Show initial result + on_trackbar(alpha_slider, nullptr); - /// Wait until user press some key - waitKey(0); - return 0; + /// Wait for user input + waitKey(0); + return 0; }