|
| 1 | +#!/usr/bin/env bash |
| 2 | + #= |
| 3 | + exec julia --project="$(realpath $(dirname $0))/" "${BASH_SOURCE[0]}" "$@" -e "include(popfirst!(ARGS))" \ |
| 4 | + "${BASH_SOURCE[0]}" "$@" |
| 5 | + =# |
| 6 | + |
| 7 | + |
| 8 | +#= |
| 9 | +Adapted from https://github.com/Simon-Hohberg/Viola-Jones/ |
| 10 | +=# |
| 11 | + |
| 12 | + |
| 13 | +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") |
| 14 | + |
| 15 | +include(joinpath(dirname(dirname(@__FILE__)), "src", "FaceDetection.jl")) |
| 16 | + |
| 17 | +using .FaceDetection |
| 18 | +const FD = FaceDetection |
| 19 | +using Printf: @printf |
| 20 | +using Images: imresize |
| 21 | +using Serialization: deserialize |
| 22 | + |
| 23 | +println("...done") |
| 24 | + |
| 25 | +function main(; |
| 26 | + smart_choose_feats::Bool=false, alt::Bool=false |
| 27 | +) |
| 28 | + |
| 29 | + # we assume that `smart_choose_feats = true` |
| 30 | + main_path = dirname(dirname(@__FILE__)) |
| 31 | + data_path = joinpath(main_path, "data") |
| 32 | + main_image_path = joinpath(main_path, "data", "main") |
| 33 | + alt_image_path = joinpath(main_path, "data", "alt") |
| 34 | + |
| 35 | + if alt |
| 36 | + # pos_testing_path = joinpath(alt_image_path, "testing", "pos") |
| 37 | + # neg_testing_path = joinpath(homedir(), "Desktop", "Assorted Personal Documents", "Wallpapers copy") |
| 38 | + pos_testing_path = joinpath(main_image_path, "testset", "faces")#joinpath(homedir(), "Desktop", "faces")#"$main_image_path/testset/faces/" |
| 39 | + neg_testing_path = joinpath(main_image_path, "testset", "non-faces") |
| 40 | + else |
| 41 | + pos_testing_path = joinpath(main_image_path, "testset", "faces")#joinpath(homedir(), "Desktop", "faces")#"$main_image_path/testset/faces/" |
| 42 | + neg_testing_path = joinpath(main_image_path, "testset", "non-faces") |
| 43 | + end |
| 44 | + |
| 45 | + # pos_testing_path = joinpath(data_path, "lizzie-testset", "faces") |
| 46 | + # neg_testing_path = joinpath(data_path, "lizzie-testset", "nonfaces") |
| 47 | + |
| 48 | + if ! isfile(joinpath(dirname(@__FILE__), "data", "haar-like_features")) |
| 49 | + error(throw("You do not have a data file. Ensure you run \"write.jl\" to obtain your Haar-like features before running this script/")) |
| 50 | + end |
| 51 | + |
| 52 | + # read classifiers from file |
| 53 | + classifiers = deserialize(joinpath(dirname(@__FILE__), "data", "haar-like_features")) |
| 54 | + |
| 55 | + FD.notify_user("Loading test faces...") |
| 56 | + |
| 57 | + faces_testing = FD.load_images(pos_testing_path)[1] |
| 58 | + # faces_ii_testing = map(FD.to_integral_image, faces_testing) |
| 59 | + faces_ii_testing = map(FD.to_integral_image, faces_testing) |
| 60 | + println("...done. ", length(faces_testing), " faces loaded.") |
| 61 | + |
| 62 | + FD.notify_user("Loading test non-faces..") |
| 63 | + |
| 64 | + non_faces_testing = FD.load_images(neg_testing_path)[1] |
| 65 | + non_faces_ii_testing = map(FD.to_integral_image, non_faces_testing) |
| 66 | + println("...done. ", length(non_faces_testing), " non-faces loaded.\n") |
| 67 | + |
| 68 | + FD.notify_user("Testing selected classifiers...") |
| 69 | + correct_faces = 0 |
| 70 | + correct_non_faces = 0 |
| 71 | + |
| 72 | + # correct_faces = sum([FD._get_feature_vote(face, classifiers) for face in faces_ii_testing]) |
| 73 | + # correct_non_faces = length(non_faces_testing) - sum([FD._get_feature_vote(nonFace, classifiers) for nonFace in non_faces_ii_testing]) |
| 74 | + correct_faces = sum(FD.ensemble_vote_all(faces_ii_testing, classifiers)) |
| 75 | + correct_non_faces = length(non_faces_testing) - sum(FD.ensemble_vote_all(non_faces_ii_testing, classifiers)) |
| 76 | + correct_faces_percent = (float(correct_faces) / length(faces_testing)) * 100 |
| 77 | + correct_non_faces_percent = (float(correct_non_faces) / length(non_faces_testing)) * 100 |
| 78 | + |
| 79 | + faces_frac = string(correct_faces, "/", length(faces_testing)) |
| 80 | + faces_percent = string("(", correct_faces_percent, "% of faces were recognised as faces)") |
| 81 | + non_faces_frac = string(correct_non_faces, "/", length(non_faces_testing)) |
| 82 | + non_faces_percent = string("(", correct_non_faces_percent, "% of non-faces were identified as non-faces)") |
| 83 | + |
| 84 | + println("...done.\n") |
| 85 | + FD.notify_user("Result:\n") |
| 86 | + |
| 87 | + @printf("%10.9s %10.15s %15s\n", "Faces:", faces_frac, faces_percent) |
| 88 | + @printf("%10.9s %10.15s %15s\n\n", "Non-faces:", non_faces_frac, non_faces_percent) |
| 89 | +end |
| 90 | + |
| 91 | +@time main(smart_choose_feats=true, alt=false) |
0 commit comments