Skip to content

Commit 2008732

Browse files
authored
Add files via upload
1 parent 6bf161b commit 2008732

File tree

16 files changed

+1121
-0
lines changed

16 files changed

+1121
-0
lines changed

ScreenShot/1.PNG

28.7 KB
Loading

ScreenShot/2-1.jpg

229 KB
Loading

ScreenShot/2.jpg

229 KB
Loading

ScreenShot/3.jpg

239 KB
Loading

ScreenShot/4-1.jpg

242 KB
Loading

ScreenShot/4.jpg

242 KB
Loading

ScreenShot/5.jpg

270 KB
Loading

src/Detector-1.m

Lines changed: 297 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,297 @@
1+
function varargout = Detector(varargin)
2+
% DETECTOR MATLAB code for Detector.fig
3+
% DETECTOR, by itself, creates a new DETECTOR or raises the existing
4+
% singleton*.
5+
%
6+
% H = DETECTOR returns the handle to a new DETECTOR or the handle to
7+
% the existing singleton*.
8+
%
9+
% DETECTOR('CALLBACK',hObject,eventData,handles,...) calls the local
10+
% function named CALLBACK in DETECTOR.M with the given input arguments.
11+
%
12+
% DETECTOR('Property','Value',...) creates a new DETECTOR or raises the
13+
% existing singleton*. Starting from the left, property value pairs are
14+
% applied to the GUI before Detector_OpeningFcn gets called. An
15+
% unrecognized property name or invalid value makes property application
16+
% stop. All inputs are passed to Detector_OpeningFcn via varargin.
17+
%
18+
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
19+
% instance to run (singleton)".
20+
%
21+
% See also: GUIDE, GUIDATA, GUIHANDLES
22+
23+
% Edit the above text to modify the response to help Detector
24+
25+
% Last Modified by GUIDE v2.5 06-May-2017 21:58:39
26+
27+
% Begin initialization code - DO NOT EDIT
28+
gui_Singleton = 1;
29+
gui_State = struct('gui_Name', mfilename, ...
30+
'gui_Singleton', gui_Singleton, ...
31+
'gui_OpeningFcn', @Detector_OpeningFcn, ...
32+
'gui_OutputFcn', @Detector_OutputFcn, ...
33+
'gui_LayoutFcn', [] , ...
34+
'gui_Callback', []);
35+
if nargin && ischar(varargin{1})
36+
gui_State.gui_Callback = str2func(varargin{1});
37+
end
38+
39+
if nargout
40+
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
41+
else
42+
gui_mainfcn(gui_State, varargin{:});
43+
end
44+
% End initialization code - DO NOT EDIT
45+
46+
47+
% --- Executes just before Detector is made visible.
48+
49+
function Detector_OpeningFcn(hObject, eventdata, handles, varargin)
50+
% This function has no output args, see OutputFcn.
51+
% hObject handle to figure
52+
% eventdata reserved - to be defined in a future version of MATLAB
53+
% handles structure with handles and user data (see GUIDATA)
54+
% varargin command line arguments to Detector (see VARARGIN)
55+
56+
% Choose default command line output for Detector
57+
handles.output = hObject;
58+
59+
% Update handles structure
60+
guidata(hObject, handles);
61+
62+
% UIWAIT makes Detector wait for user response (see UIRESUME)
63+
% uiwait(handles.figure1);
64+
65+
% --- Outputs from this function are returned to the command line.
66+
function varargout = Detector_OutputFcn(hObject, eventdata, handles)
67+
% varargout cell array for returning output args (see VARARGOUT);
68+
% hObject handle to figure
69+
% eventdata reserved - to be defined in a future version of MATLAB
70+
% handles structure with handles and user data (see GUIDATA)
71+
72+
% Get default command line output from handles structure
73+
varargout{1} = handles.output;
74+
75+
76+
% --- Executes on button press in pushbutton1.
77+
function pushbutton1_Callback(hObject, eventdata, handles)
78+
% hObject handle to pushbutton1 (see GCBO)
79+
% eventdata reserved - to be defined in a future version of MATLAB
80+
% handles structure with handles and user data (see GUIDATA)
81+
global looper;
82+
looper = 0;
83+
drawnow();
84+
%% Read in image
85+
set(handles.text4,'string','');
86+
n=get(handles.edit1,'string');
87+
I = imread(n);
88+
axes(handles.axes1)
89+
handles.axes1 = imshow(I);
90+
set(handles.text4,'string','Image Loaded');
91+
drawnow();
92+
93+
function edit1_Callback(hObject, eventdata, handles)
94+
% hObject handle to edit1 (see GCBO)
95+
% eventdata reserved - to be defined in a future version of MATLAB
96+
% handles structure with handles and user data (see GUIDATA)
97+
98+
% Hints: get(hObject,'String') returns contents of edit1 as text
99+
% str2double(get(hObject,'String')) returns contents of edit1 as a double
100+
101+
102+
% --- Executes during object creation, after setting all properties.
103+
function edit1_CreateFcn(hObject, eventdata, handles)
104+
% hObject handle to edit1 (see GCBO)
105+
% eventdata reserved - to be defined in a future version of MATLAB
106+
% handles empty - handles not created until after all CreateFcns called
107+
108+
109+
110+
111+
% Hint: edit controls usually have a white background on Windows.
112+
% See ISPC and COMPUTER.
113+
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
114+
set(hObject,'BackgroundColor','white');
115+
end
116+
117+
118+
% --- Executes on button press in pushbutton2.
119+
function pushbutton2_Callback(hObject, eventdata, handles)
120+
% hObject handle to pushbutton2 (see GCBO)
121+
% eventdata reserved - to be defined in a future version of MATLAB
122+
% handles structure with handles and user data (see GUIDATA)
123+
global looper;
124+
looper = 1;
125+
set(handles.text4,'string','Select Object');
126+
n=get(handles.edit1,'string');
127+
nnet=alexnet;
128+
I = imread(n);
129+
while looper
130+
Selection = getrect;
131+
I2=imcrop(I,(Selection));
132+
picture=imresize(I2,[227,227]);
133+
label=classify(nnet,picture);
134+
%set(handles.edit1,'String',char(label))
135+
handles.axes1 = rectangle('position',(Selection),'EdgeColor','k','linewidth',3);
136+
x1 = Selection(1,1)+5;
137+
y1 = Selection(1,2)+10;
138+
%display(y1);
139+
handles.axes1 = text(x1,y1,char(label),'color','k','FontSize',15);
140+
%handles.drawLabel = text(bbox(1,1),bbox(1,2),'object','color',rndColor);
141+
%X_Cut_Min = Selection(1,1);
142+
%Y_Cut_Min = Selection(1,2);
143+
%X_Cut_Max = Selection(1,3) + Selection(1,1);
144+
%Y_Cut_Max = Selection(1,4) + Selection(1,2);
145+
%X_Cut_Min = X_Cut_Min/1000;
146+
%Y_Cut_Min = Y_Cut_Min/1000;
147+
%X_Cut_Max = X_Cut_Max/1000;
148+
%Y_Cut_Max = Y_Cut_Max/1000;
149+
%display(X_Cut_Min)
150+
%display(Y_Cut_Min)
151+
%display(X_Cut_Max)
152+
%display(Y_Cut_Max)
153+
%handles.axes1 = annotation('textbox',[X_Cut_Min,Y_Cut_Min,X_Cut_Max,Y_Cut_Max],'String', char(label));
154+
%annotation('textbox',(Selection),'String', char(label))
155+
end
156+
157+
158+
% --- Executes on button press in pushbutton3.
159+
function pushbutton3_Callback(hObject, eventdata, handles)
160+
% hObject handle to pushbutton3 (see GCBO)
161+
% eventdata reserved - to be defined in a future version of MATLAB
162+
% handles structure with handles and user data (see GUIDATA)
163+
set(handles.text4,'string','Loading');
164+
drawnow();
165+
n=get(handles.edit1,'string');
166+
nnet=alexnet;
167+
I = imread(n);
168+
169+
Im=I;
170+
171+
rmat=Im(:,:,1);
172+
gmat=Im(:,:,2);
173+
bmat=Im(:,:,3);
174+
175+
%subplot(2,2,1), imshow(rmat);
176+
%title('Red Plane');
177+
%subplot(2,2,2), imshow(gmat);
178+
%title('Green Plane');
179+
%subplot(2,2,3), imshow(bmat);
180+
%title('Blue Plane');
181+
%subplot(2,2,4), imshow(I);
182+
%title('Original Image');
183+
184+
%%
185+
levelr = 0.63;
186+
levelg = 0.5;
187+
levelb = 0.4;
188+
i1=im2bw(rmat,levelr);
189+
i2=im2bw(gmat,levelg);
190+
i3=im2bw(bmat,levelb);
191+
Isum = (i1&i2&i3);
192+
193+
% Plot the data
194+
%subplot(2,2,1), imshow(i1);
195+
%title('Red Plane');
196+
%subplot(2,2,2), imshow(i2);
197+
%title('Green Plane');
198+
%subplot(2,2,3), imshow(i3);
199+
%title('Blue Plane');
200+
%subplot(2,2,4), imshow(Isum);
201+
%title('Sum of all the planes');
202+
203+
%% Complement Image and Fill in holes
204+
Icomp = imcomplement(Isum);
205+
Ifilled = imfill(Icomp,'holes');
206+
%figure, imshow(Ifilled);
207+
208+
%% Morphological filter
209+
se = strel('disk', 25);
210+
Iopenned = imopen(Ifilled,se);
211+
% figure,imshowpair(Iopenned, I);
212+
%imshow(Iopenned);
213+
214+
%% Extract features
215+
216+
Iregion = regionprops(Iopenned, 'centroid');
217+
[labeled,numObjects] = bwlabel(Iopenned,4);
218+
stats = regionprops(labeled,'Eccentricity','Area','BoundingBox');
219+
areas = [stats.Area];
220+
eccentricities = [stats.Eccentricity];
221+
222+
idxOfObjects = find(eccentricities);
223+
statsDefects = stats(idxOfObjects);
224+
225+
%figure, imshow(I);
226+
set(handles.text4,'string','Annotating');
227+
drawnow();
228+
for idx = 1 : length(idxOfObjects)
229+
% pause(0.01) % Do something important
230+
I2=imcrop(I,statsDefects(idx).BoundingBox);
231+
%imshow(I2);
232+
picture=imresize(I2,[227,227]);
233+
label=classify(nnet,picture);
234+
handles.axes1 = rectangle('position',(statsDefects(idx).BoundingBox),'EdgeColor','k','linewidth',3);
235+
x1 = statsDefects(idx).BoundingBox(1,1)+5;
236+
y1 = statsDefects(idx).BoundingBox(1,2)+10;
237+
%display(y1);
238+
handles.axes1 = text(x1,y1,char(label),'color','k','FontSize',15);
239+
%h = rectangle('Position',statsDefects(idx).BoundingBox,'LineWidth',2);
240+
%set(h,'EdgeColor',[.75 0 0]);
241+
%hold on;
242+
drawnow()
243+
end
244+
set(handles.text4,'string','Done!');
245+
246+
247+
% --- Executes during object creation, after setting all properties.
248+
function axes2_CreateFcn(hObject, eventdata, handles)
249+
% hObject handle to axes2 (see GCBO)
250+
% eventdata reserved - to be defined in a future version of MATLAB
251+
% handles empty - handles not created until after all CreateFcns called
252+
253+
% Hint: place code in OpeningFcn to populate axes2
254+
axes(hObject)
255+
x=imread('BackG.jpg');
256+
imshow(x)
257+
%set(axes1,'handlevisibility','off')
258+
259+
% --- Executes during object creation, after setting all properties.
260+
function axes1_CreateFcn(hObject, eventdata, handles)
261+
% hObject handle to axes1 (see GCBO)
262+
% eventdata reserved - to be defined in a future version of MATLAB
263+
% handles empty - handles not created until after all CreateFcns called
264+
265+
% Hint: place code in OpeningFcn to populate axes1
266+
set(gca,'xtick',[])
267+
set(gca,'ytick',[])
268+
269+
% --- Executes on button press in pushbutton4.
270+
function pushbutton4_Callback(hObject, eventdata, handles)
271+
% hObject handle to pushbutton4 (see GCBO)
272+
% eventdata reserved - to be defined in a future version of MATLAB
273+
% handles structure with handles and user data (see GUIDATA)
274+
275+
%%
276+
global looper;
277+
camera = webcam(2);
278+
nnet=alexnet;
279+
looper = 1;
280+
while looper
281+
picture=camera.snapshot;
282+
picture=imresize(picture,[227,227]);
283+
label=classify(nnet,picture);
284+
set(handles.text4,'string',char(label));
285+
handles.axes1=imshow(picture);
286+
%title(char(label));
287+
%drawnow;
288+
end
289+
290+
291+
% --- Executes on button press in pushbutton5.
292+
function pushbutton5_Callback(hObject, eventdata, handles)
293+
% hObject handle to pushbutton5 (see GCBO)
294+
% eventdata reserved - to be defined in a future version of MATLAB
295+
% handles structure with handles and user data (see GUIDATA)
296+
global looper;
297+
looper = 0;

src/Detector.fig

24.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)