OpenCV 视频捕获抓取和检索

问题描述 投票:0回答:1

这个问题我已经困扰很长时间了,但我不确定发生了什么。 所以我有一个调用

nextFrame
的循环,现在问题在于
imshow
实际显示的内容。

我每次调用

cap.grab()
cap.retrieve()
时特别想要一张图像,但似乎在“cap”对象内部有这个缓冲区,所以在获取单个瞬时图像时,我会得到图像的序列/图像我单击图像,然后在 3/4 帧后生成一个新序列。

如何获取单帧?

cap 是一个 VideoCapture 对象,maxCount 是向量的大小。

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++;
}

我在 Eclipse Mars 上使用 Linux Mint Rosa 和 OpenCV 3.1.0

编辑 问题是 VideoCapture 有一个缓冲区,在您自己的计算机上以调试模式尝试此操作,帧不是实时的,我将如何解决这个问题?

我尝试使用

cap.set(CV_CAP_PROP_BUFFERSIZE,1);

但它给了我这个错误。

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

也尝试过

cap.set(CV_CAP_PROP_MODE,1);

但它给了我这个错误。

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

编辑 它可能是带有缓冲区的相机,而不是 VideoCapture 对象本身。

c++ linux opencv video-capture
1个回答
0
投票

可能需要进行缓慢且作弊的修复

cap.open( *CAMERA_NUM* );

在循环中,这很慢,但它可以在没有缓冲区的情况下实现静态图像。

© www.soinside.com 2019 - 2024. All rights reserved.