question

AhmedWassimBENSALEMENISo-3626 avatar image
0 Votes"
AhmedWassimBENSALEMENISo-3626 asked AhmedWassimBENSALEMENISo-3626 commented

Convert int/byte[] or Bitmap to the Mat type of openCv

Hello Guys , is there any way to convert array or bitmap or whatever to The type Mat of openCv ..
I have a image object and i want to make usable for openCv , so first i need to convert it to Mat

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

DanielZhang-MSFT avatar image
0 Votes"
DanielZhang-MSFT answered AhmedWassimBENSALEMENISo-3626 commented

Hi AhmedWassimBENSALEMENISo-3626,
To use OpenCvSharp, you need to add both OpenCvSharp4 and OpenCvSharp4.runtime.* packages to your project.
90185-opencv.png
Right-click your project namre->Manager NuGet Packages->Browse-> Search and Install them.
Then you can achieve it via BitmapConverter.ToMat() method.
Here is my test code you can refer to.

 Image img = Image.FromFile(@"C:\Users\Pictures\home.PNG");
 Bitmap bmpScreenshot = new Bitmap(img);
 var imageMat = OpenCvSharp.Extensions.BitmapConverter.ToMat(bmpScreenshot);

Best Regards,
Daniel Zhang


If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentationto enable e-mail notifications if you want to receive the related email notification for this thread.



opencv.png (21.9 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@DanielZhang-MSFT
Hello Sir ,
Thank your for help , i want to ask if also i can do the image processing with OpenCvSharp4 that i installed with nuget ?
i mean does it have the basic fucntion for image procssing?

0 Votes 0 ·
DanielZhang-MSFT avatar image DanielZhang-MSFT AhmedWassimBENSALEMENISo-3626 ·

Hi @AhmedWassimBENSALEMENISo-3626,
As document said that OpenCvSharp4 is an OpenCV wrapper for .NET. Since this package only contains the core managed library, another native binding package (OpenCvSharp4.runtime.*) for the operating system is required.
And it will encounter the error "Unable to load DLL'OpenCvSharpExtern': The specified module could not be found" without OpenCvSharp4.runtime.
Best Regards,
Daniel Zhang


0 Votes 0 ·

GRAZIE
Thank you for your help sir

0 Votes 0 ·