我正在使用C++和opencv在linux上编码。我发现了this类似的问题;虽然,我不能完全实现它的工作。从视频文件的垫阵列 - opencv
我想要做的是读取一个视频文件,并在数组中存储一定数量的帧。在这个数字上,我想删除第一帧并将最近的帧添加到数组的末尾。
这是我的代码到目前为止。
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++;
}
我对垫子的理解说这可能是指针问题;我只是不知道如何解决它。当我查看垫子阵列时,每个元素都是同一个框架。谢谢。
如果你想使用数组来存储'numberFrames'最后一帧,为什么你要使用'} else if(currentFrameNumber <= numberFrames){'?如果'currentFrameNumber> numberFrames'会阻止任何事情发生,这将会发生得非常快。所以我会说,无论视频有多长时间,你只是存储第1-6帧(不包括0)。 – Pafka 2014-10-16 19:32:49
Mat只是一个智能指针,你从捕获得到的东西指向* static *内存。你想要的是:'matArray.push_back(finalOutputImage.clone());' – berak 2014-10-16 20:07:41
@Pafka谢谢你指出我的错字。它应该是一个超过标志。仍然没有解决这个问题,但是贝拉克说的确如此。 – tierratheseeress 2014-10-17 20:45:03