title: How is the callback function called in this OpenCV example?
body: <p>I started reading <em>Learning OpenCV 3</em> but since I haven't programmed much in c++ I am confused by the way of using a callback function in the following code snippet:</p>
  
  <pre><code>int g_slider_position = 0;
  int g_run = 1, g_dontset = 0;
  cv::VideoCapture g_cap;
  
  void onTrackBarSlide(int pos, void *)
  {
      g_cap.set(CV_CAP_PROP_POS_FRAMES, pos);
      if (!g_dontset) g_run = 1;
      g_dontset = 0;
  }
  
  int main(int argc, char** argv)
  {
      g_cap.open(std::string(argv[1]));
  
      int frames = (int)g_cap.get(CV_CAP_PROP_FRAME_COUNT);
  
      cv::createTrackbar(
          "Position",
          "Example 2-4",
          &amp;g_slider_position,
          frames,
          onTrackBarSlide
      );
      cv::Mat frame;
      for (;;)
      {
          if (g_run != 0)
          {
              g_cap &gt;&gt; frame;
              if (frame.empty())
              {
                  break;
              }
              int current_pos = (int)g_cap.get(CV_CAP_PROP_POS_FRAMES);
              g_dontset = 1;
              cv::setTrackbarPos("Position", "Example 2-4", current_pos);
              cv::imshow("Example 2-4", frame);
              g_run -= 1;
          }
  
          char c = (char)cv::waitKey(10);
  
          if (c == 's')
          {
              g_run = 1;
          }
  
          if (c == 'r')
          {
              g_run = -1;
          }
      }
      return 0;
  }
  </code></pre>
  
  <p>What I gather from this is that pressing somewhere on the <em>Trackbar</em> raises an event that calls <code>onTrackBarSlide</code>. </p>
  
  <p>What I'm wondering there is where do the <code>int pos</code> argument come from? I couldn't find it on the function documentation.</p>
  
  <p>When I step through this program <code>onTrackBarSlide</code> is called after <code>setTrackbarPos</code>. This confuses me and makes me think that <code>setTrackbarPos</code> is just raising an event with <code>current_pos</code> as the argument that <code>onTrackBarSlide</code> listens for. </p>
  
  <p>But why couldn't it be done more directly by having <code>setTrackbarPos</code> call <code>g_cap.set</code> directly?</p>