我没有为 C++ opencv 相机捕获加载正确的 gstreamer dll

I don't have the proper gstreamer dll loaded for C++ opencv camera capture

我已经使用 Python 和 opencv 成功捕获了网络摄像头,但现在我正在回到 C++ 并尝试执行相同的简单功能。

这是我的(精简版)代码:

#include <iostream>
#include <opencv2\opencv.hpp>
#include <opencv2\imgcodecs.hpp>
using namespace cv;
using std::cout;
using std::endl;
using std::string;
int main()
{
    Mat img;
    VideoCapture cam(0);
    if (cam.isOpened()) {
        cout << "Camera is opened." << endl;
    } else {
        cout << "Camera is NOT opened." << endl;
    }
    const string camWin{ "Rufus' Webcam" };
    namedWindow(camWin);
    while (1) {
        cam >> img;
        imshow(camWin, img);
        if (waitKey(1) == 27)
            break;
    }
    cam.release();
}

这是我在 运行:

时得到的错误

attempting to open the camera using opencv. [ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\videoio_registry.cpp (191) cv::`anonymous-namespace'::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Enabled backends(7, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940) [ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\backend_plugin.cpp (370) cv::impl::getPluginCandidates Found 2 plugin(s) for GSTREAMER [ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\backend_plugin.cpp (175) cv::impl::DynamicLib::libraryLoad load C:\Users\rufuss\source\repos\OpenCVinCPP\x64\Debug\opencv_videoio_gstreamer450_64d.dll => FAILED [ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\backend_plugin.cpp (175) cv::impl::DynamicLib::libraryLoad load opencv_videoio_gstreamer450_64d.dll => FAILED [ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\backend_plugin.cpp (370) cv::impl::getPluginCandidates Found 2 plugin(s) for MSMF [ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\backend_plugin.cpp (175) cv::impl::DynamicLib::libraryLoad load C:\Users\rufuss\source\repos\OpenCVinCPP\x64\Debug\opencv_videoio_msmf450_64d.dll => OK [ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\videoio\src\backend_plugin.cpp (236) cv::impl::PluginBackend::PluginBackend Video I/O: loaded plugin 'Microsoft Media Foundation OpenCV Video I/O plugin' Camera is opened.

(基本没找到:opencv_videoio_gstreamer450_64d.dll,因为不存在,所以不是路径问题)

我也需要一些帮助:

  1. 正在正确安装缺少的 dll:opencv_videoio_gstreamer450_64d.dll。 或
  2. 正在从 opencv 搜索列表中禁用 gstreamer。

两者都对我有帮助,但实际上我想了解这两种技术,以供将来参考。

您可以尝试添加 cam.open(0, CAP_DSHOW);

#include <iostream>
#include <opencv2\opencv.hpp>
#include <opencv2\imgcodecs.hpp>
using namespace cv;
using std::cout;
using std::endl;
using std::string;
int main()
{
    Mat img;
    VideoCapture cam;
    cam.open(0, CAP_DSHOW);
    if (cam.isOpened()) {
        cout << "Camera is opened." << endl;
    }
    else {
        cout << "Camera is NOT opened." << endl;
    }
    const string camWin{ "Rufus' Webcam" };
    namedWindow(camWin);
    while (1) {
        cam >> img;
        imshow(camWin, img);
        if (waitKey(1) == 27)
            break;
    }
    cam.release();
}

如果您想了解更多信息,请参阅 this

您也可以在构建时执行 cmake -DWITH_GSTREAMER=OFF 以禁用 gstreamer。 (参见 this