Reputation: 975
I'm using createTrackbar(const string& trackbarname, const string& winname, int* value, int count, TrackbarCallback onChange=0, void* userdata=0)
in openCV to get an input value, which needs to be a double in the range between 0 and 1. I can easily calculate the needed value from the trackbar position, but obviously the GUI only shows the int-value for the slider, which is a little bit irritating.
Is there any way to change the value the trackbar shows? I can't find any information about this in the documentation or tutorials...
Upvotes: 3
Views: 6670
Reputation: 1642
Like already stated, this is not possible. Here is a little wrapper which calculates double values for you conveniently:
class DoubleTrack{
public:
int int_value = 0;
double precision;
void(*user_callback)(double);
void setup(const std::string& field_name, const std::string& window_name, void(*function)(double), double max_value, double default_value = 0, unsigned precision = 100){
int_value = default_value * precision;
createTrackbar(field_name, window_name, &int_value, max_value * precision, DoubleTrack::callback, this);
user_callback = function;
this->precision = precision;
}
static void callback(int, void* object){
DoubleTrack* pObject = static_cast<DoubleTrack*>(object);
pObject->user_callback(pObject->int_value / pObject->precision);
}
};
static void test(double value){
std::cout << value << std::endl;
}
DoubleTrack().setup("field_name", "window_name", test, 4.5);
Upvotes: 0
Reputation: 4074
AFAIK there is not possibility to pass double or other floating point value but still if you are okay let's say with 0.001 precision you can create a trackbar with max value 1000 and then simply treat its value as a double betwen 0 and 1 by dividing trackbar value by max value.
Upvotes: 0
Reputation: 3858
No, there is not. Unfortunately, the way the trackbar is implemented (with or without Qt) it does not support that.
Upvotes: 4