【问题标题】:how to read image from a picturebox in EMGU CV如何从 EMGU CV 中的图片框中读取图像
【发布时间】:2018-04-18 15:26:24
【问题描述】:

我正在尝试从图片框中读取图像以使用 EMGU 执行特征匹配。下面是我从示例项目中获得的代码。

        Bitmap img = new Bitmap(pictureBox1.Image);
        Image<Bgr, byte> imgInput = new Image<Bgr, byte>(img);

        using (Mat modelImage = CvInvoke.Imread("C:\\model.jpg", ImreadModes.Color)) //works
        using (Mat observedImage = CvInvoke.Imread(imgInput, ImreadModes.Color)) //doesn't work
        {
            Mat result = DrawMatches.Draw(modelImage, observedImage, out matchTime);
            ImageViewer.Show(result, String.Format("Matched in {0} milliseconds", matchTime));

        }

当我给出 CvInvoke.ImRead 的路径时,它可以工作,但是如果我创建一个位图并将该位图用作图像,它会给出一个错误,指出 CvInvoke.ImRead 有一些无效参数。

如何从图片框中读取图像?

【问题讨论】:

    标签: c# image-processing emgucv


    【解决方案1】:

    CvInvoke.Imread 方法只能用于读取文件。第一个参数必须是字符串形式的文件名。所以你可以修改你的代码如下:

        Bitmap img = new Bitmap(pictureBox1.Image);
        Image<Bgr, byte> imgInput = new Image<Bgr, byte>(img);
    
        using (Mat modelImage = CvInvoke.Imread("C:\\model.jpg", ImreadModes.Color)) //works
        using (Mat observedImage = new Image<Bgr, byte>(img).Mat) //works too
        {
            Mat result = DrawMatches.Draw(modelImage, observedImage, out matchTime);
            ImageViewer.Show(result, String.Format("Matched in {0} milliseconds", matchTime));
    
        }
    

    【讨论】:

      猜你喜欢
      • 2019-08-25
      • 1970-01-01
      • 2012-04-02
      • 2021-07-06
      • 2011-06-24
      • 1970-01-01
      • 2015-07-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多