我正在使用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 :(得分: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;