【发布时间】: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 个参数的构造函数,也许使用它可以解决问题,因为如果选中该复选框,您实际上是在单通道图像上绘图?
-
@GiorgiChkhikvadze 我将 MCvScalar 更改为 1 个参数 (255)。什么都没发生
标签: c# visual-studio emgucv