frames extraction from a video

조회 수: 1 (최근 30일)
THONTI BEERAIAH
THONTI BEERAIAH 2020년 8월 24일
댓글: THONTI BEERAIAH 2020년 8월 25일
hey
I have written a code to extract frames of two different cropped ares from a video and to evaluate intensity of cropped areas separately as below but I am getting error saying CL=S.BL(reference field is non existance) please help me fix this
% The code is process the candle images
clear;
close all;
clc;
%% Loading video of candle flickering
A = VideoReader('Augtencm.mp4');
nf = A.NumFrames;
if nf<200
B = read(A);
else
part = floor(nf/200);
for ii = 1:part
ii
B = read(A,[(ii-1)*200+1 (ii-1)*200+200]);
%eval(['B_' num2str(ii) '= read(A,[(ii-1)*200+1 (ii-1)*200+200]);']);
BL = B(280:620,235:445,:,:);
BR = B(50:620,720:850,:,:); % Comment and save the total frame for 1 or 2 parts first
filename = ['Augtencm' num2str(ii) '.mat'];
save(filename, 'B', '-v7.3');
end
end
%C = B(:,:,:,:); %Height, Width, Color Plane, Frame Number, where Color Plane is in the order Red, Green, Blue
%save('C0034.mat', 'C', '-v7.3'); % Saving as 4D matrix for future use.
%% loading the matfile
S = load('Augtencm1.mat');
CL = S.BL;
CR = S.BR;
%% Showing frames
for t = 1:200
t
imshow(B(280:620,235:445,:,t));
imshow(B(50:620,720:850,:,t)); % modify by trial and error to retain the exact flame zone
pause(0.1)
end
%% Cropping the matrix and calculating
part=4;
for ii = 1:part
ii
filename = ['Augtencm1' num2str(ii) '.mat'];
S = load(filename);
CL = S.BL;
CR = S.BR;
%C2 = C(70:650,900:1220,:,:);
[h,w,c,t] = size(CR);
for i = 1:t
cr = CR(:,:,:,i);
cl = CL(:,:,:,i);
cr = cr(:,:,:);
cl = cl(:,:,:);
ccr = rgb2gray(cr);
ccl = rgb2gray(cl);
sr((ii-1)*200+i) = sum(sum(ccr))/(h*w);
sl((ii-1)*200+i) = sum(sum(ccl))/(h*w); % area average intensity
end
end
%% plotting intensity time series
fps = 240; % this should be actual fps of recording
t = part*200;
T = 1/fps:1/fps:t/fps;
figure(1)
plot(T,sr);
plot(T,sl);
set(gca,'linewidth',1,'fontsize',12); %xlim([0 10000]); %ylim([-2 2]);
xlabel('Time (s)')
ylabel('Intensity (a.u.)')
%savefig('Augtencm.fig')
%%

답변 (1개)

Image Analyst
Image Analyst 2020년 8월 24일
Leave the semicolon off and put S on a line:
S = load(filename)
S
fieldnames(S)
What do you see in the command window? Chances are you will not see a field called BL. Attach your mat file if you need more help.
  댓글 수: 3
Image Analyst
Image Analyst 2020년 8월 25일
Well there you go. There is no such field. Why do you think there should be? By the way, when I said "what do you see" I meant for you to share it with me by copying and pasting back here.
If you want to create a new field called BL, you can attach one so S simply by assigning it:
S.BL = 42; % or whatever you want it to be.
THONTI BEERAIAH
THONTI BEERAIAH 2020년 8월 25일
I am sorry I am new here and thank you sir for your answer

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by