luckyging3r
luckyging3r

Reputation: 3165

OpenCV - Webcam imshow not displaying live feed, gray screen instead

I am working with OpenCV version 3.2.0 in Visual Studio 2015 and have been able to access my webcam until all of a sudden when I was working on it this morning. I can't figure out where this problem is coming from. I now get:

enter image description here

It doesn't throw any errors but it also doesn't show any input through the webcam

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace std;
using namespace cv;    

int main(int argc, char** argv)
{
    VideoCapture cap;
    cap.open(0);
    if (!cap.isOpened())
    {
        printf("--(!)Error opening video capture\n");
        return -3;
    }


    Mat image;
    namedWindow("Image", CV_WINDOW_AUTOSIZE);
    while (1)
    {
        cap.read(image);

        imshow("Image", image);
        waitKey(30);
    }


    return 0;
}

Has anyone encountered this error before?

Edit: Things I have looked at:

My webcams that I have work in things like Google Hangouts so I don't think it's a webcam issue.

Also, I uninstalled Visual Studio 2015 and installed Visual Studio 2017 to see if reinstalling would work and still get the same results.

Edit:

I am getting the error <information not available, no symboles loaded for opencv_world320d.dll> when I create a new VideoCapture object. I am pretty sure I have everything included correctly.

Configuration Properties -> C/C++ -> Additional Include Directories: $(OPENCV_BUILD)\include

Configuration Properties -> Linker -> General: $(OPENCV_BUILD)\x64\vc14\lib

Configuration Properties -> Linker -> Input: opencv_world320d.lib

Upvotes: 1

Views: 2051

Answers (2)

luckyging3r
luckyging3r

Reputation: 3165

As suggested by @michael scolfield, it was a problem with my antivirus blocking my webcam. I couldn't figure out how to exclude my Visual Studio directory so I just tried uninstalling it and it worked. It would be nice to have antivirus and have this working so I'll need to figure that out. But for temps this will work.

Upvotes: 0

michael scolfield
michael scolfield

Reputation: 431

I encountered the same problem after obtaining Opencv via compiling and building source using CMake. Then, I deleted them and installed Opencv from prebuilt binaries. I have run the code again and there was no problem.

Upvotes: 2

Related Questions