Filter löschen
Filter löschen

Index exceeds array bounds.

1 Ansicht (letzte 30 Tage)
ihsan yeniceri
ihsan yeniceri am 15 Sep. 2020
I have getting error:
Index exceeds array bounds.
Error in Project (line 39)
xa(t)=BB(1)+round(BB(3)/2.8);
These are my code:
opengl software;
clc;
clear all;
% Create the face detector object.
EDetect = vision.CascadeObjectDetector;
% Create the webcam object.
cam = videoinput('winvideo', 1);
d=512;% video length, samples. Time adjustment is 30 fps.
dl=8;% delay for face frame stabilization
di=64;
t=1;
tc=1;
scale=[2:1:32]; % scale for continious wavelet transform used only for picture construction
set(cam,'framesperTrigger',d,'TriggerRepeat',1);
% creating of coordinates tracking vectors in the memory
xa=zeros(1,d);ya=zeros(1,d);xwa=zeros(1,d);yha=zeros(1,d);
xb=zeros(1,d);yb=zeros(1,d);xwb=zeros(1,d);yhb=zeros(1,d);
xd=zeros(1,d);yd=zeros(1,d);xwd=zeros(1,d);yhd=zeros(1,d);
xe=zeros(1,d);ye=zeros(1,d);xwe=zeros(1,d);yhe=zeros(1,d);
xf=zeros(1,d);yf=zeros(1,d);xwf=zeros(1,d);yhf=zeros(1,d);
xg=zeros(1,d);yg=zeros(1,d);xwg=zeros(1,d);yhg=zeros(1,d);
cw=zeros(64,32,2); % reserve memory for cwt picture matrix
scrsz = get(0,'ScreenSize');
figure('Position',[scrsz(3)/4 scrsz(4)/4 scrsz(3)/2 scrsz(4)/2]);% start frame position
start(cam);
while t<d;
colorImage=getdata(cam,1);
colorImage=imresize(colorImage,0.2);
BB = step(EDetect,colorImage);% coordinate rectangle of face
if numel(BB)<1;
colorImage=getdata(cam,1);
BB = step(EDetect,colorImage);
end;
% there I use 6 sub rectangles in the face frame to further
% obtain values color components
xa(t)=BB(1)+round(BB(3)/2.8);
ya(t)=BB(2)-round(BB(4)/10);
xwa(t)=round(BB(3)/4);
yha(t)=round(BB(4)/3);
xb(t)=BB(1)+round(BB(3)/4);
yb(t)=BB(2);
xwb(t)=round(BB(3)/2.15);
yhb(t)=round(BB(4)/5);
xd(t)=BB(1)+round(BB(3)/6);
yd(t)=BB(2)+round(BB(4)/2.3);
xwd(t)=round(BB(3)/4);
yhd(t)=round(BB(4)/6);
xe(t)=BB(1)+round(BB(3)/1.7);
ye(t)=BB(2)+round(BB(4)/2.3);
xwe(t)=round(BB(3)/4);
yhe(t)=round(BB(4)/6);
xf(t)=BB(1)+round(BB(3)/1.4);
yf(t)=BB(2)+round(BB(4)/2.1);
xwf(t)=round(BB(3)/8);
yhf(t)=round(BB(4)/3);
xg(t)=BB(1)+round(BB(3)/6);
yg(t)=BB(2)+round(BB(4)/2.1);
xwg(t)=round(BB(3)/8);
yhg(t)=round(BB(4)/3);
% for coordinate time stabilization I use delay
if t>dl;
xa(t)=round(mean(xa(t-dl:t)));
ya(t)=round(mean(ya(t-dl:t)));
xwa(t)=round(mean(xwa(t-dl:t)));
yha(t)=round(mean(yha(t-dl:t)));
xb(t)=round(mean(xb(t-dl:t)));
yb(t)=round(mean(yb(t-dl:t)));
xwb(t)=round(mean(xwb(t-dl:t)));
yhb(t)=round(mean(yhb(t-dl:t)));
xd(t)=round(mean(xd(t-dl:t)));
yd(t)=round(mean(yd(t-dl:t)));
xwd(t)=round(mean(xwd(t-dl:t)));
yhd(t)=round(mean(yhd(t-dl:t)));
xe(t)=round(mean(xe(t-dl:t)));
ye(t)=round(mean(ye(t-dl:t)));
xwe(t)=round(mean(xwe(t-dl:t)));
yhe(t)=round(mean(yhe(t-dl:t)));
xf(t)=round(mean(xf(t-dl:t)));
yf(t)=round(mean(yf(t-dl:t)));
xwf(t)=round(mean(xwf(t-dl:t)));
yhf(t)=round(mean(yhf(t-dl:t)));
xg(t)=round(mean(xg(t-dl:t)));
yg(t)=round(mean(yg(t-dl:t)));
xwg(t)=round(mean(xwg(t-dl:t)));
yhg(t)=round(mean(yhg(t-dl:t)));
end;
ci=insertShape(colorImage, 'rectangle', BB);
% imege crop for every subrectangle
framecropa=imcrop(colorImage, [xa(t) ya(t) xwa(t) yha(t)]);
framecropb=imcrop(colorImage, [xb(t) yb(t) xwb(t) yhb(t)]);
framecropd=imcrop(colorImage, [xd(t) yd(t) xwd(t) yhd(t)]);
framecrope=imcrop(colorImage, [xe(t) ye(t) xwe(t) yhe(t)]);
framecropf=imcrop(colorImage, [xf(t) yf(t) xwf(t) yhf(t)]);
framecropg=imcrop(colorImage, [xg(t) yg(t) xwg(t) yhg(t)]);
% determining of time color dependences
ga=framecropa(:,:,2);
gta(t)=mean2(ga);
gb=framecropb(:,:,2);
gtb(t)=mean2(gb);
gd=framecropd(:,:,2);
gtd(t)=mean2(gd);
ge=framecrope(:,:,2);
gte(t)=mean2(ge);
gf=framecrope(:,:,2);
gtf(t)=mean2(gf);
gg=framecrope(:,:,2);
gtg(t)=mean2(gg);
%average dependence for G-component
gt=sqrt(sqrt(sqrt(gta.*gtb.*gtd.*gte.*gtf.*gtg)));
ra=framecropa(:,:,1);
rta(t)=mean2(ra);
rb=framecropb(:,:,1);
rtb(t)=mean2(rb);
rd=framecropd(:,:,1);
rtd(t)=mean2(rd);
re=framecrope(:,:,1);
rte(t)=mean2(re);
rf=framecrope(:,:,1);
rtf(t)=mean2(rf);
rg=framecrope(:,:,1);
rtg(t)=mean2(rg);
%average dependence for R-component
rt=sqrt(sqrt(sqrt(rta.*rtb.*rtd.*rte.*rtf.*rtg)));
ba=framecropa(:,:,3);
bta(t)=mean2(ba);
bb=framecropb(:,:,3);
btb(t)=mean2(bb);
bd=framecropd(:,:,3);
btd(t)=mean2(bd);
be=framecrope(:,:,3);
bte(t)=mean2(be);
bf=framecrope(:,:,3);
btf(t)=mean2(bf);
bg=framecrope(:,:,3);
btg(t)=mean2(bg);
%average dependence for B-component
bt=sqrt(sqrt(sqrt(bta.*btb.*btd.*bte.*btf.*btg)));
% wavelet filtration for G-component
[cmA, cmD]=wavedec(gt,4,'Dmey');
cmA(1:cmD(1))=cmA(1:cmD(1)).*1e-6;% 1 component level decreasing
Sumc=cmD(1)+cmD(2)+cmD(3); % 2 and 3 component level stay
Sumc2=cmD(1)+cmD(2)+cmD(3)+cmD(4)+cmD(5);
cmA(Sumc:Sumc2)=cmA(Sumc:Sumc2).*1e-6;% 4 and 5 component level decreasing
gwt=waverec(cmA,cmD,'Dmey'); % reconstruction
stdgwt=std(gwt);
gwt=gwt/stdgwt; % normalization
% wavelet filtration for R-component
[cmA, cmD]=wavedec(rt,4,'Dmey');
cmA(1:cmD(1))=cmA(1:cmD(1)).*1e-6;
Sumc=cmD(1)+cmD(2)+cmD(3);
Sumc2=cmD(1)+cmD(2)+cmD(3)+cmD(4)+cmD(5);
cmA(Sumc:Sumc2)=cmA(Sumc:Sumc2).*1e-6;
rwt=waverec(cmA,cmD,'Dmey');
stdrwt=std(rwt);
rwt=rwt/stdrwt;
% wavelet filtration for B-component
[cmA, cmD]=wavedec(bt,4,'Dmey');
cmA(1:cmD(1))=cmA(1:cmD(1)).*1e-6;
Sumc=cmD(1)+cmD(2)+cmD(3);
Sumc2=cmD(1)+cmD(2)+cmD(3)+cmD(4)+cmD(5);
cmA(Sumc:Sumc2)=cmA(Sumc:Sumc2).*1e-6;
bwt=waverec(cmA,cmD,'Dmey');
stdbwt=std(bwt);
bwt=bwt/stdbwt;
swt=gwt+rwt+bwt;% sum of reconstructed signal of each color component
% finding of peaks for current 64-samples window
if t>di;
[pks,locs] = findpeaks(swt,'MINPEAKDISTANCE',16);
cn=numel(locs)-1;
if numel(locs)>1
gi=1;
while gi<=cn
dg(gi)=locs(gi+1)-locs(gi);
gi=gi+1;
end;
end;
c=round((1/(mean(dg(1:cn))/30))*60);
% rectification of heart rate value using of Fourier multispectra
if t>d-2;
fspec=abs(fft(gwt)).*abs(fft(rwt)).*abs(fft(bwt));
[Fmax,Find] = max(fspec(2:round(d/12)));
c=round((Find+1)*30*60/d);
end;
end;
figure(1);
subplot(121);
imshow(ci);
if t>di
tc=di-1;
subplot(122);
% picture construction
cw=cwt(swt(t-tc+1:t), scale, 'Dmey');
cw=cw./max(max(cw));
cw(cw<0) = 0.1;
surf(cw.^3);
shading interp;
axis([0 64 0 32 0 2]);
set(gca,'Color',[0.16 0.18 0.19]);
set(gca,'YTickLabel',{'180','100','70','50'});
set(gca,'XTickLabel',{'2.0','1.4','0.7','0'});
ylabel({'Heart rate','(beats per minute )'});
xlabel({'Time','(seconds)'});
hold on;
% overlaying of time dependence on the 3D picture
gm=swt(t-tc+1:t);
gm=gm./max(gm);
cp(32,:)=gm./2+1;
cp(cp<0) = 0;
waterfall(cp);
title(['Your heart rate = ',num2str(c) ' beats per minute'])
hold off;
end
t=t+1;
end;
stop(cam);
delete(cam);
clear all;

Antworten (0)

Kategorien

Mehr zu Get Started with Wavelet Toolbox finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by