📄 test1.asv
字号:
% abrponm donefunction varargout = test1(varargin)% MOUTHTRAIN Application M-file for mouthtrain.fig% FIG = MOUTHTRAIN launch mouthtrain GUI.% MOUTHTRAIN('callback_name', ...) invoke the named callback.% Last Modified by GUIDE v2.0 28-Oct-2003 21:39:02global pos;if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % Use system color scheme for figure: set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); % Generate a structure of handles to pass to callbacks, and store it. handles = guihandles(fig); guidata(fig, handles); if nargout > 0 varargout{1} = fig; endelseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK try if (nargout) [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard else feval(varargin{:}); % FEVAL switchyard end catch disp(lasterr); endend% --------------------------------------------------------------------function varargout = InsPic_Callback(h, eventdata, handles, varargin)global pos;global facesamples;global pic;global im;global faceNumber;global name;global nameLabel;global manual;% when manually croping a face a flag is raisedmanual=0;%clear pos facesample pic im facenumber;faceNumber=[];nameLabel=1;name='Anonymous';pic_name = get(h,'string');pic=imread(pic_name,'jpg');axes(handles.xpic);pic = double(pic);while ((size(pic,1)*size(pic,2))>(400*300)) pic = getpic(pic,1,2);end;imshow(pic/255);[pos,facesamples] = findfaces(pic);% --------------------------------------------------------------------function varargout = cropface_Callback(h, eventdata, handles, varargin)global cropped_pic;global manual;% this is a flag, when using cropface the flag is raised.global im;global pic;manual=1;axes(handles.xpic);rect= getrect;rect=round(rect);rectsize = max(rect(3:4));rectsize = min([rectsize,size(pic,1)-rect(2),size(pic,2)-rect(1)]);im = pic(rect(2):rect(2)+rectsize,rect(1):rect(1)+rectsize)/255;axes(handles.xface);image(im*255);colormap(gray(255));cropped_pic=resample(im',20,size(im,1));cropped_pic=resample(cropped_pic',20,size(im,1));% --------------------------------------------------------------------function varargout = trainNotFace_Callback(h, eventdata, handles, varargin)%global i;%global facesamples;%notface=facesamples(:,i-1);global cropped_pic;global manual;global i;global facesamples;if (manual == 0) notface=facesamples(:,i-1);else cropped_pic=cropped_pic*255; [notface,y,x]=fdprep(uint8(cropped_pic),uint8(ones(size(cropped_pic)))); %yesface=histeq(cropped_pic(index360)/255,255)*255; %yesface=floor(yesface);endfigure(111);display360(notface);colormap(gray(255));load FC;[l,sc] = osuSVMclass(notface,FC.n, FC.alpha, FC.sv,FC.b, FC.params);strMenuHeader=sprintf('are you sure NOT face? sc=%f',sc);k=menu(strMenuHeader, 'yes' ,'no');if k==1load trainingcmulabels=[labels 2];samples=[samples notface];save trainingcmu samples labels % if (mod(size(labels),20)==0) [FC.alpha, FC.sv, FC.b, FC.params, FC.n]=osuSVMTrain(samples,labels, FC.params,2); save FC FC; % end; clear FC samples labels;end close(111);global cropped_pic;global manual;global i;global facesamples;if (manual == 0) yesface=facesamples(:,i-1);else cropped_pic=cropped_pic*255; [yesface,y,x]=fdprep(uint8(cropped_pic),uint8(ones(size(cropped_pic)))); %yesface=histeq(cropped_pic(index360)/255,255)*255; %yesface=floor(yesface);endyesface=double(yesface);figure(112);display360(yesface);colormap(gray(255));load FC;[l,sc] = osuSVMclass(yesface,FC.n, FC.alpha, FC.sv,FC.b, FC.params);% --------------------------------------------------------------------function varargout = TrainFace_Callback(h, eventdata, handles, varargin)global cropped_pic;global manual;global i;global facesamples;if (manual == 0) yesface=facesamples(:,i-1);else cropped_pic=cropped_pic*255; [yesface,y,x]=fdprep(uint8(cropped_pic),uint8(ones(size(cropped_pic)))); %yesface=histeq(cropped_pic(index360)/255,255)*255; %yesface=floor(yesface);endyesface=double(yesface);figure(112);display360(yesface);colormap(gray(255));load FC;[l,sc] = osuSVMclass(yesface,FC.n, FC.alpha, FC.sv,FC.b, FC.params);strMenuHeader=sprintf('are you sure YES face? sc=%f',sc);k=menu(strMenuHeader, 'yes' ,'no');if k==1 load trainingcmu samples = [yesface samples]; labels = [1 labels]; save trainingcmu samples labels %if (mod(size(labels),20)==0) [FC.alpha, FC.sv, FC.b, FC.params, FC.n]=osuSVMTrain(samples,labels, FC.params,2); save FC FC; %end; clear FC samples labels;end close(112);% --------------------------------------------------------------------function varargout = NextFace_Callback(h, eventdata, handles, varargin)global pos;global pic;global im;global faceNumber;global i;global coord;global facesamples;if (isempty(faceNumber)) faceNumber=size(pos,1); i = 1;endif i > faceNumber noMoreFaces=imread('no_more_faces.jpg','jpg'); axes(handles.xface); imshow(noMoreFaces); else scale=pos(i,3); bigy=double(pos(i,1))*scale; bigx=double(pos(i,2))*scale; binpic(bigy:bigy+20*scale,bigx:bigx+20*scale)=0; if (bigy>2*scale) bigy=bigy-2*scale; end if (bigx>scale) bigx=bigx-scale; end %if ((bigy+20*scale+2*scale>size(cur_pic,1))|((bigx+20*scale+scale)>size(cur_pic,2))) % continue %end im=pic(bigy:bigy+19*scale,bigx:bigx+19*scale)/255; dim=size(im,1); im_exp = pic(max(bigy-2*scale,1):min(bigy+23*scale,size(pic,1)),max(bigx-1*scale,1):min(bigx+21*scale,size(pic,2)))/255; %im = histeq(im,255); im = resample(im_exp',50,dim); im = resample(im',50,dim); axes(handles.xface); imshow(im); load FC; [l,sc] = osuSVMclass(facesamples(:,i),FC.n, FC.alpha, FC.sv,FC.b, FC.params); clear FC; scoretext=sprintf('%f',sc); set(handles.FaceScore,'string',scoretext); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % nose=1 % mouth=2 % lefteye=3 % righteye=4 % nose bridge=5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% [nosey,nosex]=locate(im,1); shownose(handles,nosex,nosey); [mouthy,mouthx]=locate(im,2); showmouth(handles,mouthx,mouthy); [lefteyey,lefteyex]=locate(im,3); showLeftEye(handles,lefteyex,lefteyey); [righteyey,righteyex]=locate(im,4); showRightEye(handles,righteyex,righteyey); [nby,nbx]=locate(im,5); shownb(handles,nbx,nby); coord=[nosey,nosex;mouthy,mouthx;lefteyey,lefteyex;righteyey,righteyex;nby,nbx]; i=i+1;end % --------------------------------------------------------------------% coord containes the face part:% [ nosey nosex% mouthy mouthx% leyey leyex% reyey reyex% nby nbx]% --------------------------------------------------------------------function showRightEye(handles,x,y)global im; axes(handles.xrighteye); reye = histeq(im(y:y+14,x:x+14),255); imshow(reye); load EC; [l,sc] = osuSVMclass(reshape(reye,225,1),EC.n, EC.alpha, EC.sv,EC.b, EC.params); scoretext=sprintf('(%d,%d) %.2f',y,x,sc); set(handles.REyeScore,'string',scoretext);% --------------------------------------------------------------------function varargout = uRightEye_Callback(h, eventdata, handles, varargin)global im;global coord;y=coord(4,1);x=coord(4,2);if y == 1 disp('cant go up');else y=y-1; coord(4,1)=y; showRightEye(handles,x,y);end% --------------------------------------------------------------------function varargout = dRightEye_Callback(h, eventdata, handles, varargin)global im;global coord;y=coord(4,1);x=coord(4,2);if y == size(im,1)-14 disp('cant go down');else y=y+1; coord(4,1)=y; showRightEye(handles,x,y);end% --------------------------------------------------------------------function varargout = rRightEye_Callback(h, eventdata, handles, varargin)global im;global coord;y=coord(4,1);x=coord(4,2);if x == size(im,2)-14 disp('cant go right');else x=x+1; coord(4,2)=x; showRightEye(handles,x,y);end% --------------------------------------------------------------------function varargout = lRightEye_Callback(h, eventdata, handles, varargin)global im;global coord;y=coord(4,1);x=coord(4,2);if x == 1 disp('cant go left');else x=x-1; coord(4,2)=x; showRightEye(handles,x,y);end% --------------------------------------------------------------------function varargout = trainNotRightEye_Callback(h, eventdata, handles, varargin)global im;global coord;y=coord(4,1);x=coord(4,2);load eyestmp = reshape(im(y:y+14,x:x+14),225,1);tmp = histeq(tmp,255);labels=[labels 2];samples=[samples tmp];save eyes labels samples%if (mod(size(samples,2),20)==0)load EC[EC.alpha, EC.sv, EC.b, EC.params, EC.n]=osuSVMTrain(samples,labels, EC.params,2);save EC EC NC MC NBC[righteyey,righteyex]=locate(im,4);%sprintf('righteye position is: %d %d',righteyey,righteyex);if (righteyey~=0) showRightEye(handles,righteyex,righteyey);endcoord(4,1)=righteyey;coord(4,2)=righteyex;%end% --------------------------------------------------------------------function varargout = showLeftEye(handles, x,y)global im;axes(handles.xlefteye);lefteye = histeq(im(y:y+14,x:x+14));imshow(lefteye); load EC; [l,sc] = osuSVMclass(reshape(lefteye,225,1),EC.n, EC.alpha, EC.sv,EC.b, EC.params); scoretext=sprintf('(%d,%d) %.2f',y,x,sc); set(handles.LEyeScore,'string',scoretext);% --------------------------------------------------------------------function varargout = uLeftEye_Callback(h, eventdata, handles, varargin)global im;global coord;y=coord(3,1);x=coord(3,2);if y == 1 disp('cant go up');else y=y-1; coord(3,1)=y; showLeftEye(handles,x,y);end% --------------------------------------------------------------------function varargout = dLeftEye_Callback(h, eventdata, handles, varargin)global im;global coord;y=coord(3,1);x=coord(3,2);if y == size(im,1)-14 disp('cant go down');else y=y+1; showLeftEye(handles,x,y); coord(3,1)=y;end% --------------------------------------------------------------------function varargout = rLeftEye_Callback(h, eventdata, handles, varargin)global im;global coord;y=coord(3,1);x=coord(3,2);if x == size(im,2)-14 disp('cant go right');else x=x+1; coord(3,2)=x; showLeftEye(handles,x,y);end% --------------------------------------------------------------------function varargout = lLeftEye_Callback(h, eventdata, handles, varargin)global im;global coord;y=coord(3,1);x=coord(3,2);if x == 1 disp('cant go left');else x=x-1; coord(3,2)=x; showLeftEye(handles,x,y);end% --------------------------------------------------------------------function varargout = trainNotLeftEye_Callback(h, eventdata, handles, varargin)global im;global coord;y=coord(3,1);x=coord(3,2);load eyestmp = reshape(im(y:y+14,x:x+14),225,1);tmp = histeq(tmp,255);labels=[labels 2];samples=[samples tmp];save eyes labels samples%if (mod(size(samples,2),20)==0)load EC[EC.alpha, EC.sv, EC.b, EC.params, EC.n]=osuSVMTrain(samples,labels, EC.params,2);save EC EC NC MC NBC[lefteyey,lefteyex]=locate(im,3);%sprintf('righteye position is: %d %d',righteyey,righteyex);if (lefteyey~=0) axes(handles.xlefteye); imshow(im(lefteyey:lefteyey+14,lefteyex:lefteyex+14));endcoord(3,1)=lefteyey;coord(3,2)=lefteyex;%end% --------------------------------------------------------------------function shownose(handles,x,y)global im;axes(handles.xnose);nose = histeq(im(y:y+17,x:x+12),255);imshow(nose);load EC;tmp=reshape(nose,13*18,1);[l,sc] = osuSVMclass(tmp,NC.n, NC.alpha, NC.sv,NC.b, NC.params);scoretext=sprintf('(%d,%d) %.2f',y,x,sc);set(handles.NoseScore,'string',scoretext);% --------------------------------------------------------------------function varargout = trainNotNose_Callback(h, eventdata, handles, varargin)global im;global coord;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -