shimat / opencvsharp

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

Unable to load DLL 'OpenCvSharpExtern' - RaspberryPi 3, Ubuntu, .NET Core #307

Closed matjanos closed 7 years ago

matjanos commented 7 years ago

Hi!

I'm trying to run API which uses OpenCVSharp3-AnyCPU (3.2.0.20170210-beta). I run it on a Raspberry Pi 3 with .NET Core (1.2.0-beta-001291-00) and Raspbian GNU/Linux 8.0 (jessie) on the board.

When I try to start my app with dotnet My.API.dll, I get error (actually it invokes ctor of CascadeClassifier):

Unable to load DLL 'OpenCvSharpExtern': The specified module could not be found.
 (Exception from HRESULT: 0x8007007E)
*** An exception has occurred because of P/Invoke. ***
Please check the following:
(1) OpenCV's DLL files exist in the same directory as the executable file.
(2) Visual C++ Redistributable Package has been installed.
(3) The target platform(x86/x64) of OpenCV's DLL files and OpenCvSharp is the same as your project's.

System.DllNotFoundException: Unable to load DLL 'OpenCvSharpExtern': The specified module could not be found.
 (Exception from HRESULT: 0x8007007E)
   at OpenCvSharp.NativeMethods.core_Mat_sizeof()
   at OpenCvSharp.NativeMethods.TryPInvoke()

My folder contains those items:

CoreCompat.System.Drawing.dll
haarcascade_frontalcatface_extended.xml
haarcascade_frontalface_default.xml
My.API.dll
Microsoft.AspNetCore.Hosting.Abstractions.dll
Microsoft.AspNetCore.Hosting.dll
Microsoft.AspNetCore.Hosting.Server.Abstractions.dll
Microsoft.AspNetCore.Http.Abstractions.dll
Microsoft.AspNetCore.Http.dll
Microsoft.AspNetCore.Http.Extensions.dll
Microsoft.AspNetCore.Http.Features.dll
Microsoft.AspNetCore.Owin.dll
Microsoft.AspNetCore.Server.Kestrel.dll
Microsoft.AspNetCore.WebUtilities.dll
Microsoft.DotNet.InternalAbstractions.dll
Microsoft.Extensions.Configuration.Abstractions.dll
Microsoft.Extensions.Configuration.dll
Microsoft.Extensions.Configuration.EnvironmentVariables.dll
Microsoft.Extensions.DependencyInjection.Abstractions.dll
Microsoft.Extensions.DependencyInjection.dll
Microsoft.Extensions.DependencyModel.dll
Microsoft.Extensions.FileProviders.Abstractions.dll
Microsoft.Extensions.FileProviders.Physical.dll
Microsoft.Extensions.FileSystemGlobbing.dll
Microsoft.Extensions.Logging.Abstractions.dll
Microsoft.Extensions.Logging.dll
Microsoft.Extensions.ObjectPool.dll
Microsoft.Extensions.Options.dll
Microsoft.Extensions.PlatformAbstractions.dll
Microsoft.Extensions.Primitives.dll
Microsoft.Net.Http.Headers.dll
Nancy.dll
Newtonsoft.Json.dll
opencv_ffmpeg320_64.dll
OpenCvSharp.Blob.dll
OpenCvSharp.dll
OpenCvSharp.dll.config
OpenCvSharpExtern.dll
refs
System.Collections.NonGeneric.dll
System.Collections.Specialized.dll
System.ComponentModel.Primitives.dll
System.ComponentModel.TypeConverter.dll
System.Data.Common.dll
System.Diagnostics.Contracts.dll
System.Drawing.Primitives.dll
System.Linq.dll
System.Net.WebSockets.dll
System.Runtime.Serialization.Primitives.dll
System.Text.Encodings.Web.dll
System.Xml.XmlSerializer.dll
web.config
x64
x86

I've tried to use dlls mapping, so I've created OpenCvSharp.dll.config file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <dllmap os="!windows" dll="opencv_core2410" target="libopencv_core.so.2.4.10" />
  <dllmap os="!windows" dll="opencv_imgproc2410" target="libopencv_imgproc.so.2.4.10" />
</configuration>
shimat commented 7 years ago

The OpenCvSharpExtern.dll that I released may work only on x86/x64 Windows 😢 You have to build OpenCvSharpExtern.dll for your Linux platform. Please get the OpenCvSharp source code files and use cmake.

cmake src
matjanos commented 7 years ago

Thanks a lot for quick reply. I think that it would be useful to prepare a CI process for Linux machines as well. Cheers!

hoyho commented 6 years ago

can you provide other platform's OpenCvSharpExtern.dll? just like we publish a dotnet core project, it will generate several paltform's files. so that we dont need to add or build OpenCvSharp by us @shimat

jiveabillion commented 6 years ago

+1 more request for an RPi dll shared on here so we can all save time and effort. I am not used to building things on linux, so I have to take the time to learn. I hope this doesn't send me down dependency hell.

bvuden commented 5 years ago

+1 for an OpenCvSharpExtern.dll that can run on Linux. Trying to run this with .NET Core on a Docker container. Will PR #582 fix this? @shimat any idea when this PR can be merged?

whuanle commented 5 years ago

+1,We apply opencvsharp to the arm development board.Manually generating dlls is complicated and lengthy~

toanlcgift commented 5 years ago

I have build it, you can download without compile from here: https://github.com/toanlcgift/RPISpiderRobot/blob/master/LiveStreamServer/LiveStreamServer/libOpenCvSharpExtern.so

sharpwood commented 5 years ago

@toanlcgift Does it support arm64?

toanlcgift commented 5 years ago

@sharpwood yes, this .so supports all arm abis

sharpwood commented 5 years ago

But my raspberry Pi 4(ununtu server 64) still reports the same error after using this file. Do I have to install opencv first? @toanlcgift

toanlcgift commented 5 years ago

@sharpwood I see the problem, because you are using dotnet sdk in RPI? right?

I installed my app via windows by command line:

dotnet publish --runtime linux-arm

Then i copy it to RPI & execute binary file, not by dotnet MyApp.dll .

Please refer https://docs.microsoft.com/en-us/dotnet/core/rid-catalog

Note: After build this library, you don't need any openCV library installed in your environment.

sharpwood commented 5 years ago

I did not make it clear, I am using OpenCVSharp4, running on the Raspberry Pi 4B. Do you have a newer version? @toanlcgift

toanlcgift commented 5 years ago

@sharpwood No i don't, you have to build yourself, needed to install openCV first (from source or binary are OK)