public class AssumedObjectData extends Object
The assumed object's data. Includes object's type and area.
Saving image masking result with feathering based on image size. Image masking is performed using auto calculated default strokes. Additionally the data of the two assumed objects is also specified in the AssumedObjects property of the AutoMaskingGraphCutOptions.
List<AssumedObjectData> assumedObjects = new LinkedList<AssumedObjectData>(); assumedObjects.add(new AssumedObjectData(DetectedObjectType.Human, new Rectangle(100, 100, 150, 300))); assumedObjects.add(new AssumedObjectData(DetectedObjectType.Dog, new Rectangle(300, 100, 50, 30))); MaskingResult[] results; try (RasterImage image = (RasterImage)Image.load("input.jpg")) { try (PngOptions pngOptions = new PngOptions()) { pngOptions.setColorType(PngColorType.TruecolorWithAlpha); pngOptions.setSource(new FileCreateSource("tempFile")); AutoMaskingGraphCutOptions options = new AutoMaskingGraphCutOptions(); options.setAssumedObjects(assumedObjects); options.setCalculateDefaultStrokes(true); options.setFeatheringRadius((Math.max(image.getWidth(), image.getHeight()) / 500) + 1); options.setMethod(SegmentationMethod.GraphCut); options.setDecompose(false); options.setExportOptions(pngOptions); options.setBackgroundReplacementColor(Color.getTransparent()); results = new ImageMasking(image).decompose(options); } } try (RasterImage resultImage = (RasterImage)results[1].getImage()) { PngOptions pngOptions = new PngOptions(); pngOptions.setColorType(PngColorType.TruecolorWithAlpha); resultImage.save("output.png", pngOptions); } // release resources for (MaskingResult res : results) { res.close(); }
Constructor and Description |
---|
AssumedObjectData()
Initializes a new instance of the
AssumedObjectData class. |
AssumedObjectData(int type,
Rectangle bounds)
Initializes a new instance of the
AssumedObjectData class. |
AssumedObjectData(String type,
Rectangle bounds)
Initializes a new instance of the
AssumedObjectData class. |
Modifier and Type | Method and Description |
---|---|
Rectangle |
getBounds()
Gets the object's bounds.
|
int |
getType()
Gets the object's type.
|
void |
setBounds(Rectangle value)
Sets the object's bounds.
|
void |
setType(int value)
Sets the object's type.
|
public AssumedObjectData()
Initializes a new instance of the AssumedObjectData
class.
public AssumedObjectData(int type, Rectangle bounds)
Initializes a new instance of the AssumedObjectData
class.
type
- The object's type.bounds
- The object's bounds.DetectedObjectType
public AssumedObjectData(String type, Rectangle bounds)
Initializes a new instance of the AssumedObjectData
class.
type
- The object's type.bounds
- The object's bounds.public final int getType()
Gets the object's type.
public final void setType(int value)
Sets the object's type.
value
- the object's type.public final Rectangle getBounds()
Gets the object's bounds.
public final void setBounds(Rectangle value)
Sets the object's bounds.
value
- the object's bounds.