gocv icon indicating copy to clipboard operation
gocv copied to clipboard

Can gocv package OpenCV into a binary file through cgo?

Open yh4922 opened this issue 1 year ago • 13 comments

There is a requirement that the project needs to be deployed on many devices, and some devices cannot even install docker and there is no way to precompile opencv

If there is a way to package opencv into a binary file at compile time, it should be a good solution to this problem

Similar to go-sqlite3

I don't know if this example is appropriate, but in short, what I want to express is this

yh4922 avatar Feb 21 '23 07:02 yh4922

for deployment copy opencv libs and set LD_LIBRARY_PATH to that folder cp -r /usr/local/lib/libopencv*.* build/${VER}/libs export LD_LIBRARY_PATH=pwd/libs/

thats what we do for builds

abhikalitra avatar Mar 02 '23 08:03 abhikalitra

https://github.com/jan-bar/xgo/blob/master/docker/readme.md

You can try my project, I made a docker image. And completed the compilation of window under Linux, and also used cgo. gocv supports static compilation. You can prepare cross-compilation tools and use static compilation, which should be able to achieve the effect you want.

image

jan-bar avatar Apr 24 '23 01:04 jan-bar

Sure, I’d be happy to give it a try! Thank you!

yh4922 avatar Apr 24 '23 07:04 yh4922

https://github.com/jan-bar/xgo/blob/master/docker/readme.md

You can try my project, I made a docker image. And completed the compilation of window under Linux, and also used cgo. gocv supports static compilation. You can prepare cross-compilation tools and use static compilation, which should be able to achieve the effect you want.

image

It seems to be not working well. I encountered an error when compiling gocv on the ARM platform. You can refer to my question here: https://github.com/hybridgroup/gocv/issues/1057

yh4922 avatar Apr 24 '23 07:04 yh4922

I don't have an arm-based device, and cross-compiling opencv for arm always reports an error. It seems that you need to explore it carefully. I think some libraries also need to be cross-compiled. If there is an arm-based environment, I may not have such trouble.

You can refer to the official method for cross-compilation

-DCMAKE_TOOLCHAIN_FILE=../platforms/linux/aarch64-gnu.toolchain.cmake

https://github.com/opencv/opencv/blob/4.x/.github/workflows/arm64-build-checks.yml

jan-bar avatar Apr 24 '23 09:04 jan-bar

@yh4922 same problem see here:https://github.com/JuliaLang/julia/issues/41613

After my unremitting efforts, I finally found that opencv cannot be compiled on the arm64 platform. Eventually there will be compilation errors

libquadmath0 not support aarch64

image

jan-bar avatar Apr 27 '23 08:04 jan-bar

May I ask if there is any solution? The normal compilation method works on arm64, but static compilation does not.

同样的问题看这里:朱莉娅郎/朱莉娅#41613

经过我的不懈努力,我终于发现opencv无法在arm64平台上编译。最终会出现编译错误

libquadmath0不支持 AAc64

图像

yh4922 avatar May 08 '23 05:05 yh4922

@yh4922 I have tried without success,you can study further.

jan-bar avatar May 08 '23 07:05 jan-bar

Okay, thank you very much.

yh4922 avatar May 09 '23 06:05 yh4922

I’m having a problem similar to this one, so maybe someone has already come in a solution to that.

I did a program in Go using gocv and go-face, it is working and compiling perfectly in Ubuntu. But I would like to build for Windows platform. If I try to cross-platform appear syntax errors in the code... If you take the code for Windows and try to compile, there is always a library or other that the compiler does not find or the path to the file is non-existent.

Would anyone have a path that could go to solve this problem?

PS. I have already followed the installation tutorials of dependencies, both gocv and go-face, among others.

jocemarkovacs avatar Nov 09 '23 19:11 jocemarkovacs

For me, it's also not possible to build a static binary on ARM64 (Raspberry Pi 5 with PiOS-Bookwork):

go build -v -tags static -ldflags="-extldflags=-static"
log/internal
log
gocv.io/x/gocv
klaus/openCV/hello-cv
# klaus/openCV/hello-cv
/usr/local/go/pkg/tool/linux_arm64/link: running g++ failed: exit status 1
/usr/bin/ld: cannot find -lIlmImf: No such file or directory
/usr/bin/ld: cannot find -lippiw: No such file or directory
/usr/bin/ld: cannot find -lippicv: No such file or directory
/usr/bin/ld: cannot find -lquadmath: No such file or directory
/usr/bin/ld: /usr/local/lib/libopencv_core.a(opencl_core.cpp.o): in function `opencl_check_fn(int)':
opencl_core.cpp:(.text._ZL15opencl_check_fni+0x168): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
collect2: error: ld returned 1 exit status

Klaus-Tockloth avatar Feb 16 '24 07:02 Klaus-Tockloth

I would like to know if this issue has received support.

yh4922 avatar Mar 11 '24 10:03 yh4922

Hi Yohann,

I'm still having difficulty building my project on the Windows platform for distribution. Do you have the knowledge to build this? Front fyne(front) and backend with OpenCV.

thank you for your time.

On Mon, Mar 11, 2024 at 7:31 AM Yohann @.***> wrote:

I would like to know if this issue has received support.

— Reply to this email directly, view it on GitHub https://github.com/hybridgroup/gocv/issues/1056#issuecomment-1988097995, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQP2B7BAMO7YP5HI6YMGDG3YXWBX5AVCNFSM6AAAAAAVCVIVUSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSOBYGA4TOOJZGU . You are receiving this because you commented.Message ID: @.***>

jocemarkovacs avatar Mar 11 '24 13:03 jocemarkovacs