shimat / opencvsharp

OpenCV wrapper for .NET
Apache License 2.0
5.39k stars 1.15k forks source link

Cannot run on Ubuntu 18.04 #1134

Closed help-14 closed 3 years ago

help-14 commented 3 years ago

Summary of your issue

Hi, I'm running a webserver on Ubuntu 18.04 but when open an image, I got this error:

The type initializer for 'OpenCvSharp.NativeMethods' threw an exception.
   at OpenCvSharp.NativeMethods.imgcodecs_imread(String fileName, Int32 flags, IntPtr& returnValue)
   at OpenCvSharp.Mat..ctor(String fileName, ImreadModes flags)
   at WebServer.services.vcbs.VCBS.SplitImage(String imagePath) in /mnt/c/Users/Nhan/Documents/WebServer/WebServer/services/vcbs/VCBS.cs:line 18

I have already add the latest version of OpenCvSharp4 and OpenCvSharp4.runtime.ubuntu.18.04-x64. Here is line 18 of VCBS.cs:

Mat img = new Mat(imagePath, ImreadModes.Grayscale);

The image is there, this code run perfectly on Windows but got the same problem with WSL and Azure VM.

Environment

help-14 commented 3 years ago

Okay so it is dependency problem, fixed with this in Ubuntu 18.04:

sudo apt install libtesseract4 libgtk2.0-0 libcairo2 libgdk-pixbuf2.0-0 libdc1394-22  libtiff5 libavcodec-extra57 libavformat57 libavutil55 libswscale4 libopenexr22 -y

But for some reason libavcodec-extra57 libavformat57 libavutil55 libswscale4 libopenexr22 not available on Ubuntu 20.04 so beware.