简体   繁体   English

如何将位图转换为图像<Bgr, Byte>

[英]How to convert Bitmap to Image<Bgr, Byte>

I am using the OpenCV library for image processing.我正在使用 OpenCV 库进行图像处理。

I want to convert a System.Drawing.Bitmap to an Image<Bgr, Byte> .我想将System.Drawing.Bitmap转换为Image<Bgr, Byte> How can I do this?我怎样才能做到这一点?

Image构造函数有一个Bitmap重载(假设您使用 Emgu CV 包装器,因为您已将其标记为.NET )。

Image<Bgr, Byte> myImage = new Image<Bgr, Byte>(myBitmap); 

在 .NET Emgu.CV 4.4.0.4099我必须安装Emgu.CV.Bitmap 4.4.0.4099Emgu.CV.runtime.windows才能使用bitmap.ToImage<Bgr, byte>()扩展方法。

The constructor for Image<Bgr, byte> no longer accepts Bitmap as parameter. Image<Bgr, byte>的构造函数不再接受Bitmap作为参数。 I had to use the following code for Emgu version 4.3:对于 Emgu 4.3 版,我必须使用以下代码:

Image<Bgr, byte> emguImage = bitmap.ToImage<Bgr, byte>();

I found it on github and in patch notes.我在 github 和补丁说明中找到了它。 The official documentation tutorials were not properly updated.官方文档教程没有正确更新。

I am using Emgu.CV 4.5.1.4349 on NetStandard 2.1 Need to install Emgu.CV.Bitmap and Emgu.CV.runtime.windows in order to convert your Bitmap to Image<Bgr, byte>我在 NetStandard 2.1 上使用 Emgu.CV 4.5.1.4349 需要安装 Emgu.CV.Bitmap 和 Emgu.CV.runtime.windows 以便将您的 Bitmap 转换为 Image<Bgr, byte>

var myImage = myBitmap.ToImage<Bgr, byte>() var myImage = myBitmap.ToImage<Bgr, byte>()

for whom to be concern: you should add dependency dll into project and change 'copy to output directory' property to 'copy always' (add -> existing item) from Emgu\\emgucv-windows-universal-cuda 2.9.0.1922\\bin\\x86需要关注的对象:您应该将依赖项 dll 添加到项目中,并将 Emgu\\emgucv-windows-universal-cuda 2.9.0.1922\\bin\\ 中的“复制到输出目录”属性更改为“始终复制”(添加 -> 现有项目) x86

in my project add : opencv_core290.dll , opencv_highgui290.dll , opencv_ffmpeg290.dll , opencv_imageproc290.dll and cudart32_55.dll在我的项目中添加: opencv_core290.dll 、 opencv_highgui290.dll 、 opencv_ffmpeg290.dll 、 opencv_imageproc290.dll 和 cudart32_55.dll

from: The type initializer for 'Emgu.CV.CvInvoke' threw an exception来自: “Emgu.CV.CvInvoke”的类型初始值设定项引发异常

I'm using Emgu 4.3.0.3890 and I had the same problem I integrated my code with my team.我正在使用 Emgu 4.3.0.3890,但在将代码与我的团队集成时遇到了同样的问题。 The line that gave me trouble was:给我带来麻烦的那一行是:

Image<Bgr, byte> img = bitmap.ToImage<Bgr, byte>();

I didn't see that the build created two new directories named x86 and x64.我没有看到构建创建了两个名为 x86 和 x64 的新目录。 When I discovered it, I added these two directories to the location of my binary files and every thing worked.当我发现它时,我将这两个目录添加到我的二进制文件的位置,并且一切正常。 I didn't have the time to to elimination to see which one of the files in these directories is responsible for it but hey, it worked.我没有时间消除以查看这些目录中的哪个文件对此负责,但是,嘿,它起作用了。 :-) :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM