opencvsharp icon indicating copy to clipboard operation
opencvsharp copied to clipboard

Docker debian and opencvsharp - .Net Rest Api

Open mapo80 opened this issue 1 year ago • 1 comments

Hi everyone,

after many struggles I understood how to use Opencvsharp on debian dockerized .Net application. Here are steps:

  • Compile everything using this dockerfile. It uses debian .net image and not ubuntu one

https://gist.github.com/mapo80/32a68cc1b797e9115ad73b6de8056394

  • After compilation succeeded, all files are on container image in this folder:

/usr/lib/libOpenCvSharpExtern.so

  • To have all dependencies run this command:

ldd libOpenCvSharpExtern.so

  • Copy all dependencies in a folder:

mkdir opencv ldd libOpenCvSharpExtern.so | awk 'NF == 4 { system("cp " $3 " ./opencv") }' cp libOpenCvSharpExtern.so ./opencv

  • Now you have all files needed to run libOpenCvSharpExtern.so

  • Copy all these files on your host machine. Execute this from your host machine terminal:

docker cp docker_image_name:/usr/lib/opencv opencv

  • You'll have all files on your host in this folder:

opencv

  • Create 2 tar/gz files:

One only with libOpenCvSharpExtern.so (file_a.tar.gz) One for all other files contained in opencv folder (file_b.tar.gz)

  • From docker file of your application add these lines:

`FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base

WORKDIR / ADD file_b.tar.gz /usr/lib/x86_64-linux-gnu ADD file_a.tar.gz /usr/share/dotnet/shared/Microsoft.NETCore.App/7.0.3`

Following this steps you can use opencv from your asp.net api application ran on your docker image.

I hope you find this useful.

mapo80 avatar Mar 03 '23 16:03 mapo80

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[bot] avatar Sep 17 '23 12:09 stale[bot]