title: Saving and using the coordinates of clicked mouse on real-time using opencv/ C++
body: <p>I am new to C++ and opencv, I am trying to use the coordinates of the clicked mouse and later track that object using Kalman filter. </p>
  
  <p>The problem is I can't access the x and y coordinate of the mouse clicking on the object in real time video. </p>
  
  <p>There are lots of codes which show how to do it but it didnt work for me.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>void CallBackFunc(int event, int x, int y, int flags, void* leftCoordinate){
     Point *p = (Point*) leftCoordinate;
     if  ( event == EVENT_LBUTTONDOWN )
     {
          cout &lt;&lt; "Left button position (" &lt;&lt; x &lt;&lt; ", " &lt;&lt; y &lt;&lt; ")" &lt;&lt; endl;
          p-&gt;x = x;
          p-&gt;y = y;
          cout &lt;&lt; "this is the pointer  : " &lt;&lt; *p &lt;&lt; endl;
     }
  }
  
  int main(int argc, const char** argv )
  {
          // Getting the video here
  
          Point TestP;
          setMouseCallback("Original", CallBackFunc, &amp;TestP);
  
          cout &lt;&lt; "The coordinates : x = " &lt;&lt; TestP.x &lt;&lt; " y = " &lt;&lt; TestP.y &lt;&lt; endl;
  }
  </code></pre>
  
  <p>The problem is, TestP is always empty and I need to use that x and y coordinate in my main.</p>
  
  <p>I really appreciate any help. Thanks</p>