title: Point Tracking using Optical Flow
body: <p>Hello I'm trying to apply point tracking to a scene. </p>
  
  <p>Now I want to get the points only moving in horizontally. Anyone have any thoughts on this?
  The arrays "Actual" and "nextfeature" contain the relevant x,y coordinates. I tried to get the difference from the two arrays, it did not work. I tried to get the optical flow using Farneback but it didn't gave me a satisfying result. I would really appreciate if anyone can give me any thoughts on how to get the points only moving in horizontal line. </p>
  
  <p>thanks.</p>
  
  <p>Here is the code.</p>
  
  <pre><code>    private void ProcessFrame(object sender, EventArgs arg)
      {
  
  
          PointF[][] Actual = new PointF[0][];
  
          if (Frame == null) 
          {
  
              Frame = _capture.RetrieveBgrFrame();
  
              Previous_Frame = Frame.Copy();
  
          }
  
          else
          {
  
              Image&lt;Gray, byte&gt; grayf = Frame.Convert&lt;Gray, Byte&gt;();
  
              Actual = grayf.GoodFeaturesToTrack(300, 0.01d, 0.01d, 5);
  
  
              Image&lt;Gray, byte&gt; frame1 = Frame.Convert&lt;Gray, Byte&gt;();
              Image&lt;Gray, byte&gt; prev = Previous_Frame.Convert&lt;Gray, Byte&gt;();
              Image&lt;Gray, float&gt; velx = new Image&lt;Gray, float&gt;(Frame.Size);
              Image&lt;Gray, float&gt; vely = new Image&lt;Gray, float&gt;(Previous_Frame.Size);
  
  
  
              Frame = _capture.RetrieveBgrFrame().Resize(300,300,Emgu.CV.CvEnum.INTER.CV_INTER_AREA);
  
              Byte []status;
              Single[] trer;
              PointF[][] feature = Actual;
              PointF[] nextFeature = new PointF[300];
  
  
  
              Image&lt;Gray, Byte&gt; buf1 = new Image&lt;Gray, Byte&gt;(Frame.Size);
              Image&lt;Gray, Byte&gt; buf2 = new Image&lt;Gray, Byte&gt;(Frame.Size);
              opticalFlowFrame = new Image&lt;Bgr, Byte&gt;(prev.Size);
  
              Image&lt;Bgr, Byte&gt;  FlowFrame = new Image&lt;Bgr, Byte&gt;(prev.Size);
  
  
              OpticalFlow.PyrLK(prev, frame1, Actual[0], new System.Drawing.Size(10, 10), 0, new MCvTermCriteria(20, 0.03d),
                       out nextFeature, out status, out trer);
  
  
  
  
              for (int x = 0; x &lt; Actual[0].Length ; x++)
              {
                  opticalFlowFrame.Draw(new CircleF(new PointF(nextFeature[x].X, nextFeature[x].Y), 1f), new Bgr(Color.Blue), 2);
  
              }
  
              new1 = old;
              old = nextFeature;
  
              Actual[0] = nextFeature;
  
  
  
              Previous_Frame = Frame.Copy();
              captureImageBox.Image = Frame;
              grayscaleImageBox.Image = opticalFlowFrame;
  
  
              //cannyImageBox.Image = velx;
  
              //smoothedGrayscaleImageBox.Image = vely;
          }
      }
  </code></pre>