【问题标题】:How to get value of a variable from another class如何从另一个类中获取变量的值
【发布时间】:2016-07-12 15:12:25
【问题描述】:

我正在使用 Emgu CV 的 SURF,并使用 int j = CvInvoke.cvCountNonZero(mask); 来查找匹配的配对点。 问题如何将这个值返回到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;
}

【问题讨论】:

    标签: c# class surf


    【解决方案1】:

    您可以创建一个简单的结果对象:

    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;
        }
    }
    

    在你的方法中:

    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);
    }
    

    main 方法中:

    DrawingResult result = MyClass.Draw(...);
    int count = result.Count;
    Image<Bgr, Byte> images = result.Images;
    

    【讨论】:

    • 我完成了你的想法,但在 main() 中出现错误。因为DrawMatches类写在另一个类中。我该如何解决这个问题。
    • 最简单的解决方案是将DrawingResult 放在一个自己的类中。
    • 但我在 main() 中的错误。 DrawingResult 结果 = MyClass.Draw(...);
    • 你有而不是MyClass 使用Draw is defined 的类 --> 这意味着DrawingResult result = DrawMatches.Draw(...);
    • 好的。谢谢我的兄弟
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-04
    • 1970-01-01
    相关资源
    最近更新 更多