I'm trying to convert a bitmap to mat to use for OpenCV. But for some reason they wouldn't let me convert it. I found the code below here on Stack and seen it on many other sites as well.
Does anyone here have an idea why it doesn't work?
Cannot convert "System.Drawing.Bitmap" to "byte[ , , ]".
Just as a note, at the beginning 8 screenshots are taken of set coordinates, these are saved as a bitmap and should then be converted to mat.
Please take a look at the embedded image.
public static Image<Bgr, byte> FromFile = new Image<Bgr, byte>("MyImage.jpg");
Mat mat = FromFile.Mat; // Only a way to convert it succesfull,
// but isnt the way i want to go.
public static Bitmap skillQ;
public static Image<Bgr, byte> FromBitmap = new Image<Bgr, byte>(skillQ).ToImage;
Mat mat2 = FromBitmap.Mat;
//public static Image<Bgr, byte> FromBitmap = new Image<Bgr, byte>(skillQ).ToImage;
This Image shows the Error Message.
First of all, you are not converting your image into a Mat
but into a Image<>
(more info about the difference and what a Mat is here ).
To convert any image from file into a Mat
you can simply use the following:
Mat fromFile = new Mat("test.bmp");
To convert a Bitmap
to Mat
you can install the NuGet Emgu.CV.Bitmap
that add some extensions to faclitate the conversion to Bitmap
.
Bitmap bitmapTest = fromFile.ToBitmap();
Mat fromBitmap = bitmapTest.ToMat();
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.