Home

This is a Julia implementation of Viola-Jones' Object Detection algorithm. Although there is an OpenCV port in Julia, it seems to be ill-maintained. As this algorithm was created for commercial use, there seem to be few widely-used or well-documented implementations of it on GitHub. The implementation this repository is based off is Simon Hohberg's Pythonic repository, as it seems to be well written (and the most starred Python implementation on GitHub, though this is not necessarily a good measure). Julia and Python alike are easy to read and write in — my thinking was that this would be easy enough to replicate in Julia, except for Pythonic classes, where I would have to use structs (or at least easier to replicate from than, for example, C++ or JS — two other highly-starred repositories.).

Important Note

I implore collaboration. I am an undergraduate student with no formal education in computer science (or computer vision of any form for that matter); I am certain this code can be refined/optimised by better programmers than myself. This package is still maturing, and as such there are some things I would still like to implement. Please, help me out if you like!

How it works

In an over-simplified manner, the Viola-Jones algorithm has some four stages:

  1. Takes an image, converts it into an array of intensity values (i.e., in grey-scale), and constructs an Integral Image, such that for every element in the array, the Integral Image element is the sum of all elements above and to the left of it. This makes calculations easier for step 2.
  2. Finds Haar-like Features from Integral Image.
  3. There is now a training phase using sets of faces and non-faces. This phase uses something called Adaboost (short for Adaptive Boosting). Boosting is one method of Ensemble Learning. There are other Ensemble Learning methods like Bagging, Stacking, &c.. The differences between Bagging, Boosting, Stacking are:
    • Bagging uses equal weight voting. Trains each model with a random drawn subset of training set.
    • Boosting trains each new model instance to emphasize the training instances that previous models mis-classified. Has better accuracy comparing to bagging, but also tends to overfit.
    • Stacking trains a learning algorithm to combine the predictions of several other learning algorithms.

Despite this method being developed at the start of the century, it is blazingly fast compared to some machine learning algorithms, and still widely used.

  1. Finally, this algorithm uses Cascading Classifiers to identify faces. (See page 12 of the original paper for the specific cascade).

For a better explanation, read the paper from 2001, or see the Wikipedia page on this algorithm.

Adding FaceDetection.jl

julia> using Pkg
julia> Pkg.add("FaceDetection") Updating registry at `~/.julia/registries/General.toml` Resolving package versions... Installed IfElse ─────────────── v0.1.1 Installed Static ─────────────── v0.8.10 Installed StaticArrayInterface ─ v1.5.0 Installed EllipsisNotation ───── v1.8.0 Installed GtkReactive ────────── v1.0.6 Installed StatsBase ──────────── v0.33.21 Installed ArrayInterface ─────── v7.10.0 Installed Adapt ──────────────── v4.0.4 Installed Reactive ───────────── v0.8.3 Installed IntervalSets ───────── v0.5.4 Installed ImageView ──────────── v0.10.15 Installed FaceDetection ──────── v1.1.0 Installed Interpolations ─────── v0.14.0 Updating `~/work/FaceDetection.jl/FaceDetection.jl/docs/Project.toml` [00808967] ~ FaceDetection v1.1.0 `~/work/FaceDetection.jl/FaceDetection.jl` ⇒ v1.1.0 ⌅ [86fae568] ↓ ImageView v0.11.7 ⇒ v0.10.15 Updating `~/work/FaceDetection.jl/FaceDetection.jl/docs/Manifest.toml` [79e6a3ab] ↑ Adapt v3.7.2 ⇒ v4.0.4 [4fba245c] + ArrayInterface v7.10.0 [da5c29d0] + EllipsisNotation v1.8.0 [00808967] ~ FaceDetection v1.1.0 `~/work/FaceDetection.jl/FaceDetection.jl` ⇒ v1.1.0 [8710efd8] - GtkObservables v1.2.9 [27996c0f] + GtkReactive v1.0.6 [615f187c] + IfElse v0.1.1 ⌅ [86fae568] ↓ ImageView v0.11.7 ⇒ v0.10.15 ⌅ [a98d9a8b] ↓ Interpolations v0.14.7 ⇒ v0.14.0 ⌅ [8197267c] ↓ IntervalSets v0.7.10 ⇒ v0.5.4 [d4071afc] - MultiChannelColors v0.1.3 [510215fc] - Observables v0.5.5 [a223df75] + Reactive v0.8.3 [aedffcd0] + Static v0.8.10 [0d7ed370] + StaticArrayInterface v1.5.0 ⌅ [2913bbd2] ↓ StatsBase v0.34.3 ⇒ v0.33.21 [4607b0f0] + SuiteSparse Info Packages marked with ⌅ have new versions available but compatibility constraints restrict them from upgrading. To see why use `status --outdated -m` Precompiling project... ✓ IfElse ✓ Adapt ✓ SuiteSparse ✓ Reactive ✓ Static ✓ Adapt → AdaptStaticArraysExt ✓ ArrayInterface ✓ StatsBase ✓ ArrayInterface → ArrayInterfaceStaticArraysCoreExt ✓ Interpolations ✓ StaticArrayInterface ✓ StaticArrayInterface → StaticArrayInterfaceStaticArraysExt ✓ StaticArrayInterface → StaticArrayInterfaceOffsetArraysExt ✓ EllipsisNotation ✓ IntervalSets ✗ GtkReactive ✗ ImageView ✓ FaceDetection 16 dependencies successfully precompiled in 28 seconds. 210 already precompiled. 5 dependencies precompiled but different versions are currently loaded. Restart julia to access the new versions 1 dependency had output during precompilation: ┌ Interpolations │ WARNING: method definition for checkbounds at /home/runner/.julia/packages/Interpolations/USkTk/src/Interpolations.jl:454 declares type variable N but does not use it. │ WARNING: method definition for checkbounds at /home/runner/.julia/packages/Interpolations/USkTk/src/Interpolations.jl:457 declares type variable N but does not use it. │ WARNING: method definition for GriddedInterpolation at /home/runner/.julia/packages/Interpolations/USkTk/src/gridded/gridded.jl:37 declares type variable pad but does not use it. │ WARNING: method definition for GriddedInterpolation at /home/runner/.julia/packages/Interpolations/USkTk/src/gridded/gridded.jl:60 declares type variable pad but does not use it. │ WARNING: method definition for interpolate! at /home/runner/.julia/packages/Interpolations/USkTk/src/deprecations.jl:30 declares type variable TWeights but does not use it. └ The following 1 direct dependency failed to precompile: ImageView [86fae568-95e7-573e-a6b2-d8a6b900c9ef] Failed to precompile ImageView [86fae568-95e7-573e-a6b2-d8a6b900c9ef] to "/home/runner/.julia/compiled/v1.10/ImageView/jl_XsIMbV". ERROR: LoadError: InitError: Cannot open display: Stacktrace: [1] error(s::String) @ Base ./error.jl:35 [2] Gtk.GLib.GError(f::Gtk.var"#325#331") @ Gtk.GLib ~/.julia/packages/Gtk/oo3cW/src/GLib/gerror.jl:17 [3] __init__() @ Gtk ~/.julia/packages/Gtk/oo3cW/src/Gtk.jl:142 [4] run_module_init(mod::Module, i::Int64) @ Base ./loading.jl:1134 [5] register_restored_modules(sv::Core.SimpleVector, pkg::Base.PkgId, path::String) @ Base ./loading.jl:1122 [6] _include_from_serialized(pkg::Base.PkgId, path::String, ocachepath::String, depmods::Vector{Any}) @ Base ./loading.jl:1067 [7] _require_search_from_serialized(pkg::Base.PkgId, sourcepath::String, build_id::UInt128) @ Base ./loading.jl:1581 [8] _require(pkg::Base.PkgId, env::String) @ Base ./loading.jl:1938 [9] __require_prelocked(uuidkey::Base.PkgId, env::String) @ Base ./loading.jl:1812 [10] #invoke_in_world#3 @ ./essentials.jl:926 [inlined] [11] invoke_in_world @ ./essentials.jl:923 [inlined] [12] _require_prelocked(uuidkey::Base.PkgId, env::String) @ Base ./loading.jl:1803 [13] macro expansion @ ./loading.jl:1790 [inlined] [14] macro expansion @ ./lock.jl:267 [inlined] [15] __require(into::Module, mod::Symbol) @ Base ./loading.jl:1753 [16] #invoke_in_world#3 @ ./essentials.jl:926 [inlined] [17] invoke_in_world @ ./essentials.jl:923 [inlined] [18] require(into::Module, mod::Symbol) @ Base ./loading.jl:1746 [19] include @ ./Base.jl:495 [inlined] [20] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt128}}, source::Nothing) @ Base ./loading.jl:2222 [21] top-level scope @ stdin:3 during initialization of module Gtk in expression starting at /home/runner/.julia/packages/ImageView/N01cp/src/ImageView.jl:1 in expression starting at stdin:

Index