Build opencv with gstreamer

因为从pip 下载的公开仓库的 opencv-python 并不包含 gstreamer 的调用,所以要使用opencv  + gstreamer 需要自行build opencv 并把 gstreamer build 进去。

编译方法如下:

安装gstreamer

sudo apt-get install gstreamer1.0*

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

编译opencv

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 \
-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 ..