CvInvoke.DistanceTransform的输出在CvInvoke.Imshow中显示正确,但在ImageBox中显示为黑色

时间:2019-02-12 18:58:22

标签: c# image-processing emgucv euclidean-distance

我试图从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;
        }
    }

0 个答案:

没有答案