The SegmentationModule
class enables the separation of a person or hair or skin from a scene.
//============================================================================== // 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]
Property | Description |
---|---|
hair | (get) hair: HairSegmentation Specifies an instance of a HairSegmentation object. |
person | (get) person: PersonSegmentation Specifies an instance of a PersonSegmentation object. |
skin | (get) skin: SkinSegmentation Specifies an instance of a SkinSegmentation object. |
This module exposes no methods.
Class | Description |
---|---|
HairSegmentation | The HairSegmentation class exposes the information about a person's hair. |
PersonSegmentation | The PersonSegmentation class exposes the information about a person. |
SkinSegmentation | The SkinSegmentation class exposes the information about a person's skin. |