我试图从EmguCV的ImageBox控件中显示名为“ CvInvoke.DistanceTransform”的函数的输出Mat,但是输出显示黑色图像。 但是,如果我将输出传递给“ CvInvoke.Imshow”函数,则输出显示正确。
我的问题是如何在ImageBox中显示DistanceTransform的输出?
我的代码:
public static Mat EuclideanDistanceTransfer(Mat Image)
{
Mat dist = new Mat();
Mat labels = new Mat();
CvInvoke.DistanceTransform(Image, dist, labels, DistType.L2, 3);
CvInvoke.Normalize(dist, dist, 0, 1.0, NormType.MinMax);
CvInvoke.Imshow("Image", dist); //This will shows the output correclty
return dist;
}
private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
txtPath.Text = openFileDialog.FileName;
Image<Bgr, byte> FrontImage = new Image<Bgr, byte>(txtPath.Text);
imgFrontOriginal.Image = FrontImage;
Mat FrontGrayImage = ImageOperations.ConvertToGray(FrontImage.Mat).Clone();
Mat FrontBinaryImage = ImageOperations.ConvertToBinary(FrontGrayImage, 200).Clone();
Mat InvertedBinaryImage = new Image<Gray, byte>(ImageOperations.Invert(FrontBinaryImage.Bitmap)).Mat;
imgFrontBinary.Image = InvertedBinaryImage;
Mat FrontTransferImage = ImageOperations.EuclideanDistanceTransfer(InvertedBinaryImage);
//In this line will shows only black image, why? and how to solve it?
imgFrontTransfer.Image = FrontTransferImage;
}
}