We still don’t know what doesn’t work for you, but I will provide some information on how to use the callback and what user data.
, void* userdata - , / . , , , NULL.
userdata . , , state OpenCV. main().
main(). int state, , , / ( main()).
#include <iostream>
#include <cv.h>
#include <highgui.h>
#include <pthread.h>
#include <string.h>
using namespace cv;
typedef struct custom_data
{
int state;
pthread_mutex_t mtx;
} custom_data_t;
void my_button_cb(int state, void* userdata)
{
std::cout << "@my_button_cb" << std::endl;
custom_data_t* ptr = (custom_data_t*)userdata;
if (!ptr)
{
std::cout << "@my_button_cb userdata is empty" << std::endl;
return;
}
pthread_mutex_lock(&ptr->mtx);
ptr->state = state;
pthread_mutex_unlock(&ptr->mtx);
}
int main()
{
custom_data_t my_data = { 0 };
createButton("dummy_button", my_button_cb, &my_data, CV_PUSH_BUTTON, 0);
getchar();
pthread_mutex_lock(&my_data.mtx);
std::cout << "The state retrieved by the callback is: " << my_data.state << std::endl;
pthread_mutex_unlock(&my_data.mtx);
return 0;
}