Hello there, I am trying to install OpenCvsharp and have it working which is for a Computer Vision Role using c# in a .NET console project , I have tried a bunch of things, I am using ubuntu 24.04 in WSL and have already installed dotnet, then proceed, to add the dependencies OpenCvSharp4 and OpenCvSharp4.runtime.ubuntu22 , and did apt install and all the libraries they mention in the Github Requirements for ubuntu
(Ubuntu) You must pre-install all the dependency packages needed to build OpenCV. Many packages such as libjpeg must be installed in order to work OpenCV. https://www.learnopencv.com/install-opencv-4-on-ubuntu-18-04/
First we initialize our project
dotnet new console
We will start by importing the necessary libraries for our pojects these are:
- OpenCvSharp4
Install Dependencies: dotAdd the required NuGet packages. The primary one is OpenCvSharp4.Windows. For visualization, also add ScottPlot.
Bash
dotnet add package OpenCvSharp4 # Computer vision
dotnet add package ScottPlot
The command can be run by following the next command
dotnet run
Install the following dependencies
## Install dependencies
sudo apt -y install build-essential checkinstall cmake pkg-config yasm
sudo apt -y install git gfortran
sudo apt -y install libjpeg8-dev libpng-dev
sudo apt -y install software-properties-common
sudo add-apt-repository "deb <http://security.ubuntu.com/ubuntu> xenial-security main"
sudo apt -y update
sudo apt -y install libjasper1
sudo apt -y install libtiff-dev
sudo apt -y install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev
sudo apt -y install libxine2-dev libv4l-dev
Added the following requirements as a permanent script
cat > run.sh << 'EOF'
#!/bin/bash
export LD_LIBRARY_PATH=./bin/Debug/net9.0/runtimes/linux-x64/native:$LD_LIBRARY_PATH
dotnet run
EOF
chmod +x run.sh
./run.sh
And then run it
Check what Ubuntu version you’re actually on
lsb_release -a
Remove the xenial repository that’s causing issues
sudo add-apt-repository --remove xenial-security main”
Update package lists
sudo apt update
Install the Teseract missing files
Search for available tesseract packages
apt search tesseract | grep -E “^tesseract”
Install tesseract with the correct package names
sudo apt install tesseract-ocr tesseract-ocr-eng libtesseract-dev
For know had to isntall debugging tools like strace with
sudo apt install strace
Installed this
# Instalar tesseract (la dependencia principal que falta)
sudo apt update
sudo apt install tesseract-ocr libtesseract-dev
# Instalar otras dependencias de OpenCV
sudo apt install libgtk-3-dev libglib2.0-0
After all this solutions recomended by AI , StackOverflow, Forums, Github issues ( Which seem to have a long thread not solved here Unable to load DLL 'OpenCvSharpExtern': The specified module could not be found. · Issue #143 · shimat/opencvsharp · GitHub
I got this error
/home/asperjasp/asperjasp/Job/Progile/bin/Debug/net9.0/runtimes/linux-x64/native/OpenCvSharpExtern: cannot open shared object file: No such file or directory
/usr/lib/dotnet/shared/Microsoft.NETCore.App/9.0.9/OpenCvSharpExtern: cannot open shared object file: No such file or directory
/home/asperjasp/asperjasp/Job/Progile/bin/Debug/net9.0/runtimes/linux-x64/native/libOpenCvSharpExtern: cannot open shared object file: No such file or directory
/usr/lib/dotnet/shared/Microsoft.NETCore.App/9.0.9/libOpenCvSharpExtern: cannot open shared object file: No such file or directory
at OpenCvSharp.Internal.NativeMethods.redirectError(CvErrorCallback errCallback, IntPtr userdata, IntPtr& prevUserdata)
at OpenCvSharp.Internal.ExceptionHandler.RegisterExceptionCallback()
at OpenCvSharp.Internal.NativeMethods.LoadLibraries(IEnumerable`1 additionalPaths)
at OpenCvSharp.Internal.NativeMethods..cctor()
— End of inner exception stack trace —
at OpenCvSharp.Internal.NativeMethods.imgcodecs_imread(String fileName, Int32 flags, IntPtr& returnValue)
at OpenCvSharp.Mat..ctor(String fileName, ImreadModes flags)
at Program.Main(String args) in /home/asperjasp/asperjasp/Job/Progile/Program.cs:line 14
For a simple program like this one
using OpenCvSharp;
using System .IO ;
using System;
class Program
{
static void Main(string args)
{
Console.WriteLine(“Hello, This is testing OpenCV!”);
using var src = new Mat("SAP.png", ImreadModes.Color);
}
}
And I do not what else to do, I am open to suggestions, thank you.