I declare a class in matlab and here is the constructor and a function.
function Ri = RGBimages(datadir)
if(isempty(dir(datadir)))
warning([datadir, ' is empty']);
return;
end
Ri.dataSrc=datadir;
Ri.twoEnds = load([datadir,'\seIndex.txt']);
Ri.startFrame = Ri.twoEnds(1);
Ri.endFrame = Ri.twoEnds(2);
Ri.numberOfFrames=Ri.twoEnds(2)-Ri.twoEnds(1)+1;
Ri.faceLmks = zeros(68,2,Ri.numberOfFrames);
end
function obtainFaceLmks(Ri)
indx=1;
for i = Ri.startFrame;%:Ri.endFrame
imstr = [Ri.dataSrc,'\rgb_',num2str(i),'.png'];
[status,result] = system(['fitD -m src\my.amf -h src\haarcascade_frontalface_alt2.xml -i ',imstr,' -n 30']);
if(status==-1)
warning(result);
else
temp=flHelper(result(1:size(result,2)-59));
Ri.faceLmks(:,:,indx)=temp;
end
indx=indx+1;
end
return;
end
then I do this:
ims = RGBimages('data\a01_s01_e01');
ims.obtainFaceLmks();
and it seems ims’s attributes (ims.faceLmks) didn’t change, why?
Thanks for anyhelp
Value classes are passed by value. Consequently, a method should return the (updated) class instance, and you need to capture that. In other words, the method definition should be
and you’d call the method
Handle classes are passed by reference. Consequently, a method doesn’t need to return the updated class instance, and you don’t need to capture it. However, you need to inherit from
handle, and you need to implement a copy method to make a copy of a class instance; assigning to another variable won’t work.See the documentation for further info.