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 ImageMagick ──────────── v1.2.1 Installed LERC_jll ─────────────── v4.0.1+0 Installed ImageIO ──────────────── v0.6.8 Installed TiledIteration ───────── v0.3.1 Installed TiffImages ───────────── v0.10.2 Installed Gtk ──────────────────── v1.3.1 Installed ImageSegmentation ────── v1.8.1 Installed Xorg_libXcomposite_jll ─ v0.4.6+0 Installed EllipsisNotation ─────── v1.8.0 Installed JLD2 ─────────────────── v0.4.54 Installed at_spi2_core_jll ─────── v2.56.2+0 Installed Images ───────────────── v0.25.3 Installed MetaGraphs ───────────── v0.7.2 Installed GtkReactive ──────────── v1.0.6 Installed SpecialFunctions ─────── v2.5.1 Installed GTK3_jll ─────────────── v3.24.31+0 Installed adwaita_icon_theme_jll ─ v3.33.93+0 Installed ImageMagick_jll ──────── v6.9.13025+0 Installed ImageMetadata ────────── v0.9.9 Installed Xorg_libXtst_jll ─────── v1.2.5+0 Installed Colors ───────────────── v0.12.11 Installed gdk_pixbuf_jll ───────── v2.42.13+0 Installed ColorTypes ───────────── v0.11.5 Installed StatsBase ────────────── v0.33.21 Installed ImageCore ────────────── v0.9.4 Installed Dbus_jll ─────────────── v1.16.2+0 Installed at_spi2_atk_jll ──────── v2.38.0+0 Installed ATK_jll ──────────────── v2.38.1+0 Installed Reactive ─────────────── v0.8.3 Installed ImageTransformations ─── v0.9.5 Installed QuartzImageIO ────────── v0.7.4 Installed Libtiff_jll ──────────── v4.7.1+0 Installed ColorVectorSpace ─────── v0.9.10 Installed ColorSchemes ─────────── v3.26.0 Installed OpenSpecFun_jll ──────── v0.5.6+0 Installed ImageBase ────────────── v0.1.5 Installed AxisAlgorithms ───────── v1.0.1 Installed ImageAxes ────────────── v0.6.11 Installed WoodburyMatrices ─────── v0.5.6 Installed ImageMorphology ──────── v0.3.2 Installed ImageView ────────────── v0.10.15 Installed ImageFiltering ───────── v0.7.6 Installed IntervalSets ─────────── v0.5.4 Installed Interpolations ───────── v0.14.0 Installed FaceDetection ────────── v1.1.0 Updating `~/work/FaceDetection.jl/FaceDetection.jl/docs/Project.toml` [00808967] ~ FaceDetection v1.2.0 `~/work/FaceDetection.jl/FaceDetection.jl` ⇒ v1.1.0 Updating `~/work/FaceDetection.jl/FaceDetection.jl/docs/Manifest.toml` [66dad0bd] - AliasTables v1.1.3 ⌃ [13072b0f] ↓ AxisAlgorithms v1.1.0 ⇒ v1.0.1 [d1d4a3ce] - BitFlags v0.1.9 [62783981] - BitTwiddlingConvenienceFunctions v0.1.6 [2a0fbf3d] - CPUSummary v0.2.6 [fb6a15b2] - CloseOpenIntervals v0.1.13 ⌃ [35d6a980] ↓ ColorSchemes v3.29.0 ⇒ v3.26.0 ⌅ [3da002f7] ↓ ColorTypes v0.12.1 ⇒ v0.11.5 ⌅ [c3611d14] ↓ ColorVectorSpace v0.11.0 ⇒ v0.9.10 ⌅ [5ae59095] ↓ Colors v0.13.1 ⇒ v0.12.11 [187b0558] - ConstructionBase v1.6.0 [adafc99b] - CpuId v0.3.1 [da5c29d0] + EllipsisNotation v1.8.0 [00808967] ~ FaceDetection v1.2.0 `~/work/FaceDetection.jl/FaceDetection.jl` ⇒ v1.1.0 [4c0ca9eb] + Gtk v1.3.1 [9db2cae5] - Gtk4 v0.7.8 [8710efd8] - GtkObservables v2.2.0 [27996c0f] + GtkReactive v1.0.6 [076d061b] - HashArrayMappedTries v0.2.0 [2c695a8d] - HistogramThresholding v0.3.1 [3e5b6fbb] - HostCPUFeatures v0.1.17 ⌃ [2803e5a7] ↓ ImageAxes v0.6.12 ⇒ v0.6.11 ⌃ [c817782e] ↓ ImageBase v0.1.7 ⇒ v0.1.5 [cbc4b850] - ImageBinarization v0.3.1 ⌅ [a09fc81d] ↓ ImageCore v0.10.5 ⇒ v0.9.4 [89d5987c] - ImageCorners v0.1.3 ⌃ [6a3955dd] ↓ ImageFiltering v0.7.10 ⇒ v0.7.6 ⌃ [82e4d734] ↓ ImageIO v0.6.9 ⇒ v0.6.8 ⌃ [6218d12a] ↓ ImageMagick v1.4.2 ⇒ v1.2.1 ⌃ [bc367c6b] ↓ ImageMetadata v0.9.10 ⇒ v0.9.9 ⌅ [787d08f9] ↓ ImageMorphology v0.4.6 ⇒ v0.3.2 ⌃ [80713f31] ↓ ImageSegmentation v1.9.0 ⇒ v1.8.1 ⌅ [02fcd773] ↓ ImageTransformations v0.10.2 ⇒ v0.9.5 ⌅ [86fae568] ↓ ImageView v0.12.6 ⇒ v0.10.15 ⌅ [916415d5] ↓ Images v0.26.2 ⇒ v0.25.3 ⌅ [a98d9a8b] ↓ Interpolations v0.16.1 ⇒ v0.14.0 ⌅ [8197267c] ↓ IntervalSets v0.7.11 ⇒ v0.5.4 ⌅ [033835bb] ↓ JLD2 v0.5.15 ⇒ v0.4.54 [10f19ff3] - LayoutPointers v0.1.17 [bdcacae8] - LoopVectorization v0.12.172 [d125e4d3] - ManualMemory v0.1.8 ⌅ [626554b9] ↓ MetaGraphs v0.8.0 ⇒ v0.7.2 [d4071afc] - MultiChannelColors v0.1.4 [510215fc] - Observables v0.5.5 [1d0040c9] - PolyesterWeave v0.2.2 [f27b6e38] - Polynomials v4.1.0 [43287f4e] - PtrArrays v1.3.0 ⌃ [dca85d43] ↓ QuartzImageIO v0.7.5 ⇒ v0.7.4 [a223df75] + Reactive v0.8.3 [3cdcf5f2] - RecipesBase v1.3.4 [94e857df] - SIMDTypes v0.1.0 [476501e8] - SLEEFPirates v0.6.43 [7e506255] - ScopedValues v1.3.0 [efcf1570] - Setfield v1.1.2 [276daf66] + SpecialFunctions v2.5.1 ⌅ [2913bbd2] ↓ StatsBase v0.34.5 ⇒ v0.33.21 [8290d209] - ThreadingUtilities v0.5.5 ⌅ [731e570b] ↓ TiffImages v0.11.4 ⇒ v0.10.2 ⌅ [06e1c1a7] ↓ TiledIteration v0.5.0 ⇒ v0.3.1 [3d5dd08c] - VectorizationBase v0.21.71 [e3aaa7dc] - WebP v0.1.3 ⌅ [efce3f68] ↓ WoodburyMatrices v1.0.0 ⇒ v0.5.6 [7b86fcea] + ATK_jll v2.38.1+0 [ee1fde0b] + Dbus_jll v1.16.2+0 [77ec8976] + GTK3_jll v3.24.31+0 [6ebb71f1] - GTK4_jll v4.14.5+0 [59f7168a] - Giflib_jll v5.2.3+0 [75302f13] - Graphene_jll v1.10.8+0 ⌅ [c73af94c] ↓ ImageMagick_jll v7.1.1048+0 ⇒ v6.9.13025+0 [88015f11] ↑ LERC_jll v3.0.0+1 ⇒ v4.0.1+0 [89763e89] ↑ Libtiff_jll v4.5.1+1 ⇒ v4.7.1+0 [efe28fd5] + OpenSpecFun_jll v0.5.6+0 [2381bf8a] - Wayland_protocols_jll v1.44.0+0 [3c9796d7] + Xorg_libXcomposite_jll v0.4.6+0 [b6f176f1] + Xorg_libXtst_jll v1.2.5+0 ⌅ [b437f822] ↓ adwaita_icon_theme_jll v43.0.1+0 ⇒ v3.33.93+0 [de012916] + at_spi2_atk_jll v2.38.0+0 [0fc3237b] + at_spi2_core_jll v2.56.2+0 [da03df04] ↑ gdk_pixbuf_jll v2.42.12+0 ⇒ v2.42.13+0 [c5f90fcd] - libwebp_jll v1.4.0+0 [9fa8497b] - Future v1.11.0 Info Packages marked with ⌃ and ⌅ have new versions available. Those with ⌃ may be upgradable, but those with ⌅ are restricted by compatibility constraints from upgrading. To see why use `status --outdated -m` Precompiling project... 678.5 ms ✓ LERC_jll 792.9 ms ✓ TiledIteration 819.4 ms ✓ OpenSpecFun_jll 942.5 ms ✓ WoodburyMatrices 851.3 ms ✓ Dbus_jll 789.7 ms ✓ adwaita_icon_theme_jll 1217.3 ms ✓ Reactive 888.8 ms ✓ EllipsisNotation 804.6 ms ✓ Xorg_libXtst_jll 1115.2 ms ✓ Xorg_libXcomposite_jll 862.8 ms ✓ ATK_jll 3770.0 ms ✓ ColorTypes 3329.8 ms ✓ StatsBase 837.2 ms ✓ AxisAlgorithms 1183.6 ms ✓ Libtiff_jll 840.2 ms ✓ IntervalSets 881.6 ms ✓ at_spi2_core_jll 4129.6 ms ✓ SpecialFunctions 3007.6 ms ✓ Interpolations 1137.2 ms ✓ LittleCMS_jll 1067.6 ms ✓ gdk_pixbuf_jll 1050.2 ms ✓ at_spi2_atk_jll 7766.2 ms ✓ Colors 3362.4 ms ✓ SpecialFunctions → SpecialFunctionsChainRulesCoreExt 1105.7 ms ✓ OpenJpeg_jll 4350.2 ms ✓ ColorVectorSpace 1588.5 ms ✓ Librsvg_jll 1112.7 ms ✓ GTK3_jll 1054.8 ms ✓ ImageMagick_jll 5624.2 ms ✓ ColorSchemes 19873.8 ms ✓ Gtk ✗ GtkReactive 43054.0 ms ✓ ImageCore 3352.6 ms ✓ ImageMorphology 3810.7 ms ✓ QuartzImageIO 60253.2 ms ✓ JLD2 4515.8 ms ✓ ImageBase 3352.3 ms ✓ MetaGraphs 4665.6 ms ✓ ImageAxes 6663.2 ms ✓ ImageMagick 3155.3 ms ✓ ImageTransformations 2022.1 ms ✓ ImageMetadata ✗ ImageView 90088.6 ms ✓ TiffImages 938.9 ms ✓ ImageIO 71276.9 ms ✓ ImageFiltering 4054.2 ms ✓ ImageSegmentation 22341.7 ms ✓ Images 4101.8 ms ✓ FaceDetection 47 dependencies successfully precompiled in 164 seconds. 208 already precompiled. 22 dependencies precompiled but different versions are currently loaded. Restart julia to access the new versions. Otherwise, loading dependents of these packages may trigger further precompilation to work with the unexpected 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. └

Index