opencv


Many sliders with one callback


Is it possible to create some sliders and make one callback for all of them?
I am creating a window, in which i would like to set about 10 parameters. It would be much better to have 1 callback function for all of them instead of 10 functions.
currently i create trackbar like this:
cvCreateTrackbar("Var1","Window",&global_var1, 250, changing_var1);
cvCreateTrackbar("Var2","Window",&global_var2, 250, changing_var2);
and then
void changing_var1(int pos) {
global_var1 = pos;
}
void changing_var2(int pos) {
global_var2 = pos;
}
Is it possible to create one callback that would be albe to change all parameters according to which parameter i want to change?
Yes you should be able to do this (at least with the C++ interface). You will want to utilize the optional userData field. Below is a small example of how you can accomplish 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 that is what you were looking for :)

Related Links

exc_bad_access when using Mat in OpenCV?
Image Retrieval through fisher vectors: why my implementation works SO BAD?
Reduce number of weak classifiers in lower stages. OpenCV cascade classifier
OpenCV cascade classifier training - 1-stage stops
Reprojection of calibrateCamera and projectPoints
How to calculate matrix rank in OpenCV?
GdkGLExt-WARNING **: Window system doesn't support OpenGL
incorrect size of vector when converting Mat to Vector
Mingw doesn't find file strsafe.h while compiling OpenVC library
Opencv image regitsration mask
Detect presence and location of a ball in video with opencv
use of undefined type 'cv::cuda::GpuMat'
Camera Calibration Error Estimation in OpenCv
Using Levenberg-Marquardt optimization algorithm via opencv projectPoints() to estimate Calibration Errors
alternate function for erode to reduce the processing time
OpenCV Python calcOpticalFlowPyrLK returning points out of the camera frame

Categories

HOME
elastic-beanstalk
ssis
codeigniter
matlab
performance
vb.net
actions-on-google
unit-testing
dicom
rtmp
afp
garbage-collection
stack
twitter-digits
encog
jfreechart
ceph
prestashop-1.7
asciidoc
nservicebus
nanotime
lighttpd
resolve
monaco-editor
libssh
jpos
pwm
netlify
effects
python-responses
svgpanzoom
pvlib
background-process
edit-distance
azure-app-service-envrmnt
pdfstamper
fipy
sieve-of-eratosthenes
double-click-advertising
macvim
nio
vtable
amazon-elasticsearch
sagepay
protobuf-3
compass-lucene
using
mobile-browser
freecodecamp
opal
uifont
notimplementedexception
node.js-tape
fasta
catalina
lcov
tachyon
ispconfig
git-config
sizeof
kernighan-and-ritchie
activemodel
ios-frameworks
pddl
pakyow
cucumber-java
screen-capture
relaxng
sqlj
dnx
dbfit
openejb
spymemcached
cocoon-gem
size-t
sql-server-ce-3.5
cordova-cli
centering
vraptor
catalina.out
hobbitmon
tlb
pydatalog
confirmation
jquery-mobile-popup
repeating
nsimageview
virtual-earth
godaddy-api
square-cube
cassette
rc-shell
calloc
teamcity-7.0
bapi
ember-router
android-assets
process.start
combinators
servletunit
myisam
keylogger
iphone-sdk-3.1

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App