Hair Segmentation

DeepAR SDK uses deep neural networks to find and segment the hair in the camera feed. The result of the hair segmentation is the hair mask texture which can be used to change the hair color.

Hair segmentation can be used simultaneously with face tracking.

There are many use cases for this feature. The first, and probably the most important of them all - it's really fun to see your hair change color in real-time. Hair Segmentation can also be used in hair styling and beautifying apps, as a tool to improve the sales of your hair products, in games or entertainment apps, or simply as a creative way to prank your friends.

Segmentation features
Hair segmentation features are supported on iPhone7 and newer devices.

Example tutorial

In this example, we will demonstrate how to implement a hair color segmentation.

  • Open the studio, go to File → Create new effect

  • Select the Root node and in Node properties set the Position mode to Position in camera space

  • Next, select the Root node, go to Node → Add Quad

  • Select that Quad and in Node properties put the quad into the Overlay layer

  • Go to the Textures tab, click Add → Hair Mask

This will add the special texture which is filled by the hair segmentation. The hair mask texture will be one channel (R8 format) and it will have the value 1.0 where the hair is and 0.0 otherwise.

Now, add the new texture from the example folder

(examples/hair_coloring/red.png)

  • Go to the Textures tab, click Add → Texture → red.png (examples/hair_coloring/red.png)

  • Select the Quad under Root node

  • In Material properties under Select Shaders choose LUT with alpha mask

  • Set the Input texture to Camera texture

  • Set the Alpha mask to Hair Mask

  • Set the LUT to red.png

Now, add the Camera Quad Component.

  • Select the Quad under Root node

  • In the menu bar go to the Add Components tab and select the Camera Quad component

In DeepAR Studio, the mask will not be the actual hair. Instead of the hair, the upper half of the texture will have value 1.0 and lower half 0.0.

In the mobile SDK, the hair mask will correctly track the hair.

Download this example with texture assets

Did this answer your question?