📄 fasttrainer.m
字号:
% 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 24-Nov-2003 17:05:45global pos;if nargin == 0 % LAUNCH GUI fig = openfig(mfilename,'reuse'); % 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 = NextFace_Callback(h, eventdata, handles, varargin)persistent d;persistent i;global im;global x;global y;global coord;if (isempty(d)) cd C:\matlabR12\work\anonimous\cropped_images d = dir('*.jpg'); i=1;endim = double(imread(d(i).name,'jpg'))/255;if (length(size(im))==3) im1 = 77*im(:,:,1)+150*im(:,:,2)+29*im(:,:,3); im = im1/256;end;dim = size(im,1);im = resample(im',84,dim);im = resample(im',84,dim);%im = im(2:51,2:51);axes(handles.xpic);imshow(im);i=i+1%if (isempty(faceNumber))% faceNumber=size(pos,1);% i = 1;%end%if i > faceNumber % noMoreFaces=imread('no_more_faces.jpg','jpg'); % axes(handles.xpic); % imshow(noMoreFaces); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 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]; % --------------------------------------------------------------------% 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),225);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;y=coord(1,1);x=coord(1,2);load nosestmp = reshape(im(y:y+17,x:x+12),234,1);tmp = histeq(tmp,255);labels=[labels 2];samples=[samples tmp];save noses labels samples%if (mod(size(samples,2),20)==0)load EC[NC.alpha, NC.sv, NC.b, NC.params, NC.n]=osuSVMTrain(samples,labels, NC.params,2);save EC EC NC MC NBC[nosey,nosex]=locate(im,1);%sprintf('righteye position is: %d %d',righteyey,righteyex);if (nosey~=0) shownose(handles,nosex,nosey);endcoord(1,1)=nosey;coord(1,2)=nosex;%end;% --------------------------------------------------------------------function varargout = uNose_Callback(h, eventdata, handles, varargin)global coord;y=coord(1,1);x=coord(1,2);if y == 1 disp('cant go up');else y=y-1; shownose(handles,x,y); coord(1,1)=y;end% --------------------------------------------------------------------function varargout = dNose_Callback(h, eventdata, handles, varargin)global im;global coord;y=coord(1,1);x=coord(1,2);if y == size(im,1)-13
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -