c++ - 来自视频文件的垫子数组 - opencv

标签 c++ arrays opencv mat

我在 Linux 上使用 C++ 和 opencv 进行编码。我找到了 this类似的问题;虽然,我不能完全让它工作。

我想做的是读取视频文件并将一定数量的帧存储在数组中。超过这个数字,我想删除第一帧并将最新的帧添加到数组的末尾。

到目前为止,这是我的代码。

VideoCapture cap("Video.mp4");
int width = 2;
int height = 2;
Rect roi = Rect(100, 100, width, height);

 vector<Mat> matArray;
int numberFrames = 6;
int currentFrameNumber = 0;

for (;;){

    cap >> cameraInput;
    cameraInput(roi).copyTo(finalOutputImage);

    if(currentFrameNumber < numberFrames){
        matArray.push_back(finalOutputImage);
    }else if(currentFrameNumber <= numberFrames){
        for(int i=0;i<matArray.size()-1; i++){
            swap(matArray[i], matArray[i+1]);
        }
        matArray.pop_back();
        matArray.push_back(finalOutputImage);
    }

    currentFrameNumber++;
 }

我对垫子的理解表明这可能是指针的问题;我只是不确定如何解决它。当我查看垫子阵列时,每个元素都是相同的框架。谢谢。

最佳答案

如果您要使用 C++ 非常有用的 STL,则无需所有这些复杂的操作。

if( currentFrameNumber >= numberFrames )
    matArray.remove( matArray.begin() );
matArray.push_back( finalOutputImage.clone() );     //check out @berak's comment

应该这样做。

关于c++ - 来自视频文件的垫子数组 - opencv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26412268/

相关文章:

python - 在 Numpy 数组中查找子列表的索引

python - “int”对象在列表中不可迭代

c - 循环时如何在opencv中显示图像?

opencv - LabVIEW 使用 C DLL 使用 OpenCV DLL

c++ - 使用具有尾随返回类型的 lambda 尝试 SFINAE 时出现硬错误

c++ - 实现从 Java 到 C++ 的飞跃

java - 是否可以创建一个数组列表?

C++/opencv : how to delete specific path pixels in efficient way

c++ - 如何用 `int32_t` 值快速填充内存?

c++ - 析构函数很懒惰,为什么?