Compare segmented texture shape and area

Hi,

I'd like to make a custom segmentation lens, like the pizza example,
I'd like to add an event to see if the segmented pizza fulfills my criteria (like the round enough shape or the size of the pizza).
I wonder if I can get any hints for that.

Answers

  • Bakari Mustafa
    Bakari Mustafa Posts: 174 🔥🔥🔥

    To create a custom segmentation lens that checks if the segmented object fulfills certain criteria, you can use the ObjectSegmentation component and write a script to analyze the segmented object and determine if it meets your criteria.

    Here is how you could do this:

    1. Add an ObjectSegmentation component to your scene: Drag an ObjectSegmentation component from the Object Library onto the root object of your scene.
    2. Write a script to analyze the segmented object: In the script, use the "onSegmentationUpdate" event of the ObjectSegmentation component to get the segmentation data for the object and analyze it to determine if it meets your criteria. For example, you could use the "getSegmentationData" function to get the segmentation data for the object, and then use the data to calculate the size and shape of the object.

    Here is an example of how you could write a script to analyze the segmented object and determine if it meets your criteria:

    // Import the ObjectSegmentation component
    const ObjectSegmentation = require('ObjectSegmentation');
    
    // Get a reference to the ObjectSegmentation component
    const objectSegmentation = script.getSceneObject().getComponent(ObjectSegmentation);
    
    // Handle the onSegmentationUpdate event of the ObjectSegmentation component
    objectSegmentation.onSegmentationUpdate = function() {
      // Get the segmentation data for the object
      const segmentationData = objectSegmentation.getSegmentationData();
    
      // Calculate the size and shape of the object using the segmentation data
      const size = calculateSize(segmentationData);
      const shape = calculateShape(segmentationData);
    
      // Check if the object meets your criteria
      if (size >= MIN_SIZE && size <= MAX_SIZE && shape == DESIRED_SHAPE) {
        // The object meets your criteria
      } else {
        // The object does not meet your criteria
      }
    }
    
    function calculateSize(segmentationData) {
      // Calculate the size of the object using the segmentation data
      // ...
    }
    
    function calculateShape(segmentationData) {
      // Calculate the shape of the object using the segmentation data
      // ...
    }