简体   繁体   中英

OpenCV Videocapture Grab and Retrieve

I've had this issue for a long time and I'm not sure whats going on. So i have a loop from which nextFrame is called, now the issue lies with what the imshow actually shows.

I specifically want one image every time i call cap.grab() and cap.retrieve() , but it seems to have this buffer internally in the "cap" object, so instead on getting individual instantaneous images i would get a sequence/images of images when i click through the images, then after 3/4 frames a new sequence.

How do i get single frames?

cap is a VideoCapture object, maxCount is the size of the vector.

void CamLoop::nextFrame() {
.
.
.
    //if first loop fill a vector<Mat> with random Mats from camera
    if (firstLoop) {
        Mat buff;
        cap >> buff;
        for(int i = 0; i<(maxCounter); i++) {
            buffer.push_back(buff);
        }
    }

    projector.nextCode();

    if (!customImages) {
        cap.grab();
        Mat buff;
        cap.retrieve(buff);


//tried this way too
//cap >> buff;

        buffer[counter] = buff;

        setMouseCallback( "Camera", mouseFunc, this );
        imshow("Camera", buffer[counter]);
        waitKey(1);
    }
.
.
.
counter++;
}

I am using Linux Mint Rosa with OpenCV 3.1.0 on Eclipse Mars

EDIT The problem is that VideoCapture has a buffer, try this on your own computer in debug mode, the frames aren't live, how would i over come this issue?

I tried using

cap.set(CV_CAP_PROP_BUFFERSIZE,1);

but it gives me this error.

VIDEOIO ERROR: V4L2: setting property #38 is not supported

also tried

cap.set(CV_CAP_PROP_MODE,1);

but it gives me this error.

VIDEOIO ERROR: V4L2: setting property #9 is not supported

EDIT It may be the camera with the buffer and not the VideoCapture object itself.

A slow and cheat fix may be to do

cap.open( *CAMERA_NUM* );

in the loop, this is slow but it achieves still images without the buffer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM