Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCvSharp4.runtime.linux-arm doesn't work on raspberry pi 4 #1263

Closed
dseferlis opened this issue May 13, 2021 · 32 comments
Closed

OpenCvSharp4.runtime.linux-arm doesn't work on raspberry pi 4 #1263

dseferlis opened this issue May 13, 2021 · 32 comments
Labels

Comments

@dseferlis
Copy link

dseferlis commented May 13, 2021

Summary of issue

Hello everyone.
First of all thank you for your effort to make this lib.
Trying to use opencvsharp on an image capture app on a raspberry pi. Installed the OpenCvSharp4.runtime.linux-arm nuget package thinking of this is what I need.
Although I get the error bellow.
Is there something I can do to make it work?

Environment

Raspberry pi model 4 4GB
OS: Raspbian 10 buster (armv7l)
Project framework: .net 5

Example code:

using OpenCvSharp;

namespace OpencvTest.Console
{
    class Program
    {
        static void Main(string[] args) {
            var capture = new VideoCapture(0);
            var window = new Window("Test");
            var image = new Mat();
            while (true) {
                capture.Read(image);
                if (image.Empty()) {
                    break;
                }
                
                window.ShowImage(image);
                if (Cv2.WaitKey(1) == 113) {
                    break;
                }
            }
            System.Console.WriteLine("Hello World!");
        }
    }
}

Output:

Unhandled exception. System.TypeInitializationException: The type initializer for 'OpenCvSharp.Internal.NativeMethods' threw an exception.
 ---> System.DllNotFoundException: Unable to load shared library 'OpenCvSharpExtern' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libOpenCvSharpExtern: wrong ELF class: ELFCLASS64
   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.videoio_VideoCapture_new3(Int32 device, Int32 apiPreference, IntPtr& returnValue)
   at OpenCvSharp.VideoCapture..ctor(Int32 index, VideoCaptureAPIs apiPreference)
   at OpencvTest.Console.Program.Main(String[] args)
@AvenSun
Copy link
Contributor

AvenSun commented May 13, 2021

you should check dependency of native library as follows
ldd ./lib/OpenCvSharpExtern.so
Do use full path of library, find all marked "not found" then install .
but the best way is building OpenCvSharpExtern library on Pi 4.

@dseferlis
Copy link
Author

dseferlis commented May 14, 2021

Thanks for reply.
Project build produces a libOpenCvSharpExtern.so. Running ldd libOpenCvSharpExtern.so (even with full path) i get the error "not a dynamic executable". Am I missing something?

EDIT: using file libOpenCvSharpExtern.so i get:
libOpenCvSharpExtern.so: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=2feb0d05276a0f30a7e6c2669610ca40685c2dca, not stripped

@AvenSun
Copy link
Contributor

AvenSun commented May 16, 2021

@bitdeli-chef

EDIT: using file libOpenCvSharpExtern.so i get:
libOpenCvSharpExtern.so: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=2feb0d05276a0f30a7e6c2669610ca40685c2dca, not stripped

It seems that libOpenCvSharpExtern.so (64 bit) you're referred is not a valid library for current OS .
Is your OS 32bit ?

@dseferlis
Copy link
Author

dseferlis commented May 16, 2021

Is your OS 32bit ?

Yes. It's the default for raspberry i think. At least in the official imager.

@AvenSun
Copy link
Contributor

AvenSun commented May 17, 2021

that's the problem
32-bit OS can not invoke 64-bit library .

@dseferlis
Copy link
Author

So I should build library on pi i guess.
Is there plans to release lib for arm32?

@AvenSun
Copy link
Contributor

AvenSun commented May 18, 2021

If you would like to use OpenCvSharp on arm32
yes, you have to build it on your own.
actually Pi 4 is 64 bit SOC, you can also try 64-bit OS.

@dseferlis
Copy link
Author

Thank you!!! I hadn't realize Pi can run 64bit OS...

@dseferlis dseferlis reopened this May 18, 2021
@dseferlis
Copy link
Author

dseferlis commented May 18, 2021

What I don't get is that building project for linux-arm, which produces 32bit executable, libOpenCvSharpExtern.so is included in output directory, but when building for linux-arm64, which produces 64bit executable, libOpenCvSharpExtern.so is not included.

@AvenSun
Copy link
Contributor

AvenSun commented May 23, 2021

I can build it successfully on Jetson family (arm64).
you should check the log

@jblam
Copy link

jblam commented Jun 23, 2021

libOpenCvSharpExtern.so: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=2feb0d05276a0f30a7e6c2669610ca40685c2dca, not stripped

It seems that libOpenCvSharpExtern.so (64 bit) you're referred is not a valid library for current OS .

I'd just note that the latest version of the OpenCvSharp4.runtime.linux-arm nuget package (currently 4.5.2.20210507) includes the x84-64 binary, not an ARM binary. So the package is guaranteed never to work, as I understand it.

I'd suggest unlisting that package, to avoid having other people encounter this problem and leave comments on this issue :)

@GitNao
Copy link

GitNao commented Jul 10, 2021

@GitNao
Copy link

GitNao commented Jul 10, 2021

libavcodec.so.57 => not found
libavformat.so.57 => not found
libavutil.so.55 => not found
libswscale.so.4 => not found

libOpenCvSharpExtern.so (https://github.com/GitNao/opencvsharp/actions/runs/1017218277)

libavcodec.so.58 => /lib/arm-linux-gnueabihf/neon/vfp/libavcodec.so.58 (0x738f4000)
libavformat.so.58 => /lib/arm-linux-gnueabihf/neon/vfp/libavformat.so.58 (0x736ca000)
libavutil.so.56 => /lib/arm-linux-gnueabihf/neon/vfp/libavutil.so.56 (0x73641000)
libswscale.so.5 => /lib/arm-linux-gnueabihf/neon/vfp/libswscale.so.5 (0x735c6000)

@jblam
Copy link

jblam commented Jul 16, 2021

@GitNao this looks great! Unfortunately I've since removed my dependency on OpenCV so I'm not in a position to verify the change.

@starrynightok
Copy link

I encountered the same problem on arm64,and cross-compile this library. it took effect.

@obie73
Copy link

obie73 commented Sep 25, 2021

I encountered the same problem on arm64, and cross-compile this library. it took effect.

Did you compile on an Apple M1?

@CobraCalle
Copy link

Hello,

because there is an "arm64" nuget too, I ran into the same problem, because I would like to use the "original" raspberry os. I have to access the camera through mmal, and under 64bit debian I cannot access video frames larger than 2mp, but I have a 12mp camera attached)... I think that is because mmal(sharp) is not 100% officially supported under debian (64bit), so I would like to go back to 32bite rapbian...

I 32-bit nuget would be great, because than ir would be much mor easy to switch to a newer version.

thanks

carl

@timstokman
Copy link
Contributor

timstokman commented Jan 11, 2022

libOpenCvSharpExtern.so: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=2feb0d05276a0f30a7e6c2669610ca40685c2dca, not stripped

It seems that libOpenCvSharpExtern.so (64 bit) you're referred is not a valid library for current OS .

I'd just note that the latest version of the OpenCvSharp4.runtime.linux-arm nuget package (currently 4.5.2.20210507) includes the x84-64 binary, not an ARM binary. So the package is guaranteed never to work, as I understand it.

I'd suggest unlisting that package, to avoid having other people encounter this problem and leave comments on this issue :)

Noticed the same thing. They do have a workflow for linux-arm, I wonder what is going on there: https://github.com/shimat/opencvsharp/blob/master/.github/workflows/linux-arm.yml. Might be it's just attaching the wrong artifact to the linux-arm package. It's building the 32 bits version for arm, I'd expect a 64 bits version somewhere as well, but I can only see I arm64 cuda version that seems a little behind version-wise.

@syamaner
Copy link

A bit late to the discussion but recently I experienced a similar issue too. If using Docker to run on Raspberry Pi, building OpenCV and OpenCvSharp as a multi architecture Docker build and then copy the native libraries to the target image when building the application.

Here is an example: https://github.com/syamaner/docker-multi-arch-opencvsharp/tree/main/docker
And a bit more in the post: https://dev.to/syamaner/docker-multi-architecture-net-60-and-opencvsharp-1okd

Essentially all it does is to build both libraries, copy libOpenCvSharpExtern.so and all dependencies to /artifacts directory. Then when building an application image, use it as a stage to copy contents of the /artifacts into the target image. the build image is only 94 to 125 mb depending on target architecture:

https://hub.docker.com/repository/docker/syamaner/opencvsharp-build/tags

This way I only need to add OpenCvSharp4 as a package reference and native bindings will be handled at Docker build time when building the application image. I have tested using 32 and 64 bit OS on Raspberry pi including official Rabpbian as well as Ubuntu 20.04 and 22.04.

Hope it helps.

@shenlongju
Copy link

有可供下载使用的文件吗,不想从头编译了

@AvenSun
Copy link
Contributor

AvenSun commented Oct 31, 2022

@shenlongju
the attached file I built works well on Jetson, but it's not the latest version.
It should work on all arm64/aarch64 platform, you can have a try.
libOpenCvSharpExtern for Jetson(arm64/aarch64)

@shenlongju
Copy link

shenlongju commented Oct 31, 2022 via email

@mimimiaomiao1
Copy link

@shenlongju我构建的附件在 Jetson 上运行良好,但它不是最新版本。它应该适用于所有arm64 / aarch64平台,您可以尝试一下。libOpenCvSharpExtern for Jetson(arm64/aarch64)

image

Raspberry arm64 tips

@AvenSun
Copy link
Contributor

AvenSun commented Nov 30, 2022

@OaimIsGnay
you can try install it via
apt install libjpeg-turbo8

@mimimiaomiao1
Copy link

@OaimIsGnay you can try install it via apt install libjpeg-turbo8

hello . can't find

@mimimiaomiao1
Copy link

Can you tell me the source?

@AvenSun
Copy link
Contributor

AvenSun commented Nov 30, 2022

apt update first then try it again

@mimimiaomiao1
Copy link

apt update first then try it again

Does not work Please give me your source address

@vnetb
Copy link

vnetb commented Nov 30, 2022

I use this on my Raspi.

 $ ldd libOpenCvSharpExtern.so | grep jpeg
        libjpeg.so.62 => /lib/aarch64-linux-gnu/libjpeg.so.62 

#1497 (comment)

@AvenSun
Copy link
Contributor

AvenSun commented Dec 5, 2022

apt update first then try it again

Does not work Please give me your source address

https://github.com/libjpeg-turbo/libjpeg-turbo

@stale
Copy link

stale bot commented Jun 10, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 10, 2023
@stale stale bot closed this as completed Jun 18, 2023
@hongzhuoxx
Copy link

hongzhuoxx commented Mar 1, 2024

Nuget Install Sdcb.OpenCvSharp4.mini.runtime.debian.12-arm64 or Sdcb.OpenCvSharp4.mini.runtime.ubuntu.22.04-arm64

#========================================================================

Linux orangepi5plus 5.10.160-rockchip-rk3588 #1.0.8 SMP Fri Nov 10 17:58:32 CST 2023 aarch64 GNU/Linux

Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm

#========================================================================

Test OK!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests