Blue screen when using VideoCapture

asked 2016-04-23 11:11:13 -0600

XXXjimmy gravatar image

I'm accessing the front and back cameras of my surface pro 4. When I run my code the program usually get stuck at the following line and I get a bluescreen after a while.

std::VideoCapture vidCap(1);

Strangely it doesn't always happen. Sometimes (about 1 out of 5 tries) the programm works perfectly fine and I can see my camera stream. Do you guys have ideas what I can do?

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

int main()
{
    const char* windowName = "Webcam Stream";
    cv::namedWindow(windowName, CV_WINDOW_AUTOSIZE);
    cv::Mat frame;
    cv::VideoCapture vidCap(1);

    while (vidCap.isOpened()) {
        vidCap >> frame;

        cv::cvtColor(frame, frame, CV_BGR2GRAY);
        cv::imshow(windowName, frame);

        int k = cv::waitKey(33);
        if (k == 27) {
            break;
        }
    }
    return 0;
}
edit retag flag offensive close merge delete

Comments

Is your cam id =1 available ? did you try the default cv::VideoCapture vidCap(0); ?

pklab gravatar imagepklab ( 2016-04-23 12:02:13 -0600 )edit

I have got a surface pro4 and I like to use a logitech webcam with cv::VideoCapture vidCap(2);

LBerger gravatar imageLBerger ( 2016-04-23 14:54:17 -0600 )edit

@pklab 0 is the back camera and 1 is the front camera. Somethimes it works can I can see the stream perfectly and the next time I run it ends in a bluescreen.

@LBerger have you tried it with your surface cameras? USB Cameras w. vidCap(2) works perfectly for me aswell. I guess the bluescreens are driver realated. What confusses me is that sometimes I can access the onboard cameras perfectly fine.

XXXjimmy gravatar imageXXXjimmy ( 2016-04-24 09:06:13 -0600 )edit

Yes I tried too. With 0 and 1 it is too slow and sometines blue screen.

Problem is not opencv. With my logitech webcam there is no problem.

I think that origin is Windows Hello which need facial recognition. In camera driver you can check if pcl64.dll is included (or pcl.dll).

LBerger gravatar imageLBerger ( 2016-04-24 09:19:24 -0600 )edit