如何从另一个 class 获取变量的值
How to get value of a variable from another class
我正在使用 Emgu CV 的 SURF,我使用 int j = CvInvoke.cvCountNonZero(mask);
来查找匹配的对点。
问题如何把return这个值变成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;
}
您可以创建一个简单的结果对象:
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;
我正在使用 Emgu CV 的 SURF,我使用 int j = CvInvoke.cvCountNonZero(mask);
来查找匹配的对点。
问题如何把return这个值变成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;
}
您可以创建一个简单的结果对象:
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;