Skip to content

LineStrips2D

Represents a collection of 2D line strips (polylines), where each strip is a sequence of connected 2D points. This datatype is used for contours, polygons, and paths from detection or segmentation within the Telekinesis ecosystem.

Field

Required

FieldTypeDescription
stripsSequence[ArrayLike]List of strips; each strip has shape (M, 2), dtype float32. Cannot be empty.

Optional

None.

Methods

MethodDescription
to_dict()Returns a dictionary with key strips: a list of arrays, each of shape (M, 2) (2D points per strip).

Example

From the datatypes examples:

python
import numpy as np
from datatypes import datatypes
from loguru import logger

# ------------------------------------------------
# 1. Create LineStrips2D instance
# ------------------------------------------------
strip_1 = np.array(
    [[0.0, 0.0], [1.0, 0.0], [0.5, 1.0], [0.0, 0.0]], dtype=np.float32
)
strip_2 = np.array(
    [[2.0, 0.0], [3.0, 0.0], [3.0, 1.0], [2.0, 1.0], [2.0, 0.0]],
    dtype=np.float32,
)
strip_3 = np.array(
    [[4.0, 0.0], [4.5, 0.5], [5.0, 0.0], [5.5, 0.5], [6.0, 0.0]],
    dtype=np.float32,
)
line_strips_2d = datatypes.LineStrips2D(strips=[strip_1, strip_2, strip_3])

# ------------------------------------------------
# 2. Access strips via to_dict
# ------------------------------------------------
strips_dict = line_strips_2d.to_dict()
strips_list = strips_dict["strips"]
logger.info("LineStrips2D to_dict num_strips={}", len(strips_list))
logger.info("LineStrips2D to_dict strip_0 shape={}", strips_list[0].shape)
logger.info("LineStrips2D to_dict strip_1 shape={}", strips_list[1].shape)
logger.info("LineStrips2D to_dict strip_2 shape={}", strips_list[2].shape)