Back to Bokeh

Face Detection

examples/server/app/faces/templates/index.html

4.0.0.dev11022 B
Original Source

{% from macros import embed %}

Face Detection {{ bokeh_css | indent(8) }} {{ bokeh_js | indent(8) }}

Face Detection with Bokeh and OpenCV

This example detects faces in a live camera feed, draws a box around each one, and plots the number of faces seen over time.

Under the hood, OpenCV's Haar cascade scans each frame for contrast patterns. A Haar-like feature compares neighboring image regions:

{{ embed(roots.haar_feature) | indent(14) }}

Here, I(p) is the intensity of pixel p, while R+ and R− are neighboring rectangles whose summed intensities are compared (see Wikipedia's overview of Haar-like features).

Integral images make these sums fast, while the cascade rejects unlikely windows early. Bokeh flips the surviving boxes from OpenCV's top-left origin into its bottom-left plot space and streams them with the RGBA frame.

{{ embed(roots.image) | indent(10) }}

{{ embed(roots.ts) | indent(10) }}

{{ plot_script | indent(8) }}