Yes, you should do this (at least with the C ++ interface). You will want to use the optional userData field. Below is a small example of how you can do this:
#include <opencv2/highgui/highgui.hpp> #include <iostream> using namespace std; using namespace cv; struct ColorThresholdData { int redHigh; int redLow; }; enum ColorThresholdType { RED_HIGH, RED_LOW }; void fooCallback(int value, void* colorThreshold); struct ColorThresholdData data; int main(int argc, char** argv) { ... createTrackbar("red high", windowName, NULL, 255, fooCallback, new ColorThresholdType(RED_HIGH)); createTrackbar("red low", windowName, NULL, 255, fooCallback, new ColorThresholdType(RED_LOW)); ... } void fooCallback(int value, void* colorThreshold) { ColorThresholdType* ct = reinterpret_cast<ColorThresholdType*>(colorThreshold); switch(*ct) { case RED_HIGH: cout << "Got RED_HIGH value" << endl; data.redHigh = value; break; case RED_LOW: cout << "Got RED_LOW value" << endl; data.redLow = value; break; } }
Hope this is what you were looking for :)
source share