2016-07-12 1 views
0

J'utilise le SURF d'Emgu CV et j'ai utilisé int j = CvInvoke.cvCountNonZero(mask); pour trouver des paires appariées. Le problème comment retourner cette valeur dans main()?Comment obtenir la valeur d'une variable d'une autre classe

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

Répondre

0

Vous pouvez créer un simple objet de résultat:

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

Et dans votre méthode:

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

Et dans la méthode main:

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

Je fait votre idée , mais j'ai une erreur dans main(). Parce que la classe DrawingResult a écrit dans une autre classe nommée par DrawMatches. Comment puis-je résoudre ce problème. – Kurd

+0

La solution la plus simple a mis le DrawingResult dans sa propre classe. –

+0

mais mon erreur dans le main(). Résultat DrawingResult = MyClass.Draw (...); – Kurd