OpenCV VideoCapture doesn't work inside Visual Studio 2017 (Windows 10)

1

I have a very strange problem. VideoCapture does not open nor webcam nor video file when I run the C++ application from Visual Studio and in the case of webcam gives me the following error:

WinRT originate error - 0xC00D36B3 : 'The stream number provided was invalid.'

followed by

Microsoft C++ exception: _com_error at memory location 0x000000D9B66FCBB0. Microsoft C++ exception: _com_error at memory location 0x000000D9B66FCAA0. Microsoft C++ exception: cv::Exception at memory location 0x000000D9B66FEFD0. Microsoft C++ exception: cv::Exception at memory location 0x000000D9B66FEFD0.

But when I run the app from outside VS - everything works. I use OpenCV v4.0.0

windows
opencv
video-capture
asked on Stack Overflow Apr 4, 2019 by Alexey Bokov • edited Apr 5, 2019 by nathancy

1 Answer

0

To diagnose your problem, try the following first and give me feedback.

#include <opencv2/opencv.hpp>

using namespace cv;

int main()
{
    VideoCapture cap(0); // open the default camera
    if (!cap.isOpened())  // check if we succeeded
        return -1;

    Mat edges;
    Mat frame;
    namedWindow("edges", WINDOW_NORMAL);

    while (true)
    {
        cap >> frame; // get a new frame from camera
        cvtColor(frame, edges, COLOR_RGB2GRAY);
        GaussianBlur(edges, edges, Size(7, 7), 1.5, 1.5);
        Canny(edges, edges, 0, 50, 3);
        imshow("edges", edges);
        if (waitKey(30) >= 0) break;
    }
    // the camera will be deinitialized automatically in VideoCapture destructor
}

The required libs:

opencv_core401.lib
opencv_imgproc401.lib
opencv_videoio401.lib
opencv_highgui401.lib
answered on Stack Overflow Apr 5, 2019 by Kim Jong Un

User contributions licensed under CC BY-SA 3.0