kallaballa / V4D.old

V4D is a high performance visualization module for OpenCV. It features vector graphics using NanoVG a GUI based on NanoGUI and OpenCL/OpenGL and OpenCL/VAAPI interoperability.
https://viel-zu.org/opencv/doxygen/html/d7/dfc/v4d.html
Apache License 2.0
6 stars 1 forks source link

Notes on building GCV for Ubuntu 22.04 with GTK3 and Intel GPU #3

Open blondquirk opened 1 year ago

blondquirk commented 1 year ago

Hello, I think it may be appropriate to share the overview of the issues that arose when trying to get GCV nanovg-demo working (just for fun) in Ubuntu 22.04 with GTK3. It may also apply to other Ubuntu versions as well.

Nanovg part

I ended up with a setup that does not use nanovg.so, so skip this part.

Nanogui part

Cloned nanogui with --recursive option, then $ cmake -DCMAKE_BUILD_TYPE=Release -DNANOGUI_BACKEND="GLES 2" -DNANOGUI_BUILD_EXAMPLES=ON -DNANOGUI_BUILD_GLFW=ON -DNANOGUI_BUILD_PYTHON=OFF .. Take notice that all examples are linked only to libnanogui.so, and do not require libnanovg.so. I do not think GLES2 option is critical, but I use it instead of basic opengl. Nanogui that has built-in glfw will have hundreds of glfw symbols in it:

$ strings libnanogui.so |grep -i glfw |wc -l
455

OpenCV part

Problem 1: libopencv_core.so is not linked to OpenGL.

To check the linking flaws, ldd utility was used. Cause: OpenCV build system will not enable OpenGL (that was explicitly requested by user) at all if GTK3 library is selected. Related issues: https://github.com/opencv/opencv/issues/20850 https://github.com/opencv/opencv/issues/21592. Solution: Not ready to be PR'd to OpenCV-next.

Type 1 solution

Headless-style opencv (disable e.g. highgui that links to qt or gtk, but keep opengl in general). Patch the build system to respect the user choice for the following options. cmake -DCMAKE_BUILD_TYPE=Release -DOPENCV_ENABLE_EGL=ON -DWITH_OPENGL=ON -DWITH_GTK=OFF -DWITH_QT=OFF

Type 2 solution

Build highgui against GTK3, if GTK3 is already installed. This is what I did (with a patch also). CGV doesn't care that highgui has its OpenGL code disabled in GTK3 mode, by the way. The following is an example of how this should work (NOT the actual options needed for GCV build). cmake -DCMAKE_BUILD_TYPE=Release -DOPENCV_ENABLE_EGL=ON -DWITH_OPENGL=ON -DWITH_GTK=ON -DWITH_QT=OFF

Problem 2: OpenCV libopencv_videoio.so library is not linked to libav*.so, even if told so.

Cause: The OpenCV build system will not raise an error, even if e.g. libavdevice headers are not present in the system. Solution: Install FFMpeg-related (libav*-dev) headers and rebuild OpenCV.

Intel VAAPI part

Problem: vainfo shows no VAEntrypointEncSliceLP for VP9. Possible solution: Add i915.enable_guc=2 to kernel boot options (see https://github.com/intel/media-driver/blob/intel-media-22.6.6/README.md#known-issues-and-limitations).

CGV part

Problem: glewInit() returns error code -4 (GLEW_ERROR_NO_GLX_DISPLAY). Related: https://github.com/nigels-com/glew/issues/273 Solution: Error vanished when nanogui built-in glfw was enabled. In the Makefiles of GCV, remove pkgconfig glfw3 and other links to system glfw. Problem: bunny.webm is detected as zero-width and zero-height by nanovg-demo Solution: Fix OpenCV libavformat support as described above. Problem: nanovg-demo will not encode or save the video. Solution: Make sure VP9 VAEntrypointEncSliceLP is shown by vainfo.

Problem: quad-demo and video-demo build fails with "missing glEnable" Possible solution: add -lGL to the main Makefile.

video-demo: shows normally font-demo: shows normally

kallaballa commented 1 year ago

wow. nice report. but at the moment I am a little short in time :) anyway, I will look into it!

kallaballa commented 1 year ago

I know about the problems with GTK3... never got it to work. I never had the other issues. trying to reproduce.

kallaballa commented 1 year ago

anyway, I updated the README to include full instructions for ubuntu LTS