-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvalidation.jl
More file actions
executable file
·86 lines (71 loc) · 2.94 KB
/
Copy pathvalidation.jl
File metadata and controls
executable file
·86 lines (71 loc) · 2.94 KB
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
#=
Adapted from https://github.com/Simon-Hohberg/Viola-Jones/
=#
# println("\033[1;34m===>\033[0;38m\033[1;38m\tLoading required libraries (it will take a moment to precompile if it is your first time doing this)...\033[0;38m")
@info "Loading required libraries (it will take a moment to precompile if it is your first time doing this)..."
using FaceDetection
const FD = FaceDetection
using Printf: @printf
using Images: Gray, clamp01nan, save, imresize, load
using Serialization: deserialize
@info("...done")
function main(;
smart_choose_feats::Bool = false,
image_reconstruction::Bool = true,
feat_validation::Bool = true,
scale::Bool = false,
scale_to::Tuple = (200, 200),
)
include("constants.jl")
include("main_data.jl")
max_feature_width, max_feature_height, min_feature_height, min_feature_width, min_size_img = determine_feature_size(
pos_testing_path, neg_testing_path; scale = scale, scale_to = scale_to
)
img_size = scale ? scale_to : min_size_img
data_file = joinpath(
dirname(@__FILE__), "data", "haar-like_features_c$(num_classifiers)_$(img_size)"
)
# read classifiers from file
classifiers = deserialize(data_file)
# FD.notify_user("Loading test faces...")
#
# faces_testing = FD.load_images(pos_testing_path)[1]
# # faces_ii_testing = map(FD.to_integral_image, faces_testing)
# faces_ii_testing = map(FD.to_integral_image, faces_testing)
# println("...done. ", length(faces_testing), " faces loaded.")
#
# FD.notify_user("Loading test non-faces..")
#
# non_faces_testing = FD.load_images(neg_testing_path)[1]
# non_faces_ii_testing = map(FD.to_integral_image, non_faces_testing)
# println("...done. ", length(non_faces_testing), " non-faces loaded.\n")
random_image = get_random_image(pos_testing_path)
if image_reconstruction
# Just for fun: putting all Haar-like features over each other generates a face-like image
@info("Constructing an image of all Haar-like Features found...")
reconstructed_image = FD.reconstruct(classifiers, img_size)
save(
joinpath(dirname(dirname(@__FILE__)), "figs", "reconstruction.png"),
Gray.(map(clamp01nan, reconstructed_image)),
)
@info(
"...done. See ",
joinpath(dirname(dirname(@__FILE__)), "figs", "reconstruction.png"),
".\n"
)
end
if feat_validation
@info("Constructing a validation image on a random image...")
validation_image = FD.generate_validation_image(random_image, classifiers)
save(
joinpath(dirname(dirname(@__FILE__)), "figs", "validation.png"),
validation_image,
)
@infp(
"...done. See ",
joinpath(dirname(dirname(@__FILE__)), "figs", "validation.png"),
".\n"
)
end
end
@time main(smart_choose_feats = true, image_reconstruction = true, feat_validation = false)