Quellcode

Download der Projekt Dateien:

 

Visualisierung_HOG.m

function varargout = Visualisierung_HOG(varargin)
% VISUALISIERUNG_HOG M-file for Visualisierung_HOG.fig
% VISUALISIERUNG_HOG, by itself, creates a new VISUALISIERUNG_HOG or raises the existing
% singleton*.
%
% H = VISUALISIERUNG_HOG returns the handle to a new VISUALISIERUNG_HOG or the handle to
% the existing singleton*.
%
% VISUALISIERUNG_HOG('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in VISUALISIERUNG_HOG.M with the given input arguments.
%
% VISUALISIERUNG_HOG('Property','Value',...) creates a new VISUALISIERUNG_HOG or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Visualisierung_HOG_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Visualisierung_HOG_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 Visualisierung_HOG

% Last Modified by GUIDE v2.5 07-Dec-2011 08:07:42

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Visualisierung_HOG_OpeningFcn, ...
'gui_OutputFcn', @Visualisierung_HOG_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 Visualisierung_HOG is made visible.
function Visualisierung_HOG_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 Visualisierung_HOG (see VARARGIN)

% Choose default command line output for Visualisierung_HOG
handles.output = hObject;
set(hObject,'toolbar','figure');
set(handles.figure1,'CloseRequestFcn',@closeGUI); %Close Request

axes(handles.SEW_Logo); % Auswahl des entsprechenden Axes-Objekts
addpath([cd '/Programmdata'])
G1=imread('sew_logo.jpg'); % Einlesen der Grafik
image (G1); axis image; % Grafik ausgeben, Grafik entzerren
axis off % Koordinatenachsen ausblenden

global minimaleUeberdeckungsflaeche;
minimaleUeberdeckungsflaeche = 0.3;

plot(handles.axes1,0,0); %handles.axes1
grid (handles.axes1,'on');
xlabel (handles.axes1,'recall')
ylabel (handles.axes1,'precision')
title(handles.axes1,'Trefferquote - Genauigkeit (recall - precision)');



loglog(handles.axes2,0,0,'LineWidth',2);
set(handles.axes2,'ytick',[0.01 0.02 0.05 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1])
%ylim(handles.axes2,[min(missRate),1]);
grid (handles.axes2,'on');
xlabel (handles.axes2,'false positive rate')
ylabel (handles.axes2,'miss rate')
title(handles.axes2,'miss rate - false positive rate');



% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Visualisierung_HOG wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Visualisierung_HOG_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 Laden.
function Laden_Callback(hObject, eventdata, handles)

%% Textdatei laden

ueberschrift='Textdatei öffnen';

[dateiName,pfadName] = uigetfile({ ...
'*.txt'}, ueberschrift, pwd, 'MultiSelect', 'off'); %Dateiname und Pfad der einzulesenden TXT-Datei

if ~ischar(pfadName) || ~ischar(dateiName)
handles.pfadUndDateiname='keineEingabe';
else
handles.pfadUndDateiname = fullfile(pfadName,dateiName); %Datei+Pfad
end
guidata(hObject,handles)

% --- Executes on button press in Ausfuehren.
function Ausfuehren_Callback(hObject, eventdata, handles)
%main
%Funktionen die benötigt werden:
%-VOCinit (initialiesierung für Personen)
%-VOCreadimgset (testset laden)
%-ExternRead (laden und verarbeiten der Detektierungs Textdatei)
%-VOCpr /VOCsavepr (Precision-Recall-Kurve darstellen und speichern)
%-VOCdet /VOCsavedet (Det-Kurve darstellen und speichern)


% change this path if you install the PASCAL code elsewhere
addpath([cd '/PASCAL']);

% initialize the PASCAL options

VOCinit;

% define a name for this experiment e.g. myinstitution_final
expt='pascal_develtest';


label=PASopts.VOCclass(3).label;
fprintf('label: "%s"\n',label);

fprintf('loading Extern data set 1\n');
[dets,subset]=ExternRead(handles);

% load test set 'test1'
fprintf('loading test set 1\n');
testset=VOCreadimgset(PASopts,label,subset); % --> Referenzdaten

BBvergleich(PASopts,testset,dets,handles); %Werte berechnen und plotten

guidata(hObject,handles)


% --- Executes on button press in Speichern.
function Speichern_Callback(hObject, eventdata, handles)
%% Ergebnisse Speichern unter
savePlot(handles.axes1,handles.axes2);
%ueberschrift='Figure Speichern unter';
%datum=datestr(datevec(now));
%datum(ismember(datum,' '))='_'; %Alle Leerzeichen duch Unterstriche ersetzen
%datum(ismember(datum,':'))=[]; %Alle : entfernen
%resultsVerz = strcat(pwd,'\results\newfile','_',datum,'.jpg'); %Verzeichnis Results (Ergebnisse der Auswertung)
%[FileName,PathName,FilterIndex] = uiputfile({'*.bmp';'*.jpg';'*.tif';'*.png';'*.gif';'*.fig'},ueberschrift,resultsVerz);

%guidata(hObject,handles)


function closeGUI(src,evnt)
%src is the handle of the object generating the callback (the source of the event)
%evnt is the The event data structure (can be empty for some callbacks)
selection = questdlg('Do you want to close the Visualisierung HOG?',...
'Close Request Function',...
'Yes','No','Yes');
switch selection,
case 'Yes',
delete(gcf)
case 'No'
return
end

% --- Executes on button press in Daten_exportieren.
function Daten_exportieren_Callback(hObject, eventdata, handles)
% hObject handle to Daten_exportieren (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global globalData;
%% Open file
%- FileFullName : 'X:\Path\to\File\FileFullName.ext'
[fileout,pathout,FilterIndex] = uiputfile({'*.csv';'*.mat'},'Geben Sie einen Dateinamen ein und wählen sie das Datenformat');
FileFullName = [pathout,fileout];
if length(FileFullName) > 1
%Daten laden
global globalData;
if(~isempty(globalData))

%Überprüfung der Endung

%Daten als .csv speichern
if(FilterIndex == 1)
csvwrite(FileFullName,[globalData.missRate,globalData.falsePositive, ...
globalData.precision,globalData.recall,globalData.confidence, ...
globalData.truePositive,globalData.trueNegative, ...
globalData.truePositiveCumSum,globalData.falsePositive, ...
globalData.falseNegative]);
end

%Daten als .mat speichern
if(FilterIndex == 2)
oldpath = pwd;
string = ['cd(''',pathout,''')'];
eval(['cd(''',pathout,''')']);
eval(['save ', fileout, ' globalData']);
eval(['cd(''',oldpath,''')']);
end
end
end


% function savePlotWithinGUI(axesObject, legendObject)
% %this function takes in two arguments
% %axesObject is the axes object that will be saved (required input)
% %legendObject is the legend object that will be saved (optional input)
%
% %stores savepath for the phase plot
% [filename, pathname] = uiputfile({ '*.emf','Enhanced Meta File (*.emf)';...
% '*.bmp','Bitmap (*.bmp)'; '*.fig','Figure (*.fig)'}, ...
% 'Save picture as','default');
%
% %if user cancels save command, nothing happens
% if isequal(filename,0) || isequal(pathname,0)
% return
% end
% %create a new figure
% newFig = figure;
%
% %get the units and position of the axes object
% axes_units = get(axesObject,'Units');
% axes_pos = get(axesObject,'Position');
%
% %copies axesObject onto new figure
% axesObject2 = copyobj(axesObject,newFig);
%
% %realign the axes object on the new figure
% set(axesObject2,'Units',axes_units);
% set(axesObject2,'Position',[15 5 axes_pos(3) axes_pos(4)]);
%
% %if a legendObject was passed to this function . . .
% if (exist('legendObject'))
%
% %get the units and position of the legend object
% legend_units = get(legendObject,'Units');
% legend_pos = get(legendObject,'Position');
%
% %copies the legend onto the the new figure
% legendObject2 = copyobj(legendObject,newFig);
%
% %realign the legend object on the new figure
% set(legendObject2,'Units',legend_units);
% set(legendObject2,'Position',[15-axes_pos(1)+legend_pos(1) 5-axes_pos(2)+legend_pos(2) legend_pos(3) legend_pos(4)] );
%
% end
%
% %adjusts the new figure accordingly
% set(newFig,'Units',axes_units);
% set(newFig,'Position',[15 5 axes_pos(3)+30 axes_pos(4)+10]);
%
% %saves the plot
% saveas(newFig,fullfile(pathname, filename))
%
% %closes the figure
% close(newFig)


% --------------------------------------------------------------------


% --- Executes on button press in Clear_plots.
function Clear_plots_Callback(hObject, eventdata, handles)
cla(handles.axes1,'reset')
cla(handles.axes2,'reset')
set(handles.axes1,'Visible','off')
set(handles.axes2,'Visible','off')
guidata(hObject, handles); %updates the handles



function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
global minimaleUeberdeckungsflaeche;
minimaleUeberdeckungsflaeche = str2double(get(hObject,'String'))/100;

% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

BBvergleich.m

function BBvergleich(PASopts,imgset,detsRohdaten,handles)

global minimaleUeberdeckungsflaeche;


%% Daten konvertieren und ordnen
% -------------------------------------------------------------------------
%Aus den Thresholdwerten die confidence ermittlen.
%Ermittelte Daten nach absteigender confidence ordnen, dann Referenzdaten
%entsprechend den sortierten ermittelten Daten ordnen, dann
%confidence-Werte (absteigend) in extra Matrix schreiben

anzahlTestbilderAlle = length(imgset.recs);
anzahlTestbilderMitPersonen = length(imgset.posinds);

%Aus der Threshold die confidence berechnen
dets = detsRohdaten;
zaehlerDets=0;
bildnameAktuell='';
bildnameAlt='';

for a=1:length(dets)
bildnameAktuell=detsRohdaten(a).imgname;
if (~strcmp(bildnameAktuell,bildnameAlt))
zaehlerDets = zaehlerDets+1;
dets(zaehlerDets)=detsRohdaten(a);
elseif(~isempty(detsRohdaten(a).confidence))
dets(zaehlerDets).confidence=detsRohdaten(a).confidence;
end
bildnameAlt=bildnameAktuell;
end

dets=dets(1:zaehlerDets);

for a=1:zaehlerDets
dets(a).imgnum=zaehlerDets;
if(isempty(dets(a).confidence))
dets(a).confidence = 0;
end
if(length(dets(a).confidence)>1)
dets(a).confidence = sum(dets(a).confidence)./length(dets(a).confidence);
end

end


%Ermittelte Werte mit absteigender confidence ordnen
[~,si]=sort(-[dets(:).confidence]);
dets=dets(:,si);

for i=1:anzahlTestbilderAlle
confidence(i)=dets(i).confidence; %confidence Werte absteigend
end


%Vorgegebenen Bilder so sortieren wie in dets
% for i=1:anzahlTestbilderAlle
% imgnames(i)=dets(i).imgnum; %%SM vorl. imgnum
% end

index=zeros(1,anzahlTestbilderAlle);
for a=1:anzahlTestbilderAlle
for b=1:anzahlTestbilderAlle
if(~isempty(strfind(imgset.recs(b).imgname,dets(a).imgname)))
index(a)=b;
end
%index(a)=strfind(dets(a).imgname,'person_055.png');
end

end

imgset.recs=imgset.recs(index); %hier ist der eigentliche Sortiervorgang

%Referenzdaten ermitteln
%Die Daten werden in ein Cell-Array geschrieben, um besser mit den Daten
%arbeiten zu können
referenzBB = cell(anzahlTestbilderAlle,1); %referenzBB: Referenz Bounding-Boxes
for iteratorTestbilderMitPersonen=1:anzahlTestbilderAlle
PersonenanzahlAktuellesBild = length(imgset.recs(iteratorTestbilderMitPersonen).objects); %Ermittelt die Objektanzahl pro Bild;
tempMatrix = zeros(PersonenanzahlAktuellesBild,4);
for iteratorPersonenAktuellesBild=1:PersonenanzahlAktuellesBild
if(~isempty(imgset.recs(iteratorTestbilderMitPersonen).objects(iteratorPersonenAktuellesBild).bbox))
tempMatrix(iteratorPersonenAktuellesBild,:) = imgset.recs(iteratorTestbilderMitPersonen).objects(iteratorPersonenAktuellesBild).bbox;
else
tempMatrix=[];
end
end
referenzBB(iteratorTestbilderMitPersonen) = mat2cell(tempMatrix);
end

%Ermittelte Daten
%Die Daten werden in ein Cell-Array geschrieben, um besser mit den Daten
%arbeiten zu können
%referenzBB und ermitteltBB sind gleich aufgebaut

%Die Daten von OpenCV sind als(x1,y1,breite,höhe) angegegen, hier deshalb
%zusätzlich noch die Umrechung in (x1,y1,x2,y2).
ermitteltBB = cell(anzahlTestbilderAlle,1);
for iteratorAnzahlTestbilderAlle=1:anzahlTestbilderAlle
tempMatrix = dets(iteratorAnzahlTestbilderAlle).bbox;
if (~isempty(tempMatrix))
tempMatrix(:,3) = tempMatrix(:,1)+tempMatrix(:,3);
tempMatrix(:,4) = tempMatrix(:,2)+tempMatrix(:,4);
end
ermitteltBB(iteratorAnzahlTestbilderAlle) = mat2cell(tempMatrix);
end

%% Berechnung

%Varialben für die Berechnung
falsePositive = zeros(anzahlTestbilderAlle,1); %Fälschlich detektierte Personen
truePositive = zeros(anzahlTestbilderAlle,1); %Richtig detektierte Personen
falseNegative = zeros(anzahlTestbilderAlle,1);
trueNegative = zeros(anzahlTestbilderAlle,1);

% Bilder vergleichen
for iteratorAnzahlTestbilderAlle=1:anzahlTestbilderAlle
if isempty(referenzBB{iteratorAnzahlTestbilderAlle,1}) && isempty(ermitteltBB{iteratorAnzahlTestbilderAlle,1})
trueNegative(iteratorAnzahlTestbilderAlle) = 1;
end
if ~isempty(referenzBB{iteratorAnzahlTestbilderAlle,1}) && isempty(ermitteltBB{iteratorAnzahlTestbilderAlle,1})
falseNegative(iteratorAnzahlTestbilderAlle) = 1;
end
if isempty(referenzBB{iteratorAnzahlTestbilderAlle,1}) && ~isempty(ermitteltBB{iteratorAnzahlTestbilderAlle,1})
falsePositive(iteratorAnzahlTestbilderAlle)=1;
end
if ~isempty(referenzBB{iteratorAnzahlTestbilderAlle,1}) && ~isempty(ermitteltBB{iteratorAnzahlTestbilderAlle,1})
%Bounding-Boxes müssen verglichen werden
%Schritt 1 BB der Referenz nach Größe sortieren
anzahlPersonen = size(referenzBB{iteratorAnzahlTestbilderAlle},1);
tempRefM = referenzBB{iteratorAnzahlTestbilderAlle};
groesseBBRef = ((tempRefM(:,3) - tempRefM(:,1)).*(tempRefM(:,4) - tempRefM(:,2)));
tempRefM = [tempRefM, groesseBBRef];
indizierung = sort(groesseBBRef,1,'descend');

%vorhanden ermittelte Bounding-Boxes:
tempErmM = ermitteltBB{iteratorAnzahlTestbilderAlle};
groesseBBErm = ((tempErmM(:,3) - tempErmM(:,1)).*(tempErmM(:,4) - tempErmM(:,2)));
tempErmM = [tempErmM, groesseBBErm];
QUOTIENT_GESAMMT = 0;

groesseBBErmSchleife = groesseBBErm;
tempErmMSchleife = tempErmM;
groesseBBRefSchleife = groesseBBRef;

for i=1:anzahlPersonen
index=find(groesseBBRef == indizierung(i));
tempRefMatrix = tempRefM(index,1:4);

if(~isempty(tempErmMSchleife))
for j=1:size(tempErmMSchleife,1)
ueberdeckungPunkte=[max(tempErmMSchleife(:,1),tempRefMatrix(1)) , max(tempErmMSchleife(:,2),tempRefMatrix(2)) , min(tempErmMSchleife(:,3),tempRefMatrix(3)) , min(tempErmMSchleife(:,4),tempRefMatrix(4))];
ueberdeckungFlaeche=(ueberdeckungPunkte(:,3)-ueberdeckungPunkte(:,1)).*(ueberdeckungPunkte(:,4)-ueberdeckungPunkte(:,2));
QUOTIENT = ueberdeckungFlaeche./abs((groesseBBRefSchleife(i)+groesseBBErmSchleife-ueberdeckungFlaeche));
if max(QUOTIENT) < 0
QUOTIENT = 0;
end
indexLoeschen = find(QUOTIENT == max(QUOTIENT));
tempErmMSchleife(indexLoeschen,:)=[];
groesseBBErmSchleife(indexLoeschen,:)=[];
%groesseBBRefSchleife(index,:)=[];
end
else
QUOTIENT = 0;
end


QUOTIENT_GESAMMT = QUOTIENT_GESAMMT + max(QUOTIENT);


end

if (QUOTIENT_GESAMMT/anzahlPersonen) >= minimaleUeberdeckungsflaeche;
truePositive(iteratorAnzahlTestbilderAlle) = 1;
end

end

end

%Ermitteln der Abgeleiteten Werte
truePositiveCumSum=cumsum(truePositive);
recall=truePositiveCumSum/anzahlTestbilderMitPersonen; %np = Anzahl der Bilder mit Personen
precision=truePositiveCumSum./(1:length(recall))'; %Ist sozusagen die Ableitung ROC-Kurve, also sozugagen der aktuellen Erfolgswert

falsePositive=cumsum(~truePositive)/length(truePositive);
missRate=1-cumsum(truePositive)/anzahlTestbilderMitPersonen;


%% Plotten der Funktionen in die GUI-figures
plot(handles.axes1,recall,precision,'LineWidth',2); %handles.axes1
grid (handles.axes1,'on');
xlabel (handles.axes1,'false positive rate')
ylabel (handles.axes1,'miss rate')
title(handles.axes1,'Trefferquote - Genauigkeit (recall - precision)');

loglog(handles.axes2,falsePositive,missRate,'LineWidth',2);
set(handles.axes2,'ytick',[0.01 0.02 0.05 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.95 0.99 1])
ylim(handles.axes2,[min(missRate),1]);
grid (handles.axes2,'on');
xlabel (handles.axes2,'false positive rate')
ylabel (handles.axes2,'miss rate')
title(handles.axes2,'miss rate - false positive rate');

%% Daten global abspeichern, um sie ggf. abspeichern zu können
global globalData;
globalData.missRate = missRate;
globalData.falsePositive = falsePositive;
globalData.precision = precision;
globalData.recall = recall;
globalData.confidence = confidence';
globalData.truePositive = truePositive;
globalData.trueNegative = trueNegative;
globalData.truePositiveCumSum = truePositiveCumSum ;
globalData.falsePositive = falsePositive;
globalData.falseNegative = falseNegative;