Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The callback function must be static or global, but you can pass it a reference to an object you want to operate on (see <a href="http://opencv-users.1802565.n2.nabble.com/Member-function-callback-in-cvCreateTrackbar-td3785481.html" rel="noreferrer">this post</a> on the OpenCV Users mailing list).</p> <p>The <a href="http://opencv.willowgarage.com/documentation/cpp/user_interface.html#cv-createtrackbar" rel="noreferrer">createTrackbar</a> method has a <code>userdata</code> parameter which is passed to the calling function. In C there is an undocumented <code>cvCreateTrackbar2</code> method, defined in <code>highgui_c.h</code>, which has the same functionality:</p> <pre><code>CVAPI(int) cvCreateTrackbar2( const char* trackbar_name, const char* window_name, int* value, int count, CvTrackbarCallback2 on_change, void* userdata CV_DEFAULT(0)); </code></pre> <p>These methods let you create a class with a static callback function that takes a pointer to an object of that class. You can create the trackbar like so:</p> <pre><code>cv:createTrackbar("Label", "Window" &amp;variable, MAX_VAL, &amp;MyClass::func, this); </code></pre> <p>The callback would look something like this:</p> <pre><code>void MyClass:func(int newValue, void * object) { MyClass* myClass = (MyClass*) object; // ...do stuff. } </code></pre> <p>Note that you don't need to explicitly update the variable yourself as long as you provided a pointer to it when creating the trackbar (as above), but if you need to process it first I suggest you set it explicitly in the callback function.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload