0

I am using Emgu CV's SURF and I used int j = CvInvoke.cvCountNonZero(mask); to find matched pair points. The problem how to return this value into main()?

...
...
...
public static Image<Bgr, Byte> Draw(Image<Gray, Byte> modelImage, Image<Gray, byte> observedImage, out long matchTime)      
{
    HomographyMatrix homography;
    VectorOfKeyPoint modelKeyPoints;
    VectorOfKeyPoint observedKeyPoints;
    Matrix<int> indices;
    Matrix<byte> mask;

    FindMatch(modelImage, observedImage, out matchTime, out modelKeyPoints, out observedKeyPoints, out indices, out mask, out homography);

    //Draw the matched keypoints
    Image<Bgr, Byte> result = Features2DToolbox.DrawMatches(modelImage, modelKeyPoints, observedImage, observedKeyPoints, indices, new Bgr(255, 255, 255), new Bgr(255, 255, 255), mask, Features2DToolbox.KeypointDrawType.DEFAULT);

    int j = CvInvoke.cvCountNonZero(mask);
    return result;
}
Kurd
  • 11
  • 6

1 Answers1

0

You can create a simple result object:

public class DrawingResult {
    public Image<Bgr, Byte> Images { get; private set; }
    public int Count {get; private set; }

    public DrawingResult(Image<Bgr, Byte> images, int count) {
       Images = images;
       Count = count;
    }
}

And in your method:

public static DrawingResult Draw(Image<Gray, Byte> modelImage, Image<Gray, byte> observedImage, out long matchTime)
{
    HomographyMatrix homography;
    VectorOfKeyPoint modelKeyPoints;
    VectorOfKeyPoint observedKeyPoints;
    Matrix<int> indices;
    Matrix<byte> mask;

    FindMatch(modelImage, observedImage, out matchTime, out modelKeyPoints, out observedKeyPoints, out indices, out mask, out homography);

    //Draw the matched keypoints
    Image<Bgr, Byte> result = Features2DToolbox.DrawMatches(modelImage, modelKeyPoints, observedImage, observedKeyPoints,
       indices, new Bgr(255, 255, 255), new Bgr(255, 255, 255), mask, Features2DToolbox.KeypointDrawType.DEFAULT);

    int j = CvInvoke.cvCountNonZero(mask);
    return new DrawingResult(result, j);
}

And in the main method:

DrawingResult result = MyClass.Draw(...);
int count = result.Count;
Image<Bgr, Byte> images = result.Images;
wake-0
  • 3,918
  • 5
  • 28
  • 45
  • I done your idea, but I got error in main(). Because class DrawingResult wrote in another class named by DrawMatches. How can I solve this problem. – Kurd Jul 12 '16 at 16:00
  • Easiest solution put the `DrawingResult` in an own class. – wake-0 Jul 12 '16 at 16:17
  • but my error in the main(). DrawingResult result = MyClass.Draw(...); – Kurd Jul 12 '16 at 16:43
  • you have instead of `MyClass` use the class where `Draw is defined` --> which means `DrawingResult result = DrawMatches.Draw(...);` – wake-0 Jul 12 '16 at 17:52
  • OK. Thank you my brother – Kurd Jul 14 '16 at 11:50
  • Sorry, I did not know, because I am newer in stackoverflow. Can you help me in the following question: [How to convert datatype of (Matrix) to (array)](http://stackoverflow.com/questions/38369572/how-to-convert-matrixfloat-to-array) – Kurd Jul 14 '16 at 13:11