1
votes

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.

1
What is maxCounter? Where do you increment counter? Anyway, cap >> buff should give you one frame into buff.A. Sarid
Clone the buffer after you capture it. CV::Mat doesn't do a deep copy by default, so you've got a ton of references to the same underlying array (read the documentation)Dan Mašek
edited question, cloning the buffer doesnt help .Vroosh
A.Sarid the problem is more that there seems to be this weird buffer in VideoCapture so the image 'cap>>buff' would give me isnt the next frame from the camera, its from this strange bufferVroosh
are you sure the buffer is in VideoCapture and not in your camera? For me there is only 2 buffered images afair.Micka

1 Answers

0
votes

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.