The onChange
argument has a default value of 0 (NULL). You do not pass onChange
to cv_createTrackbar
so the default value is used. You attempt to dereference it within your function as *onChange
. Dereferencing a NULL pointer will result in a segmentation fault (core dumped).
The prototype for createTrackbar
is:
int createTrackbar(const string& trackbarname, const string& winname,
int* value, int count, TrackbarCallback onChange=0, void* userdata=0);
And the documentation states:
onChange – Pointer to the function to be called every time the slider changes position. This function should be prototyped as void Foo(int,void*); , where the first parameter is the trackbar position and the second parameter is the user data (see the next parameter). If the callback is the NULL pointer, no callbacks are called, but only value is updated.
Since onChange
is expecting a pointer and the documentation specifically states that NULL is valid, you need to change *onChange
to onChange
. The dereference is not necessary.
Also, change TrackbarCallback*
to TrackbarCallback
for your function arguments. It doesn't need to be a pointer to a pointer.