1 | initial version |
If you take a look at the most recent documentation you can see that you can supply a user defined pointer to an object, defined as a void pointer.
If it handles a single value, you can pass that around using its pointer. If you want to pass multiple data, then you will need to construct a struct and pass all the data with a pointer to the struct. An example is below:
int ref = 1;
createTrackbar("Name","Window",0, 1, myFunc, &ref);
void myFunc(int value, void *userdata)
{
// Retrieve the data
// Needs explicit type declaration
int val = *((int*)&userdata);
}
2 | No.2 Revision |
If you take a look at the most recent documentation you can see that you can supply a user defined pointer to an object, defined as a void pointer.
If it handles a single value, you can pass that around using its pointer. If you want to pass multiple data, then you will need to construct a struct and pass all the data with a pointer to the struct. An example is below:
int ref = 1;
createTrackbar("Name","Window",0, 1, myFunc, &ref);
void myFunc(int value, void *userdata)
{
// Retrieve the data
// Needs explicit type declaration
int val = *((int*)&userdata);
}
And more general you can do it as below
cv:createTrackbar("Label", "Window" &variable, MAX_VAL, &MyClass::func, this);
void MyClass:func(int newValue, void * object) {
MyClass* myClass = (MyClass*) object;
// ...do stuff.
}
3 | No.3 Revision |
If you take a look at the most recent documentation you can see that you can supply a user defined pointer to an object, defined as a void pointer.
If it handles a single value, you can pass that around using its pointer. If you want to pass multiple data, then you will need to construct a struct and pass all the data with a pointer to the struct. An example is below:
int ref = 1;
createTrackbar("Name","Window",0, 1, myFunc, &ref);
void myFunc(int value, void *userdata)
{
// Retrieve the data
// Needs explicit type declaration
int val = *((int*)&userdata);
}
And more general you can do it as below
cv:createTrackbar("Label", "Window" &variable, MAX_VAL, &MyClass::func, this);
void MyClass:func(int newValue, void * object) {
MyClass* myClass = (MyClass*) object;
// ...do stuff.
}
To add multiple variables you will need to create a struct and provide a pointer to that
struct myData{
int variable1 = 0;
int variable2 = 0;
}
void myFunc(int value, void *userdata)
{
// Retrieve the data
// Needs explicit type declaration
myData pushed_data = *((myData*)&userdata);
}
myData test;
test.variable1 = 5;
test.variable2 = 17;
createTrackbar("Name","Window",0, 1, myFunc, &test);
4 | No.4 Revision |
If you take a look at the most recent documentation you can see that you can supply a user defined pointer to an object, defined as a void pointer.
If it handles a single value, you can pass that around using its pointer. If you want to pass multiple data, then you will need to construct a struct and pass all the data with a pointer to the struct. An example is below:
int ref = 1;
createTrackbar("Name","Window",0, 1, myFunc, &ref);
void myFunc(int value, void *userdata)
{
// Retrieve the data
// Needs explicit type declaration
int val = *((int*)&userdata);
}
And more general you can do it as below
cv:createTrackbar("Label", "Window" &variable, MAX_VAL, &MyClass::func, this);
static void MyClass:func(int newValue, void * object) {
MyClass* myClass = (MyClass*) object;
// ...do stuff.
}
To add multiple variables you will need to create a struct and provide a pointer to that
struct myData{
int variable1 = 0;
int variable2 = 0;
}
void myFunc(int value, void *userdata)
{
// Retrieve the data
// Needs explicit type declaration
myData pushed_data = *((myData*)&userdata);
}
myData test;
test.variable1 = 5;
test.variable2 = 17;
createTrackbar("Name","Window",0, 1, myFunc, &test);