cv2.VideoCapture 打开 Gstreamer 管道时出错

cv2.VideoCapture error when open Gstreamer pipeline

我正在尝试使用 opencv-python 在 window10 上像这样打开 gstreamer 管道

cv2.VideoCapture('videotestsrc ! video/x-raw,framerate=20/1 ! videoscale ! videoconvert ! appsink', cv2.CAP_GSTREAMER)

我已经安装了gstreamer并进行了测试,但是VideoCapture没有打开。 所以我使用 print(cv2.getBuildInformation()) 并检查 gstreamer 没有像下面那样构建

Video I/O:
    DC1394:                      NO
    FFMPEG:                      YES (prebuilt binaries)
      avcodec:                   YES (58.91.100)
      avformat:                  YES (58.45.100)
      avutil:                    YES (56.51.100)
      swscale:                   YES (5.7.100)
      avresample:                YES (4.0.0)
    GStreamer:                   NO
    DirectShow:                  YES
    Media Foundation:            YES
      DXVA:                      NO

现在,我不知道如何使用 gstreamer 构建 opencv。:(

我 运行 遇到了这个完全相同的令人沮丧的问题。幸运的是,这里有一个解决它的便捷指南:https://medium.com/@galaktyk01/how-to-build-opencv-with-gstreamer-b11668fa09c

总而言之,您必须使用 cmake 手动构建 gstreamer opencv 才能正确配置它。根据我的经验,这大约需要 1-2 小时,编译时间为 1 小时。希望对你有用!