0% found this document useful (0 votes)
253 views14 pages

How To Compile Opencv With Gstreamer (Ubuntu&Windows) : Galaktyk 01

The document provides instructions for compiling OpenCV with Gstreamer support on both Ubuntu and Windows systems. For Ubuntu, it describes installing prerequisites like Gstreamer and development packages, cloning the OpenCV source code, configuring CMake to enable Gstreamer support, building and installing OpenCV. For Windows, it outlines uninstalling existing OpenCV, installing prerequisites like Gstreamer and NumPy, configuring the build with CMake and Visual Studio, and verifying the install. The instructions allow capturing and processing video frames with OpenCV and Gstreamer.

Uploaded by

Đinh Luận
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
253 views14 pages

How To Compile Opencv With Gstreamer (Ubuntu&Windows) : Galaktyk 01

The document provides instructions for compiling OpenCV with Gstreamer support on both Ubuntu and Windows systems. For Ubuntu, it describes installing prerequisites like Gstreamer and development packages, cloning the OpenCV source code, configuring CMake to enable Gstreamer support, building and installing OpenCV. For Windows, it outlines uninstalling existing OpenCV, installing prerequisites like Gstreamer and NumPy, configuring the build with CMake and Visual Studio, and verifying the install. The instructions allow capturing and processing video frames with OpenCV and Gstreamer.

Uploaded by

Đinh Luận
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

3/9/23, 8:43 AM How to compile OpenCV with Gstreamer [Ubuntu&Windows] | by Galaktyk 01 | Medium

Galaktyk 01 Follow

Mar 17, 2019 · 4 min read · Listen

Save

How to compile OpenCV with Gstreamer


[Ubuntu&Windows]
Update 🔥🔥👍👍💕

try using vcpkg (cpp package manager)

vcpkg install opencv[gstreamer,ffmpeg,python]:x64-windows

and export the lib

vcpkg export opencv:x64-windows --zip

## Ubuntu

Ubuntu 16.04
Python 3.7
OpenCV 4.1.0
Open in app Sign up Sign In

https://galaktyk.medium.com/how-to-build-opencv-with-gstreamer-b11668fa09c 1/14
3/9/23, 8:43 AM How to compile OpenCV with Gstreamer [Ubuntu&Windows] | by Galaktyk 01 | Medium

Gstreamer 1.8.3
Cmake 3.5.1
Search Medium

1. install gstreamer1.0

sudo apt-get install gstreamer1.0*


sudo apt install ubuntu-restricted-extras

2. install lib, dev package

sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev

3. install numpy
I recommend to use conda or virtualenv over the native one, in case we mess things up.

source activate <your_env>


pip install numpy

4. Clone OpenCV repo

git clone https://github.com/opencv/opencv.git


cd opencv/
git checkout 4.1.0

5. Building

mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D PYTHON_EXECUTABLE=$(which python3) \
-D BUILD_opencv_python2=OFF \ 86 9
https://galaktyk.medium.com/how-to-build-opencv-with-gstreamer-b11668fa09c 2/14
3/9/23, 8:43 AM How to compile OpenCV with Gstreamer [Ubuntu&Windows] | by Galaktyk 01 | Medium

-D CMAKE_INSTALL_PREFIX=$(python3 -c “import sys; print(sys.prefix)”)


\
-D PYTHON3_EXECUTABLE=$(which python3) \
-D PYTHON3_INCLUDE_DIR=$(python3 -c “from distutils.sysconfig import
get_python_inc; print(get_python_inc())”) \
-D PYTHON3_PACKAGES_PATH=$(python3 -c “from distutils.sysconfig import
get_python_lib; print(get_python_lib())”) \
-D WITH_GSTREAMER=ON \
-D BUILD_EXAMPLES=ON ..

After finished the configuration, Go check GStreamer and Python section

6. Check your log


✔ check if it has Python 3: section and all interpreter and path are right.
(If they aren’t there, check the numpy package)
https://galaktyk.medium.com/how-to-build-opencv-with-gstreamer-b11668fa09c 3/14
3/9/23, 8:43 AM How to compile OpenCV with Gstreamer [Ubuntu&Windows] | by Galaktyk 01 | Medium

✔ check the GStreamer section.


(If they aren’t say YES, go check GStreamer lib package)

if something went wrong just remove build folder and try again.

7. Building

sudo make -j$(nproc)

It will take a long time, Go grab some coffee. ☕

◾ Install package

https://galaktyk.medium.com/how-to-build-opencv-with-gstreamer-b11668fa09c 4/14
3/9/23, 8:43 AM How to compile OpenCV with Gstreamer [Ubuntu&Windows] | by Galaktyk 01 | Medium

sudo make install


sudo ldconfig

## WINDOWS

Windows 10 1903
python 3.7.0
OpenCV 4.1.0

https://galaktyk.medium.com/how-to-build-opencv-with-gstreamer-b11668fa09c 5/14
3/9/23, 8:43 AM How to compile OpenCV with Gstreamer [Ubuntu&Windows] | by Galaktyk 01 | Medium

Gstreamer 1.16.4
Cmake 3.14.5
Visual Studio 2019

1. Uninstall old opencv-python

pip uninstall opencv-python

2. Install numpy

pip install numpy

3. Download gstreamer and opencv


◾ Install both gstreamer-runtime and gstreamer-development package in the same
location
>> https://gstreamer.freedesktop.org/download/

https://galaktyk.medium.com/how-to-build-opencv-with-gstreamer-b11668fa09c 6/14
3/9/23, 8:43 AM How to compile OpenCV with Gstreamer [Ubuntu&Windows] | by Galaktyk 01 | Medium

◾ Download opencv release sources (.zip file) and extract.


>> https://github.com/opencv/opencv/archive/4.1.0.zip

4. Set Path Variable


◾ Add gstreamer to Path variable

◾ Add system variable “GSTREAMER_DIR” “C:\gstreamer\1.0\x86_64”

5. CmakeGUI & Visual Studio


◾ install CmakeGUI 3.14.5
CmakeGUI >> https://cmake.org/download/

Visual Studio 2019(Community version is fine)


>> https://visualstudio.microsoft.com/downloads/

◾ Open CmakeGUI.
◾ Select opencv source and build folder.

https://galaktyk.medium.com/how-to-build-opencv-with-gstreamer-b11668fa09c 7/14
3/9/23, 8:43 AM How to compile OpenCV with Gstreamer [Ubuntu&Windows] | by Galaktyk 01 | Medium

◾ Hit Configure, select your Visual Studio version then click Finish

https://galaktyk.medium.com/how-to-build-opencv-with-gstreamer-b11668fa09c 8/14
3/9/23, 8:43 AM How to compile OpenCV with Gstreamer [Ubuntu&Windows] | by Galaktyk 01 | Medium

◾ Click Configure again, the red value will change to white.

◾ Click Generate

◾ Click “Open Project”

◾ in Visual Studio:
switch from DEBUG to RELEASE and x64

https://galaktyk.medium.com/how-to-build-opencv-with-gstreamer-b11668fa09c 9/14
3/9/23, 8:43 AM How to compile OpenCV with Gstreamer [Ubuntu&Windows] | by Galaktyk 01 | Medium

◾ Right click on INSTALL and select Build

😉👌

◾ Finally, add bin & lib folder to your env PATH , (from C:\opencv-
4.1.0\build\install\x64\vc16)

https://galaktyk.medium.com/how-to-build-opencv-with-gstreamer-b11668fa09c 10/14
3/9/23, 8:43 AM How to compile OpenCV with Gstreamer [Ubuntu&Windows] | by Galaktyk 01 | Medium

Test
◾ Identify the location of a cv2 module

import cv2
print(cv2.__file__)"

https://galaktyk.medium.com/how-to-build-opencv-with-gstreamer-b11668fa09c 11/14
3/9/23, 8:43 AM How to compile OpenCV with Gstreamer [Ubuntu&Windows] | by Galaktyk 01 | Medium

◾ Check build information

print(cv2.getBuildInformation())

https://galaktyk.medium.com/how-to-build-opencv-with-gstreamer-b11668fa09c 12/14
3/9/23, 8:43 AM How to compile OpenCV with Gstreamer [Ubuntu&Windows] | by Galaktyk 01 | Medium

import cv2
cap = cv2.VideoCapture('autovideosrc ! videoconvert ! appsink')
while True:
ret,frame = cap.read()
cv2.imshow('',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
cap.release()

https://galaktyk.medium.com/how-to-build-opencv-with-gstreamer-b11668fa09c 13/14
3/9/23, 8:43 AM How to compile OpenCV with Gstreamer [Ubuntu&Windows] | by Galaktyk 01 | Medium

Enjoy 🐔

Python Gstreamer Opencv

About Help Terms Privacy

Get the Medium app

https://galaktyk.medium.com/how-to-build-opencv-with-gstreamer-b11668fa09c 14/14

You might also like