在opening Fun中設定全域變數global i
在所需要的每個按鈕下宣告global i 再設定i=i+1
ps:利用GUI界面手工判斷人眼是否正視攝像頭
需要設定 開始讀取按鈕 否則容易與是否混淆
可能使此圖片的是計入下一圖片
且先存盤txt檔案 再讀取影像
注意內容與影像的匹配
uj5u.com熱心網友回復:
大哥,能給一下源代碼嗎uj5u.com熱心網友回復:
可以啊function varargout = untitled(varargin)
% UNTITLED MATLAB code for untitled.fig
% UNTITLED, by itself, creates a new UNTITLED or raises the existing
% singleton*.
%
% H = UNTITLED returns the handle to a new UNTITLED or the handle to
% the existing singleton*.
%
% UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED.M with the given input arguments.
%
% UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitled_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitled_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help untitled
% Last Modified by GUIDE v2.5 01-Aug-2019 21:25:26
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before untitled is made visible.
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to untitled (see VARARGIN)
% Choose default command line output for untitled
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes untitled wait for user response (see UIRESUME)
% uiwait(handles.figure1);
global i
i=1;
% --- Outputs from this function are returned to the command line.
function varargout = untitled_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
imgRoot='./Z開頭LFW資料集/'; % 測驗影像的路徑
imnames=dir([imgRoot '*' 'jpg']);
num=length(imnames);
Imagedata = imread( [ imgRoot imnames(1).name ] ); % 依次讀取影像
imname = [imgRoot imnames(1).name(1:end-4) ''];
axis off %%關閉坐標軸顯示
%%打開axes1的句柄 進行axes1的操作
axes(handles.axes1);
%%在axes1中顯示 影像
imshow(Imagedata)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
imgRoot='./Z開頭LFW資料集/'; % 測驗影像的路徑
imnames=dir([imgRoot '*' 'jpg']);
num=length(imnames);
global i
fp=fopen(['E:\Z開頭result','\',imnames(i).name(1:end-4),'.txt'],'a');%'A.txt'為檔案名;'a'為打開方式:在打開的檔案末端添加資料,若檔案不存在則創建
j = [1,0];
for jj =1 : 2
fprintf(fp, '%d', j(jj));
end
%fp為檔案句柄,指定要寫入資料的檔案。注意:%d后有空格
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
imgRoot='./Z開頭LFW資料集/'; % 測驗影像的路徑
imnames=dir([imgRoot '*' 'jpg']);
num=length(imnames);
global i
fp=fopen(['E:\Z開頭result','\',imnames(i).name(1:end-4),'.txt'],'a');%'A.txt'為檔案名;'a'為打開方式:在打開的檔案末端添加資料,若檔案不存在則創建
a = [0,1];
for aa =1 : 2
fprintf(fp, '%d', a(aa));
end
%fp為檔案句柄,指定要寫入資料的檔案。注意:%d后有空格
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
imgRoot='./Z開頭LFW資料集/'; % 測驗影像的路徑
imnames=dir([imgRoot '*' 'jpg']);
num=length(imnames);
global i
fp=fopen(['E:\Z開頭result','\',imnames(i).name(1:end-4),'.txt'],'a');%'A.txt'為檔案名;'a'為打開方式:在打開的檔案末端添加資料,若檔案不存在則創建
b = [1,0,0,0,0];
for bb =1 : 5
fprintf(fp, '%d', b(bb));
end %fp為檔案句柄,指定要寫入資料的檔案。注意:%d后有空格
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
imgRoot='./Z開頭LFW資料集/'; % 測驗影像的路徑
imnames=dir([imgRoot '*' 'jpg']);
num=length(imnames);
global i
fp=fopen(['E:\Z開頭result','\',imnames(i).name(1:end-4),'.txt'],'a');%'A.txt'為檔案名;'a'為打開方式:在打開的檔案末端添加資料,若檔案不存在則創建
c = [0,1,0,0,0];
for cc =1 : 5
fprintf(fp, '%d', c(cc));
end %fp為檔案句柄,指定要寫入資料的檔案。注意:%d后有空格
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
imgRoot='./Z開頭LFW資料集/'; % 測驗影像的路徑
imnames=dir([imgRoot '*' 'jpg']);
num=length(imnames);
global i
fp=fopen(['E:\Z開頭result','\',imnames(i).name(1:end-4),'.txt'],'a');%'A.txt'為檔案名;'a'為打開方式:在打開的檔案末端添加資料,若檔案不存在則創建
d = [0,0,1,0,0];
for dd =1 : 5
fprintf(fp, '%d', d(dd));
end %fp為檔案句柄,指定要寫入資料的檔案。注意:%d后有空格
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
imgRoot='./Z開頭LFW資料集/'; % 測驗影像的路徑
imnames=dir([imgRoot '*' 'jpg']);
num=length(imnames);
global i
fp=fopen(['E:\Z開頭result','\',imnames(i).name(1:end-4),'.txt'],'a');%'A.txt'為檔案名;'a'為打開方式:在打開的檔案末端添加資料,若檔案不存在則創建
e = [0,0,0,1,0];
for ee =1 : 5
fprintf(fp, '%d', e(ee));
end %fp為檔案句柄,指定要寫入資料的檔案。注意:%d后有空格
% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(~, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
imgRoot='./Z開頭LFW資料集/'; % 測驗影像的路徑
imnames=dir([imgRoot '*' 'jpg']);
num=length(imnames);
global i
fp=fopen(['E:\Z開頭result','\',imnames(i).name(1:end-4),'.txt'],'a');%'A.txt'為檔案名;'a'為打開方式:在打開的檔案末端添加資料,若檔案不存在則創建
f = [0,0,0,0,1];
for ff =1 : 5
fprintf(fp, '%d', f(ff));
end %fp為檔案句柄,指定要寫入資料的檔案。注意:%d后有空格
% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
imgRoot='./Z開頭LFW資料集/'; % 測驗影像的路徑
imnames=dir([imgRoot '*' 'jpg']);
num=length(imnames);
global i
fp=fopen(['E:\Z開頭result','\',imnames(i).name(1:end-4),'.txt'],'a');%'A.txt'為檔案名;'a'為打開方式:在打開的檔案末端添加資料,若檔案不存在則創建
k = [1,0,0];
for kk =1 : 3
fprintf(fp, '%d', k(kk));
end
%fp為檔案句柄,指定要寫入資料的檔案。注意:%d后有空格
i=i+1;
Imagedata = imread( [ imgRoot imnames(i).name ] ); % 依次讀取影像
imname = [imgRoot imnames(i).name(1:end-4) ''];
axis off %%關閉坐標軸顯示
%%打開axes1的句柄 進行axes1的操作
axes(handles.axes1);
%%在axes1中顯示 影像
imshow(Imagedata)
% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton11 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
imgRoot='./Z開頭LFW資料集/'; % 測驗影像的路徑
imnames=dir([imgRoot '*' 'jpg']);
num=length(imnames);
global i
fp=fopen(['E:\Z開頭result','\',imnames(i).name(1:end-4),'.txt'],'a');%'A.txt'為檔案名;'a'為打開方式:在打開的檔案末端添加資料,若檔案不存在則創建
g = [0,1,0];
for gg =1 : 3
fprintf(fp, '%d', g(gg));
end %fp為檔案句柄,指定要寫入資料的檔案。注意:%d后有空格
i=i+1;
Imagedata = imread( [ imgRoot imnames(i).name ] ); % 依次讀取影像
imname = [imgRoot imnames(i).name(1:end-4) ''];
axis off %%關閉坐標軸顯示
%%打開axes1的句柄 進行axes1的操作
axes(handles.axes1);
%%在axes1中顯示 影像
imshow(Imagedata)
% --- Executes on button press in pushbutton12.
function pushbutton12_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
imgRoot='./Z開頭LFW資料集/'; % 測驗影像的路徑
imnames=dir([imgRoot '*' 'jpg']);
num=length(imnames);
global i
fp=fopen(['E:\Z開頭result','\',imnames(i).name(1:end-4),'.txt'],'a');%'A.txt'為檔案名;'a'為打開方式:在打開的檔案末端添加資料,若檔案不存在則創建
h = [0,0,1];
for hh =1 : 3
fprintf(fp, '%d', h(hh));
end %fp為檔案句柄,指定要寫入資料的檔案。注意:%d后有空格
i=i+1;
Imagedata = imread( [ imgRoot imnames(i).name ] ); % 依次讀取影像
imname = [imgRoot imnames(i).name(1:end-4) ''];
axis off %%關閉坐標軸顯示
uj5u.com熱心網友回復:
謝謝大哥!!!轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/104946.html
標籤:機器視覺
