# Masking faces in a webcam stream

**URL:** <https://community.wolfram.com/t/masking-faces-in-a-webcam-stream/144>\
**Category:** Ideas\
**Tags:** mathematica, graphics-and-visualization, ui-ux-and-ide, virtual-reality\
**Created:** [February 1, 2013, 10:50pm UTC](https://community.wolfram.com/t/masking-faces-in-a-webcam-stream/144 "2013-02-01T22:50:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vitaliyk](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/vitaliyk/32/45591_2.png) [@Vitaliyk](https://community.wolfram.com/u/Vitaliyk)\
**Post date:** [February 1, 2013, 10:50pm UTC](https://community.wolfram.com/t/masking-faces-in-a-webcam-stream/144/1 "2013-02-01T22:50:28Z")

</div>

**[Christopher question about augmented reality](http://www.wolfram.com/community/web/community/groups/-/message_boards/message/34483)** reminded me about a concealed identity trick used in video streams when black strips or blurred areas follow character faces. We can do this with Mathematica **[FindFaces](http://reference.wolfram.com/mathematica/ref/FindFaces.html)** functionality. There are a few different ways we can overlay transparent or opaque graphic objects and images with a live video stream. One of them is simply using Show. Let us find some simple overlay masks  and what can be better than some glasses, mustaches, goatees, and pipes?

```auto
mask = Import /@ {
   "http://i.imgur.com/155BjOY.png",
   "http://i.imgur.com/zq3Qsm6.png",
   "http://i.imgur.com/kONG87s.png",
   "http://i.imgur.com/WaQkDsn.png",
   "http://i.imgur.com/JZqCWEN.png",
   "http://i.imgur.com/9Y5CcUQ.png",
   "http://i.imgur.com/5CiN4Af.png"
   }

```

![](https://global.discourse-cdn.com/wolfram/original/3X/c/a/caa99dd3a203cd02dbfd127c2b4c2d85dc1c2f2a.png)  
Now execute this code and bring a few friends to smile into camera:

```auto
Manipulate[
 i = CurrentImage[];
 Show[i, Graphics[
   MapThread[
    Inset[If[mix == "RANDOM", RandomChoice[mask], mix, mix], 
      Offset[{0, -.27 #2}, #1], Center, #2] &,
    {Mean /@ #, -.8 Subtract @@@ #[[All, All, 1]]} &[FindFaces[i]]
    ]
   ], ImageSize -> 450]
 , {{mix, mask[[7]], ""}, mask~Join~{"RANDOM"}, Setter}, 
 FrameMargins -> 0, SynchronousUpdating -> False]

```

 ![](https://global.discourse-cdn.com/wolfram/original/3X/f/9/f90e4b1f3cb44f2a800297a2fe5a3d92a2606996.jpeg)  
Thanks to our Wolfram volunteers for avid participation! Let me know if you can think of any improvements for this code.  
Have fun!

---

<div class="post-metadata">

**Author:** ![ewages](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ewages/32/14090_2.png) [@ewages](https://community.wolfram.com/u/ewages)\
**Post date:** [February 1, 2013, 11:13pm UTC](https://community.wolfram.com/t/masking-faces-in-a-webcam-stream/144/2 "2013-02-01T23:13:20Z")

</div>

Excellent! And now we need [Mustache curves](http://www.wolframalpha.com/input/?i=mustache+curves) in Wolfram|Alpha to go with our [other fun new curves](http://www.wolframalpha.com/input/?i=fictional+character+curves). This should be a Movember feature request.
