我正在使用matlab進行視頻鏡頭邊界檢測。這裏是我的代碼片段形成一個64×64矩陣的巨陣列
clc;
clear all;
[file path] = uigetfile('*.avi','Pick a Video');% this line opens a pop up window so that you can choose your video for further processing
video = VideoReader([path file]);% the video chosen through UI get stored in video object
numOfFrames = video.NumberOfFrames;% this will be a number (total number of frames in your chosen video)
%allFrames = read(video);% catching all the frames from the video in object allFrames
for i=1:1:numOfFrames
try
lFrame = read(video, i);%frames(:, :, :, i);
catch
break;
end
lRFrame = lFrame(:,:,1);
lGFrame = lFrame(:,:,2);
lBFrame = lFrame(:,:,3);
lGray = 0.299*lRFrame + 0.587*lGFrame + 0.114*lBFrame;
grayImage = imresize(lGray, [256 256]);
% step 2 of the algorithm begins from here %
meanFilterFunction = @(theBlockStructure) mean2(theBlockStructure.data(:)) * ones(1,1, class(theBlockStructure.data));
blockSize = [4 4];
blockyImage4 = blockproc(single(grayImage), blockSize, meanFilterFunction);
end
我得到一個64×64圖像中blockyImage4
但因爲它是在一個循環中,每次刷新值本身很下一次迭代。
我想要一個可以存儲(可能是所有)圖像(矩陣)的圖像數組。我應該可以訪問它們。如果所有圖像都不能存儲在數組中,那麼如何只存儲連續迭代的兩幅圖像,因爲我需要「i」和「i + 1」圖像來找出它們之間的差異。請幫忙
我不確定是否理解了這個問題,但'blockyImage4(:,:,i)= ...'會有幫助嗎? – Adiel
你需要RGB中的所有圖像嗎?也許你可以將幀轉換爲灰度(將它保存在數組中會更容易)。基本上,你可以把它保存爲一個單元格陣列,例如,每個單元格保存關於每一幀的信息(在Matlab中單元格可能非常複雜) – hesar
@hesar現在已經有一個灰度轉換。 – Trilarion