Where are we getting the value of this parameter?
In a program in the Learning OpenCV
book:
void onTrackbarSlide(int pos)
{
cvSetCaptureProperty(g_capture,CV_CAP_PROP_POS开发者_如何转开发_FRAMES,pos);
}
And, in another location:
if(frames!=0)
{
cvCreateTrackbar("Position","Example3",&g_slider_position,frames,onTrackbarSlide);
}
Where are we retrieving the value of pos
in the onTrackSlide(int pos)
function from? What value will be passed to it from cvCreateTrackbar()
?
I don't know OpenCV - but it looks like onTrackbarSlide
is some sort of event handler, so it is passed a value of pos from the trackbar UI that you are creating.
There is no value of pos directly passed from cvCreateTrackbar()
- that looks like it creates your trackbar UI, and then if interacted with by the user will call onTrackBarSlide
.
Check the docs and you'll see the function signature is:
cvCreateTrackbar(const char* trackbarName, const char* windowName, int* value, int count, CvTrackbarCallback onChange)
Notice that the last parameter has the type CvTrackbarCallback
. Obviously, this is not a built-in type, but a type defined by OpenCV. So we go back to the documentation to find more about it and interestingly enough, this information shows up:
The function cvCreateTrackbar() creates a trackbar (a.k.a. slider or range control) with the specified name and range, assigns a variable to be syncronized with trackbar position and specifies a callback function to be called on trackbar position change.
And right below this paragraph, you can see how a CvTrackbarCallback
should be declared:
CV_EXTERN_C_FUNCPTR( void (*CvTrackbarCallback)(int pos) );
To summarize, in order to call cvCreateTrackbar()
you need to declared a function with the signature void some_fun(int pos)
, to be able to be notified by OpenCV when the slider of the trackbar is updated. The argument int pos
informs the new position of the slider.
精彩评论