1

I use VS 2010, with opencv. Whatever i try when i want to use my wecamera (on my laptop), i get this: "r6010 abort() has been called". And a gray window shows up. Here is the code:

#include<opencv\cv.h>
#include<opencv\highgui.h>

using namespace cv;


int main()
{

    Mat image;

    VideoCapture cap;
    cap.open(0);

    namedWindow("Window", 1);

    while (1)
    {
        cap >> image;
        imshow("Windwow",image);
        waitKey(33);
    }

}

Btw, in another program, what i got from youtube, it says "Error: Frame is NULL".

zmbq
  • 38,013
  • 14
  • 101
  • 171

1 Answers1

0

On my laptop, I have to use device 1 to access the webcam. You should also check whether cap is opened, e.g.

cap.open(1);
if(!cap.isOpened())
    return -1;
Bull
  • 11,771
  • 9
  • 42
  • 53
  • Cap is opened, the problem isn't that. – user3700740 Jul 21 '14 at 20:10
  • Which line is actually causing it to crash? Does image get its data set when you read from cap? – Bull Jul 21 '14 at 20:13
  • this line: imshow("Windwow",image); If i balk that line, it works. Exactly the program useless then, but i dont get any error. – user3700740 Jul 21 '14 at 21:01
  • I would think that image.data is null then. How did you check that "Cap is opened"? I suggest `bool VideoCapture::read(Mat& image)` instead of `>>` so you can check the status easily. – Bull Jul 22 '14 at 00:13
  • BTW, what version of OpenCV are you using? – Bull Jul 22 '14 at 00:17
  • I checked it on this way like you said to do it: cap.open(0); if(!cap.isOpened()) return -1; And I use OpenCV 2.4.9 version – user3700740 Jul 22 '14 at 00:50