Install gstreamer support for opencv python package

2024/9/7 17:57:40

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:breakcv2.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:                      NOavcodec:                   NOavformat:                  NOavutil:                    NOswscale:                   NOavresample:                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?

Answer

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

https://en.xdnf.cn/q/72578.html

Related Q&A

How to use query function with bool in python pandas?

Im trying to do something like df.query("column == a").count()but withdf.query("column == False").count()What is the right way of using query with a bool column?

Text Extraction from image after detecting text region with contours

I want to build an OCR for an image using machine learning in python. I have preprocessed image by converting it to grayscale , applied otsu thresholding . I then used the contours to find the text re…

Pyinstaller executable fails importing torchvision

This is my main.py:import torchvision input("Press key")It runs correctly in the command line: python main.pyI need an executable for windows. So I did : pyinstaller main.pyBut when I launche…

Embedding Python in C: Having problems importing local modules

I need to run Python scripts within a C-based app. I am able to import standard modules from the Python libraries i.e.:PyRun_SimpleString("import sys")But when I try to import a local module …

Primitive Calculator - Dynamic Approach

Im having some trouble getting the correct solution for the following problem: Your goal is given a positive integer n, find the minimum number ofoperations needed to obtain the number n starting from …

Cant pickle : attribute lookup builtin.function failed

Im getting the error below, the error only happens when I add delay to process_upload function, otherwise it works without a problem.Could someone explain what this error is, why its happening and any…

Pandas Merge two DataFrames without some columns

ContextIm trying to merge two big CSV files together.ProblemLets say Ive one Pandas DataFrame like the following...EntityNum foo ... ------------------------ 1001.01 100 1002.02 50 1003…

Getting Youtube data using Python

Im trying to learn how to analyze social media data available on the web and Im starting with Youtube.from apiclient.errors import HttpError from outh2client.tools import argparser from apiclient.disco…

matplotlib does not show legend in scatter plot

I am trying to work on a clustering problem for which I need to plot a scatter plot for my clusters.%matplotlib inline import matplotlib.pyplot as plt df = pd.merge(dataframe,actual_cluster) plt.scatte…

Correct usage of asyncio.Conditions wait_for() method

Im writing a project using Pythons asyncio module, and Id like to synchronize my tasks using its synchronization primitives. However, it doesnt seem to behave as Id expect.From the documentation, it se…