SegmentationModule Overview
SegmentationModule Overview
SegmentationModule Overview

SegmentationModule

The SegmentationModule class enables the separation of a person or hair or skin from a scene.

Example

//==============================================================================
// Hides a plane in the scene when a person is not detected in the camera view,
// and updates the opacity of a separate rectangle depending on how much of
// the camera view is obscured by that person's hair.
//
// Project setup:
// - One plane: plane0
// - One material: material0
// - One rectangle: rectangle0, with material0 assigned as its material
//
// Required project capabilities:
// - Segmentation > Person
//
//==============================================================================

// Load in the required modules
const Scene = require('Scene');
const Materials = require('Materials');
const Segmentation = require('Segmentation');
const Diagnostics = require('Diagnostics');

(async function() { // Enable async/await in JS [part 1]

  // Locate the plane, rectangle and material
  const [plane, material] = await Promise.all([
    Scene.root.findFirst('plane0'),
    Materials.findFirst('material0')
  ]);

  // Hide the plane if a person is not detected in the camera view
  plane.hidden = Segmentation.person.hasForeground.not();

  // Get the percentage of screen space obscured by hair and amplify the signal
  var hairForegroundPercent = Segmentation.hair.foregroundPercent.mul(10);

  // Bind the hair's foreground percent to the opacity of the material.
  material.opacity = hairForegroundPercent;

  // Add the segmentation properties used above to the watch view
  Diagnostics.watch("Hair foreground %: ", hairForegroundPercent);
  Diagnostics.watch("Person detected: ", Segmentation.person.hasForeground);

})(); // Enable async/await in JS [part 2]

Properties

PropertyDescription
hair
(get) hair: HairSegmentation
(set) (Not Available)


Specifies an instance of a HairSegmentation object.
person
(get) person: PersonSegmentation
(set) (Not Available)


Specifies an instance of a PersonSegmentation object.
skin
(get) skin: SkinSegmentation
(set) (Not Available)


Specifies an instance of a SkinSegmentation object.

Methods

This module exposes no methods.

Classes

ClassDescription
HairSegmentationThe HairSegmentation class exposes the information about a person's hair.
PersonSegmentationThe PersonSegmentation class exposes the information about a person.
SkinSegmentationThe SkinSegmentation class exposes the information about a person's skin.

Was this article helpful?