安装 gstreamer 对 opencv python 包的支持
Install gstreamer support for opencv python package
我已经从源代码构建了自己的 opencv python 包。
import cv2
print(cv2.__version__)
打印:3.4.5
现在我面临的问题是关于从 opencv 的 VideoCapture class 使用 gstreamer。我正在尝试在 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
捕获失败,生成我上面的打印(参见 if
声明)。我检查了:
import cv2
print(cv2.getBuildInformation())
打印:
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
看到这一点,我的 gstreamer 管道不起作用是绝对有道理的。我确保 WITH_GSTREAMER 在 OpenCV 的 ccmake 期间设置为 ON(它已经是)。问题仍然存在。我什至也尝试将 WITH_GSTREAMER_0_10 设置为 ON。从 cv2 python 模块启用 gstreamer 仍然没有运气。
之前有人建议使用pip3安装cv2。我也试过了。从 pip 获取包的问题是,它根本不允许您配置 gstreamer 支持。
这里有人可以提供帮助吗?
在 opencv support forum 的帮助下,我能够解决这个问题。查看 cmake 输出提示问题:
-- 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
在 ccmake 期间,我将 WITH_GSTREAMER 和 WITH_GSTREAMER_0_10 都设置为 ON。似乎 cmake 更喜欢 gstreamer0.10 标志而不是 gstreamer1.0 标志。由于我只安装了 gstreamer1.0,opencv 完全无法设置 gstreamer 依赖项。
我确保清除所有以前部署的二进制文件:
cd <opencv-src>/build
sudo make uninstall
然后我简单地重新安装,使用调整后的设置(根据我上面的知识):
ccmake ..
make -j8
sudo make install
当我
import cv2
print(cv2.getBuildInformation())
我的控制台现在输出
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
底线是,如果您确实需要 gstreamer1.0,请不要在 cmake 期间将 WITH_GSTREAMER_0_10 设置为 ON。在这种情况下,您只能将 WITH_GSTREAMER 设置为 ON
对于那些在 Windows 上遇到同样问题的人...我必须设置以下 CMake 选项:
- 仅将 "WITH_GSTREAMER" 选项设置为 True,"WITH_GSTREAMER_0_10" 必须为 FALSE
- 添加新条目"GSTREAMER_DIR"=(gstreamer 的路径)
对我来说是 "C:/gstreamer/1.0/x86_64"
我找到了这个解决方案 here
我的OpenCV版本:3.4.3
安装软件包 libgstreamer1.0-dev
和 libgstreamer-plugins-base1.0-dev
帮助我解决了这个问题。
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
我已经从源代码构建了自己的 opencv python 包。
import cv2
print(cv2.__version__)
打印:3.4.5
现在我面临的问题是关于从 opencv 的 VideoCapture class 使用 gstreamer。我正在尝试在 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
捕获失败,生成我上面的打印(参见 if
声明)。我检查了:
import cv2
print(cv2.getBuildInformation())
打印:
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
看到这一点,我的 gstreamer 管道不起作用是绝对有道理的。我确保 WITH_GSTREAMER 在 OpenCV 的 ccmake 期间设置为 ON(它已经是)。问题仍然存在。我什至也尝试将 WITH_GSTREAMER_0_10 设置为 ON。从 cv2 python 模块启用 gstreamer 仍然没有运气。
之前有人建议使用pip3安装cv2。我也试过了。从 pip 获取包的问题是,它根本不允许您配置 gstreamer 支持。
这里有人可以提供帮助吗?
在 opencv support forum 的帮助下,我能够解决这个问题。查看 cmake 输出提示问题:
-- 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
在 ccmake 期间,我将 WITH_GSTREAMER 和 WITH_GSTREAMER_0_10 都设置为 ON。似乎 cmake 更喜欢 gstreamer0.10 标志而不是 gstreamer1.0 标志。由于我只安装了 gstreamer1.0,opencv 完全无法设置 gstreamer 依赖项。
我确保清除所有以前部署的二进制文件:
cd <opencv-src>/build
sudo make uninstall
然后我简单地重新安装,使用调整后的设置(根据我上面的知识):
ccmake ..
make -j8
sudo make install
当我
import cv2
print(cv2.getBuildInformation())
我的控制台现在输出
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
底线是,如果您确实需要 gstreamer1.0,请不要在 cmake 期间将 WITH_GSTREAMER_0_10 设置为 ON。在这种情况下,您只能将 WITH_GSTREAMER 设置为 ON
对于那些在 Windows 上遇到同样问题的人...我必须设置以下 CMake 选项:
- 仅将 "WITH_GSTREAMER" 选项设置为 True,"WITH_GSTREAMER_0_10" 必须为 FALSE
- 添加新条目"GSTREAMER_DIR"=(gstreamer 的路径) 对我来说是 "C:/gstreamer/1.0/x86_64" 我找到了这个解决方案 here
我的OpenCV版本:3.4.3
安装软件包 libgstreamer1.0-dev
和 libgstreamer-plugins-base1.0-dev
帮助我解决了这个问题。
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev