-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.m
131 lines (99 loc) · 3.92 KB
/
main.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
clear all;
close all;
clc;
%% Dock the figure window and supress the fit to window warning
set(0, "DefaultFigureWindowStyle", "docked");
warning("off", "images:imshow:magnificationMustBeFitForDockedFigure");
%% Import functions
addpath("faults\");
addpath("utils\");
%% Folder paths
% path_to_folder = "./images/1-Underfilled";
% path_to_folder = "./images/1-NotUnderfilled";
% path_to_folder = "./images/2-Overfilled";
% path_to_folder = "./images/2-NotOverfilled";
% path_to_folder = "./images/3-Cap";
% path_to_folder = "./images/3-NoCap";
% path_to_folder = "./images/4-Label";
% path_to_folder = "./images/4-NoLabel";
% path_to_folder = "./images/5-LabelStraight";
% path_to_folder = "./images/5-LabelNotStraight";
% path_to_folder = "./images/6-Deformed";
% path_to_folder = "./images/6-NotDeformed";
% path_to_folder = "./images/7-MiddleBottle";
% path_to_folder = "./images/7-NoMiddleBottle";
% path_to_folder = "./images/8-LabelPrint";
% path_to_folder = "./images/8-NoLabelPrint";
% path_to_folder = "./images/All";
path_to_folder = uigetdir("Select image folder");
%% Paths of imgs in the folder
input_imgs_paths = dir(fullfile(path_to_folder, "*.jpg"));
total_img_count = length(input_imgs_paths);
% Randomise for debugging purposes
r_input_imgs_paths = input_imgs_paths(randperm(total_img_count));
%% Stats
missing = 0;
straight = 0;
caps = 0;
overfilled = 0;
underfilled = 0;
labelled = 0;
labelPrint = 0;
deformed = 0;
% goodBottles = 0;
% badBottles = 0;
%% Loop over the images
for current_img = 1 : length(r_input_imgs_paths)
img_path = fullfile(path_to_folder, r_input_imgs_paths(current_img).name);
img = imread(img_path);
img = imcrop(img,[100 0 160 288]); % Aprox cropping
img = rgb2gray(img); % I didn't end up using any specific colour channels
if isBottleMissing(img)
missing = missing + 1;
continue;
end
%% Crop the middle bottle perfectly
img = bottleCrop(img);
%% Good and Bad bottle counter (implemented at the end)
% if hasCap(img) && ~isOverfilled(img) && ~isUnderfilled(img) ...
% && ~isDeformed(img) && hasLabel(img) ...
% && isLabelStraight(img) && isLabelPrint(img)
% goodBottles = goodBottles + 1;
% else
% badBottles = badBottles + 1;
% end
%% Detection pipeline
caps = caps + hasCap(img);
overfilled = overfilled + isOverfilled(img);
underfilled = underfilled + isUnderfilled(img);
deformed = deformed + isDeformed(img);
if hasLabel(img)
labelled = labelled + 1;
straight = straight + isLabelStraight(img);
labelPrint = labelPrint + isLabelPrint(img);
end
end
%% Display results
disp("Underfilled: " + underfilled + "/" + total_img_count + ...
" (" + underfilled * 100 / total_img_count + "%)");
disp("Overfilled: " + overfilled + "/" + total_img_count + ...
" (" + overfilled * 100 / total_img_count + "%)");
disp("Bottle Cap: " + caps + "/" + total_img_count + ...
" (" + caps * 100 / total_img_count + "%)");
disp("Labelled: " + labelled + "/" + total_img_count + ...
" (" + labelled * 100 / total_img_count + "%)");
disp("Straight Label: " + straight + "/" + total_img_count + ...
" (" + straight * 100 / total_img_count + "%)");
disp("Deformed: " + deformed + "/" + total_img_count + ...
" (" + deformed * 100 / total_img_count + "%)");
disp("Missing: " + missing + "/" + total_img_count + ...
" (" + missing * 100 / total_img_count + "%)");
disp("Label Print: " + labelPrint + "/" + total_img_count + ...
" (" + labelPrint * 100 / total_img_count + "%)");
% disp("Good Bottles: " + goodBottles + "/" + (goodBottles + badBottles) + ...
% " (" + goodBottles * 100 / (goodBottles + badBottles) + "%)");
%
% disp("Bad Bottles: " + badBottles + "/" + (goodBottles + badBottles) + ...
% " (" + badBottles * 100 / (goodBottles + badBottles) + "%)");
%% Undock the figure window
set(0, "DefaultFigureWindowStyle", "normal");