Skip to main content

Hi,

While exploring ways to deploy my application, one possibility I looked at was using gstreamer pipelines to get video into my python-opencv application using appsink. The plan was to then try using the Metis inferencing as a gstreamer pipeline, with the python program interacting with it to feed/get images and results as needed. Anyway, I hit a roadblock with that since I found that the opencv installed with the voyager-sdk installation script is built without gstreamer support. 

I looked on the internet, and found/modified and tried the following script to build opencv with gstreamer for use with the voyager-sdk:

 

#!/bin/bash

OPENCV_VER="4.x"
TMPDIR=$(mktemp -d)

# Build and install OpenCV from source.
cd "${TMPDIR}"
git clone --branch ${OPENCV_VER} --depth 1 --recurse-submodules --shallow-submodules https://github.com/opencv/opencv-python.git opencv-python-${OPENCV_VER}
cd opencv-python-${OPENCV_VER}
export ENABLE_CONTRIB=1
export ENABLE_HEADLESS=0
# We want GStreamer support enabled.
export CMAKE_ARGS="-DWITH_GSTREAMER=ON"
python3 -m pip wheel . --verbose

# Install OpenCV
python3 -m pip install opencv_contrib_python*.whl

This way I was able to successfully build opencv (v4.12) with gstreamer support (which can be verified by running print(cv2.getBuildInformation()) in python. 

However, when I tried to run ./inference.py again, then I got following output:

./inference.py yolov5s-v7-coco media/traffic1_1080p.mp4 --show-device-fps

arm_release_ver: g13p0-01eac0, rk_so_ver: 9
WARNING : pyglet could not access the display, OpenGL is not available: No standard config is available.
ERROR : OpenCV(4.12.0) /tmp/tmp.FQo9rZg2uK/opencv-python-4.x/opencv/modules/highgui/src/window.cpp:1284: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvNamedWindow'
INFO : Core Temp : 47.0°C
INFO : Metis : 891.4fps
INFO : CPU % : 14.3%
INFO : End-to-end : 226.8fps
Exception in thread InferenceThread:
Traceback (most recent call last):
File "/home/aetina/.pyenv/versions/3.10.6/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/home/aetina/.pyenv/versions/3.10.6/lib/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "/mnt/microsd/axelera/voyager2/voyager-sdk/axelera/app/display.py", line 607, in _target
self._destroy_all_windows()
File "/mnt/microsd/axelera/voyager2/voyager-sdk/axelera/app/display_cv.py", line 107, in _destroy_all_windows
cv2.destroyAllWindows()
cv2.error: OpenCV(4.12.0) /tmp/tmp.FQo9rZg2uK/opencv-python-4.x/opencv/modules/highgui/src/window.cpp:1295: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvDestroyAllWindows'

So it seems that the axelera sdk expects the opencv to be built in a certain way to operate with it. Can someone guide me how I can modify the script so that the resulting opencv build is compatible with the voyager-sdk? As stated earlier, my main motivation is only to add gstreamer support so I can use gstreamer pipelines to interface with my application. I’m sure some  others down the line will also benefit from this information, since it’s a popular usage.

Hi ​@saadtiwana

Thanks for the question! 

The error says we need GTK support. Can you perhaps try running ./inference.py with --no-display, and if you need to render then perhaps you will have to rebuiild OpenCV with -DWITH_GTK=ON


Hi ​@Habib ,

Thanks for the reply. I tried running with “--no-display” and it runs OK. The build information did show that GTK+ was included in the build.

Anyway, I also did a print of the cv2.getBuildInformation() for both the opencv included with the voyager-sdk and then did a comparison in notepad++ to see differences. I noticed that the one in the voyager sdk was build with QT5 and without GTK+ (can be one OR another, not both). Anyway, I will try building with QT5 instead and try again. Btw, is it a custom build by your build system? If yes, the settings/flags on that would be helpful.

p.s build information outputs (cv2.getBuildInformation()) attached as files.


Reply