简体   繁体   中英

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

I have successfully capture the webcam using Python and opencv but now I am getting back into C++ and trying to do the same simple functionality.

Here's my (trimmed down) code:

#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();
}

This is the error I get when I run:

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.

(basically it doesn't find: opencv_videoio_gstreamer450_64d.dll, because it doesn't exist, so not a path problem)

I could use some help either:

  1. Installing the missing dll: opencv_videoio_gstreamer450_64d.dll properly. or
  2. Disabling gstreamer from the opencv search list.

Either would help me, but I'd actually like to know both techniques, for future reference.

You may try adding 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();
}

If you would like to learn more please see this .

Also you could do cmake -DWITH_GSTREAMER=OFF while building, to disable gstreamer. (see this )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM