Effacer les filtres
Effacer les filtres

Insert elements into a 4D array

5 vues (au cours des 30 derniers jours)
Alber
Alber le 9 Avr 2020
Hello,
I have a 4-dimensional buffer called:
frameBuffer = zeros (width, height, numChannels, framesPerSymbol);
in which I want to insert 3-dimensional video frames (width, height, numChannels). The variable framesPerSymbol is the number of frames that will go in the buffer, that is, if framesPerSymbol is 10, my buffer will be 10.
And this is where I run it:
frameBuffer = zeros(width, height, numChannels,framesPerSymbol);
framesInBuffer = 0;
while hasFrame(videoObject)
frame = readFrame(videoObject);
shiftBuffer(frameBuffer,frame); % <--------- THIS IS THE PART
% We update the framesInBuffer counter
framesInBuffer = framesInBuffer + 1;
if framesInBuffer > framesPerSymbol
framesInBuffer = framesPerSymbol;
bypassEncoding = false;
else
bypassEncoding = true;
end
end
The way I was doing the insert was like this, but I don't get results:
function [] = shiftBuffer (frameBuffer,frame)
N = size(frameBuffer,4); % Buffer size
for i = 1:N
frameBuffer(i) = frame;
end

Réponse acceptée

Srivardhan Gadila
Srivardhan Gadila le 12 Avr 2020
There are 2 mistakes in the above implementation:
  1. Accessing a frame of frameBuffer as frameBuffer(i) instead of frameBuffer(:,:,:,i)
  2. The function shiftBuffer changes the values of frameBuffer locally in the function and in the main code the frameBuffer isn't changed.
I suggest you to make the following changes.
Change the function shiftBuffer as follows:
function frameBuffer = shiftBuffer(frameBuffer,frame,framesInBuffer)
frameBuffer(:,:,:,,framesInBuffer) = frame;
end
and the following lines in your code
frame = readFrame(videoObject);
shiftBuffer(frameBuffer,frame); % <--------- THIS IS THE PART
% We update the framesInBuffer counter
framesInBuffer = framesInBuffer + 1;
to
frame = readFrame(videoObject);
% We update the framesInBuffer counter
framesInBuffer = framesInBuffer + 1;
frameBuffer = shiftBuffer(frameBuffer,frame,framesInBuffer);

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by