0

I am kind new with emgucv and optical flow. I am trying to recognize object in motion on video and draw around them circle or rectangle or some other shape. I must use opticalflow.HS and opticalflow.LK. That is the first thing I want to do. I am using emgu cv 2.4.9.I have some code, but it is just some thinking. I red previous frame and current frame and sent it to opticalflow.HS but I don't know what to do after that and I can't find any example using HS, so I would really appreciate same example what to do next after opticalflow.HS and also some advice.

  private void ProcessFrame(object sender, EventArgs e)
  {
      bool firstFrame = true;
      bool keepProcessing = true;

      Image<Gray, Byte> nextFrame = new Image<Gray, byte>(160, 640);
      Image<Gray, Byte> previousFrame = null;

      while (keepProcessing)
      {
          // ****** Change - Save previous frame before getting next one
          // Only do this if the first frame has passed
          if (!firstFrame)
              previousFrame = nextFrame.Clone();

          // grab the next frame from video source
         // _capture.Grab();

          // decode and return the grabbed video frame
          nextFrame = _capture.RetrieveGrayFrame();

          // if the frame is valid (not end of video for example)
          if (!(nextFrame==null))
          {
              // **** Change - If we are on the first frame, only show that and
              // set the flag to false
              if (firstFrame)
              {
                  firstFrame = false;

              }
              else
              {
                  Image<Gray, float> velx = new Image<Gray, float>(previousFrame.Size);
                  Image<Gray, float> vely = new Image<Gray, float>(nextFrame.Size);
                  OpticalFlow.HS(previousFrame, nextFrame, true, velx, vely, 0.1d, new MCvTermCriteria(100));
                  //capturedImageBox.Image = nextFrame;

              }
          }
          else
          {
              keepProcessing = false;
          }
      }
vale
  • 1
  • 1
  • 5

1 Answers1

0

OpticalFlow.HS Method is computes flow for every pixel of the first input image using Horn & Schunck algorithm.

After that, I suggest you should dense optical flow drawing. Hope so help you.

Go to link.

Ave
  • 4,338
  • 4
  • 40
  • 67