Install gstreamer support for opencv python package
Asked Answered
A

4

6

I have built my own opencv python package from source.

import cv2
print(cv2.__version__)

prints: 3.4.5

Now the issue I am facing is regarding the use of gstreamer from the VideoCapture class of opencv. I am trying to get this mimimum working example running on python3

cap = cv2.VideoCapture("videotestsrc ! appsink")

if not cap.isOpened():
    print("Cannot capture test src. Exiting.")
    quit()

while True:
    ret, frame = cap.read()
    if ret == False:
        break
    cv2.imshow("CVtest",frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

Capture fails, producing my print above (see if statement). I checked:

import cv2
print(cv2.getBuildInformation())

prints:

Video I/O:
DC1394:                      NO
FFMPEG:                      NO
  avcodec:                   NO
  avformat:                  NO
  avutil:                    NO
  swscale:                   NO
  avresample:                NO
GStreamer:                   NO
libv4l/libv4l2:              NO
v4l/v4l2:                    linux/videodev2.h

Seeing that, it made absolute sense that my gstreamer pipeline didn't work. I ensured WITH_GSTREAMER was set to ON during ccmake of OpenCV (which it already was). Still the issue maintained. I even tried setting WITH_GSTREAMER_0_10 to ON as well. Still no luck having gstreamer enabled from the cv2 python module.

Before anyone suggests using pip3 to install cv2. I tried that, too. The issue with getting the package from pip is, it doesn't let you configure gstreamer support at all.

Can anyone provide help here?

Acidforming answered 8/1, 2019 at 16:16 Comment(0)
A
3

I was able to solve the issue, with a bit of help from the opencv support forum. Looking at the cmake output hints at the problem:

-- Checking for module 'gstreamer-base-0.10'
--   No package 'gstreamer-base-0.10' found
-- Checking for module 'gstreamer-video-0.10'
--   No package 'gstreamer-video-0.10' found
-- Checking for module 'gstreamer-app-0.10'
--   No package 'gstreamer-app-0.10' found
-- Checking for module 'gstreamer-riff-0.10'
--   No package 'gstreamer-riff-0.10' found
-- Checking for module 'gstreamer-pbutils-0.10'
--   No package 'gstreamer-pbutils-0.10' found

During ccmake, I had set both WITH_GSTREAMER as well as WITH_GSTREAMER_0_10 to ON. Seems that cmake prefers the gstreamer0.10 flag over the one for gstreamer1.0. Since I only have gstreamer1.0 installed, opencv entirely failed setting up the gstreamer dependencies.

I made sure to whipe all previously deployed binaries:

cd <opencv-src>/build 
sudo make uninstall

Then I simply reinstalled, with the adjusted settings (given my knowledge above):

ccmake ..
make -j8
sudo make install

when I

import cv2
print(cv2.getBuildInformation())

my console now outputs

Video I/O:
DC1394:                      NO
FFMPEG:                      NO
  avcodec:                   NO
  avformat:                  NO
  avutil:                    NO
  swscale:                   NO
  avresample:                NO
GStreamer:                   
  base:                      YES (ver 1.8.3)
  video:                     YES (ver 1.8.3)
  app:                       YES (ver 1.8.3)
  riff:                      YES (ver 1.8.3)
  pbutils:                   YES (ver 1.8.3)
libv4l/libv4l2:              NO
v4l/v4l2:                    linux/videodev2.h

Bottom line is, do not set WITH_GSTREAMER_0_10 to ON during cmake, if you actually want gstreamer1.0. In that case you must only set WITH_GSTREAMER ON

Acidforming answered 9/1, 2019 at 10:41 Comment(0)
F
4

For those who are struggling with the same problem on Windows... I had to set following CMake Options:

  1. only set "WITH_GSTREAMER" option to True, "WITH_GSTREAMER_0_10" MUST BE FALSE
  2. add new entry "GSTREAMER_DIR"=(path to gstreamer) for me it was "C:/gstreamer/1.0/x86_64" I found this solution here

My OpenCV version: 3.4.3

Fimble answered 22/2, 2019 at 14:42 Comment(0)
A
3

I was able to solve the issue, with a bit of help from the opencv support forum. Looking at the cmake output hints at the problem:

-- Checking for module 'gstreamer-base-0.10'
--   No package 'gstreamer-base-0.10' found
-- Checking for module 'gstreamer-video-0.10'
--   No package 'gstreamer-video-0.10' found
-- Checking for module 'gstreamer-app-0.10'
--   No package 'gstreamer-app-0.10' found
-- Checking for module 'gstreamer-riff-0.10'
--   No package 'gstreamer-riff-0.10' found
-- Checking for module 'gstreamer-pbutils-0.10'
--   No package 'gstreamer-pbutils-0.10' found

During ccmake, I had set both WITH_GSTREAMER as well as WITH_GSTREAMER_0_10 to ON. Seems that cmake prefers the gstreamer0.10 flag over the one for gstreamer1.0. Since I only have gstreamer1.0 installed, opencv entirely failed setting up the gstreamer dependencies.

I made sure to whipe all previously deployed binaries:

cd <opencv-src>/build 
sudo make uninstall

Then I simply reinstalled, with the adjusted settings (given my knowledge above):

ccmake ..
make -j8
sudo make install

when I

import cv2
print(cv2.getBuildInformation())

my console now outputs

Video I/O:
DC1394:                      NO
FFMPEG:                      NO
  avcodec:                   NO
  avformat:                  NO
  avutil:                    NO
  swscale:                   NO
  avresample:                NO
GStreamer:                   
  base:                      YES (ver 1.8.3)
  video:                     YES (ver 1.8.3)
  app:                       YES (ver 1.8.3)
  riff:                      YES (ver 1.8.3)
  pbutils:                   YES (ver 1.8.3)
libv4l/libv4l2:              NO
v4l/v4l2:                    linux/videodev2.h

Bottom line is, do not set WITH_GSTREAMER_0_10 to ON during cmake, if you actually want gstreamer1.0. In that case you must only set WITH_GSTREAMER ON

Acidforming answered 9/1, 2019 at 10:41 Comment(0)
S
2

Installing the packages libgstreamer1.0-dev and libgstreamer-plugins-base1.0-dev helped me to solve this issue.

sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
Stoffel answered 8/5, 2019 at 10:49 Comment(1)
How to install DC1394 in opencv-python version 4.1.2? Without CAP_DC1394 I cannot set buffersize for my IP camera.Retinoscopy
C
0

It took my 8 day but i found my solution there ; https://github.com/opencv/opencv-python/issues/530 For my opinion its work better in new python3.8 virtual environment

OPENCV_VER="master"
TMPDIR=$(mktemp -d)
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=0
export ENABLE_HEADLESS=1
export CMAKE_ARGS="-DWITH_GSTREAMER=ON"
python3 -m pip wheel . --verbose
# Install OpenCV
python3 -m pip install opencv_python*.whl

If you need GTK also you can add your code ;

export CMAKE_ARGS="-DWITH_GTK=ON"

u should use these code blocks before pip wheel . --verbose

Calcariferous answered 25/9 at 17:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.