Why I couldn't get frames from my webcam ?

asked 2018-07-26 07:25:21 -0500

I'm trying to calibrate my webcam but the problem is that I got just one frame 'one image' then the camera exit automatically, I couldn't recognize the problem since this is the first time I use opencv

this the code:

VideoCapture vid(0);
    if (!vid.isOpened())
        return 0;
    int framesPerSeconds = 20;
    namedWindow("webCam", CV_WINDOW_AUTOSIZE);
    while (true) {
        if (!vid.read(frame))
            vector<Vec2f> foundPoints;
            bool found = false;
            found = findChessboardCorners(frame, chessboardDimension, foundPoints, CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_NORMALIZE_IMAGE);
            drawChessboardCorners(drawToFrame, chessboardDimension,foundPoints,found);
            if (found)
                imshow("webCam", drawToFrame);
                imshow("webCam", frame);
            char character = waitKey(1000/ framesPerSeconds);

    return 0;
edit retag flag offensive close merge delete


I believe you need a waitKey(0). I'm not super familiar with c++ but in python, you must have cv2.waitKey(0), otherwise the images will not update.

jarulsamy gravatar imagejarulsamy ( 2018-07-30 00:03:35 -0500 )edit