forked from damon-demon/Transform-Based-Tensor-Net
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataGenerator.m
33 lines (29 loc) · 1.11 KB
/
DataGenerator.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function [trainData] = DataGenerator(nOfFme, vidWid, vidHigh, fmeWid, fmeHigh)
totalDataNum = 0;
fileList = dir('*.mp4');
nOfFile = length(fileList);
for i = 1:1:nOfFile
fileName = strcat(fileList(i).name);
obj = VideoReader(fileName);
totalDataNum = totalDataNum + obj.NumberOfFrames;
end
fprintf("Total data %d.\n", totalDataNum/nOfFme);
trainData = single(zeros(fix(totalDataNum/nOfFme), fmeHigh, fmeWid, nOfFme));
numOfData = 0;
for i = 1:1:nOfFile
fprintf("File: %d/%d.\n", i, nOfFile);
fileName = strcat(fileList(i).name);
obj = VideoReader(fileName);
for j=1:nOfFme:(obj.NumberOfFrames-nOfFme)
numOfData = numOfData + 1;
fprintf("num=%d\n", numOfData);
for k=1:1:nOfFme
frame = read(obj, j+k-1);
yCbCr = rgb2ycbcr(frame);
trainData(numOfData, :, :, k) = imresize(reshape(yCbCr(:, :, 1), vidHigh, vidWid), [fmeHigh, fmeWid]);
%imshow(reshape(trainData(numOfData, :, :, k), fmeHigh, fmeWid), []);
end
end
clear frame yCbCr;
end
end