フィルターのクリア

Insert elements into a 4D array

5 ビュー (過去 30 日間)
Alber
Alber 2020 年 4 月 9 日
回答済み: Srivardhan Gadila 2020 年 4 月 12 日
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

採用された回答

Srivardhan Gadila
Srivardhan Gadila 2020 年 4 月 12 日
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);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatched Filter and Ambiguity Function についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by