Emgucv C# Image Stabilization

1.4k Views Asked by At

I have two successive images which I want to stabilize using EmguCv in C#.

I found much information on how to perform image stabilization, however I could not find any detailed explanation on how to use Emgu to stabilize two successive frames (Actual code expmples).

I understand that I have to do the following:

  1. Calculate the good features on the first frame by using the GFTTDetector() and get the Good feature points of the first Image (GFP1).
  2. Then I need to compute the Optical flow using the CvInvoke.CalcOpticalFlowPyrLK() to get the good feature points of the second image (GFP2).
  3. With the GFP1 & GFP2 I can calculate the Homography matrix with the CvInvoke.cvFindHomography() function.
  4. Finally I have to use the CvInvoke.cvWarpPerspective() to stabilize the frame.

So based on the above I tried to perform Image stabilization.

I have the two successive frames :

Image<Gray, ushort> FirstImage = new Image<Gray, ushort>(Width, Height);
Image<Gray, ushort> SecondImage= new Image<Gray, ushort>(Width, Height);

The I tried to calculate the good features:

Emgu.CV.Features2D.GFTTDetector _GFTTdetector = new Emgu.CV.Features2D.GFTTDetector(500,0.05);
var GFP1 = _GFTTdetector.Detect(FirstImage);

However when I call the .Detect I get an OpenCV exception and I cannot proceed:

$exception {"OpenCV: scn == 3 || scn == 4"} Emgu.CV.Util.CvException

Does anybody knows why I get this exception?

In addition I would appreciate if someone could post a sample code of how to use the following functions because I am not sure about what input arguments I shall use:

  • CvInvoke.CalcOpticalFlowPyrLK()
  • CvInvoke.cvFindHomography()
  • CvInvoke.cvWarpPerspective()

Lastly _GFTTdetector.Detect() returns a KeyPoint[] type, however the CvInvoke.CalcOpticalFlowPyrLK() accepts only PointF[] arguments for the good points. How I can convert the KeyPoint[] to PointF[]?

0

There are 0 best solutions below