Enter values into a FIFO array

9 次查看(过去 30 天)
Hello,
I have an array called
frameBuffer = zeros (height, width, numChannels, framesPerSymbol);
and a video. The parameters of the frameBuffer are height, width, number of color channels and framesPerSymbol, which will be the number of frames that my symbol lasts.My goal is to insert frames of the video in the array as if it were a FIFO queue, that is, if framesPerSymbol is 5:
F = frames E = empty
1) E E E E E
2) F E E E E
3) F F E E E
4) F F F E E
5) F F F F E
6) F F F F F
Thanks in advance.

采纳的回答

Mehmed Saad
Mehmed Saad 2020-4-20
编辑:Mehmed Saad 2020-4-20
I think you are trying to save last five frames in a buffer, but a for loop is not required for that purpose
frameBuffer=zeros (height, width, numChannels, framesPerSymbol);
framesInBuffer = 0;
While loop
while hasFrame(videoObject)
frame = double(readFrame(videoObject));
I made a change here
frameBuffer = shiftBuffer(frameBuffer,frame);
framesInBuffer = framesInBuffer + 1;
if framesInBuffer > framesPerSymbol
framesInBuffer = framesPerSymbol;
bypassEncoding = false;
else
bypassEncoding = true;
end
if ~bypassEncoding
if canWeEncode(frameBuffer,alpha,threshold)
encodedBuffer = steganographicEncoding(frameBuffer,width,height,codeRows,codeCols,alpha,sigma);
writeBufferToFinalVideo(encodedBuffer,100);
else
writeFrameToFinalVideo(squeeze(frameBuffer(:,:,:,1)));
end
end
end
and a change here
function frameBuffer = shiftBuffer (frameBuffer,frame)
frameBuffer = circshift(frameBuffer,1,4);
frameBuffer(:,:,:,1) = frame;
end
  1 个评论
Alber
Alber 2020-4-20
编辑:Alber 2020-4-20
Yes, my idea is that when the buffer is full, to see if I can encode and after this is done it will take me another 5 frames, so until I complete all the frames of the video and can you explain this part?
function frameBuffer = shiftBuffer (frameBuffer,frame)
frameBuffer = circshift(frameBuffer,1,4);
frameBuffer(:,:,:,1) = frame;
end
I want to take 5 frames, I encode (the whole loop below) and I will take another 5, like this until I complete all the frames of the video.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Computer Vision with Simulink 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by