简体   繁体   中英

How to convert Bitmap to Image<Bgr, Byte>

I am using the OpenCV library for image processing.

I want to convert a System.Drawing.Bitmap to an 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. I had to use the following code for Emgu version 4.3:

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

I found it on github and in patch notes. 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>

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

in my project add : opencv_core290.dll , opencv_highgui290.dll , opencv_ffmpeg290.dll , opencv_imageproc290.dll and cudart32_55.dll

from: The type initializer for 'Emgu.CV.CvInvoke' threw an exception

I'm using Emgu 4.3.0.3890 and I had the same problem I integrated my code with my team. 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. 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. :-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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