【问题标题】:EmguCV C# Contour detectionEmguCV C# 轮廓检测
【发布时间】:2021-04-22 15:41:10
【问题描述】:

我需要这部分代码的帮助。选中复选框时,我需要使我的轮廓在黑色背景上可见。但是,当我在复选框中打勾时,我的轮廓消失了。下面的代码和屏幕截图。 [这是我的截图][1]

private Image<Bgr, byte> Find(Image<Bgr, byte> image)
    {
      Image<Gray, byte> outputImage = image.Convert<Gray, byte>().ThresholdBinary(new Gray(100), new Gray(255)); //перевод изображения в серый цвет и уменьшение шума

      VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();

      Mat hierarchy = new Mat();

      CvInvoke.FindContours(outputImage, contours, hierarchy, Emgu.CV.CvEnum.RetrType.Tree, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);

      if (checkBox1.Checked)
      {
        Image<Gray, byte> blackBackground = new Image<Gray, byte>(outputImage.Width, outputImage.Height, new Gray(0));

        CvInvoke.DrawContours(blackBackground, contours, -1, new MCvScalar(255, 0, 0));

        pictureBox2.Image = blackBackground.Bitmap;
      }
      else
      {
        CvInvoke.DrawContours(image, contours, -1, new MCvScalar(255, 0, 0));

        pictureBox2.Image = image.Bitmap;
      }

      return image;
    }


  [1]: https://i.stack.imgur.com/BdtUb.png

【问题讨论】:

  • 我认为 MvcScalar 有一个带 1 个参数的构造函数,也许使用它可以解决问题,因为如果选中该复选框,您实际上是在单通道图像上绘图?
  • 欢迎来到 SO。您应该始终在帖子中呈现您的屏幕截图。请查看hereedit 您的帖子。
  • @GiorgiChkhikvadze 我将 MCvScalar 更改为 1 个参数 (255)。什么都没发生

标签: c# visual-studio emgucv


【解决方案1】:

你为什么不创建一个位图的副本并像这样分配给图片框?

pictureBox2.Image = blackBackground.ToBitmap();

pictureBox2.Image = image.ToBitmap();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-16
    • 2014-07-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多