2016-07-12 108 views
0

我正在使用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; 
} 

回答

0

您可以創建一個簡單的結果對象:

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; 
+0

我做你的想法,但我在main()中出錯。因爲類DrawingResult在由DrawMatches命名的另一個類中寫入。 我該如何解決這個問題。 – Kurd

+0

最簡單的解決方案將'DrawingResult'放入自己的類中。 –

+0

但我的錯誤在main()中。 DrawingResult result = MyClass.Draw(...); – Kurd

相關問題