Skip to content

Commit

Permalink
Merge pull request #670 from roboflow/line-counter-ux-improvements
Browse files Browse the repository at this point in the history
Line counter improvements
  • Loading branch information
grzegorz-roboflow authored Sep 24, 2024
2 parents 039e525 + 6cfe722 commit 658cb3f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
2 changes: 1 addition & 1 deletion inference/core/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.20.0"
__version__ = "0.20.1"


if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@ class LineCounterManifest(WorkflowBlockManifest):
)

line_segment: Union[list, StepOutputSelector(kind=[LIST_OF_VALUES_KIND]), WorkflowParameterSelector(kind=[LIST_OF_VALUES_KIND])] = Field( # type: ignore
description="Lines (one for each batch) in a format [(x1, y1), (x2, y2)];"
" direction of line zone is assumed to be that of direction of vector normal to [(x1, y1), (x2, y2)]",
examples=["$inputs.zones"],
description="Line in the format [[x1, y1], [x2, y2]] consisting of exactly two points. For line [[0, 100], [100, 100]] line will count objects entering from the bottom as IN",
examples=[[[0, 50], [500, 50]], "$inputs.zones"],
)
triggering_anchor: Union[str, WorkflowParameterSelector(kind=[STRING_KIND])] = Field( # type: ignore
description=f"Triggering anchor. Allowed values: {', '.join(sv.Position.list())}",
triggering_anchor: Union[str, WorkflowParameterSelector(kind=[STRING_KIND]), Literal[tuple(sv.Position.list())]] = Field( # type: ignore
description=f"Point from the detection for triggering line crossing.",
default="CENTER",
examples=["CENTER"],
)
Expand Down
31 changes: 23 additions & 8 deletions inference/core/workflows/core_steps/visualizations/line_zone/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from inference.core.workflows.core_steps.visualizations.common.utils import str_to_color
from inference.core.workflows.execution_engine.entities.base import WorkflowImageData
from inference.core.workflows.execution_engine.entities.types import (
FLOAT_KIND,
FLOAT_ZERO_TO_ONE_KIND,
INTEGER_KIND,
LIST_OF_VALUES_KIND,
Expand Down Expand Up @@ -47,9 +48,8 @@ class LineCounterZoneVisualizationManifest(VisualizationManifest):
}
)
zone: Union[list, StepOutputSelector(kind=[LIST_OF_VALUES_KIND]), WorkflowParameterSelector(kind=[LIST_OF_VALUES_KIND])] = Field( # type: ignore
description="Line zones (one for each batch) in a format [[(x1, y1), (x2, y2)], ...];"
" each zone must consist of exactly two points",
examples=["$inputs.zones"],
description="Line in the format [[x1, y1], [x2, y2]] consisting of exactly two points.",
examples=[[[0, 50], [500, 50]], "$inputs.zones"],
)
color: Union[str, WorkflowParameterSelector(kind=[STRING_KIND])] = Field( # type: ignore
description="Color of the zone.",
Expand All @@ -61,15 +61,27 @@ class LineCounterZoneVisualizationManifest(VisualizationManifest):
default=2,
examples=[2, "$inputs.thickness"],
)
text_thickness: Union[int, WorkflowParameterSelector(kind=[INTEGER_KIND])] = Field( # type: ignore
description="Thickness of the text in pixels.",
default=1,
examples=[1, "$inputs.text_thickness"],
)
text_scale: Union[float, WorkflowParameterSelector(kind=[FLOAT_KIND])] = Field( # type: ignore
description="Scale of the text.",
default=1.0,
examples=[1.0, "$inputs.text_scale"],
)
count_in: Union[int, WorkflowParameterSelector(kind=[INTEGER_KIND]), StepOutputSelector(kind=[INTEGER_KIND])] = Field( # type: ignore
description="Thickness of the lines in pixels.",
description="Reference to the number of objects that crossed into the line zone.",
default=0,
examples=[2, "$inputs.thickness"],
examples=["$steps.line_counter.count_in"],
json_schema_extra={"always_visible": True},
)
count_out: Union[int, WorkflowParameterSelector(kind=[INTEGER_KIND]), StepOutputSelector(kind=[INTEGER_KIND])] = Field( # type: ignore
description="Thickness of the lines in pixels.",
description="Reference to the number of objects that crossed out of the line zone.",
default=0,
examples=[2, "$inputs.thickness"],
examples=["$steps.line_counter.count_out"],
json_schema_extra={"always_visible": True},
)
opacity: Union[FloatZeroToOne, WorkflowParameterSelector(kind=[FLOAT_ZERO_TO_ONE_KIND])] = Field( # type: ignore
description="Transparency of the Mask overlay.",
Expand Down Expand Up @@ -104,6 +116,8 @@ def run(
copy_image: bool,
color: str,
thickness: int,
text_thickness: int,
text_scale: int,
count_in: int,
count_out: int,
opacity: float,
Expand Down Expand Up @@ -142,7 +156,8 @@ def run(
scene=annotated_image,
text=f"in: {count_in}, out: {count_out}",
text_anchor=sv.Point(x1, y1),
text_thickness=1,
text_thickness=text_thickness,
text_scale=text_scale,
background_color=sv.Color.WHITE,
text_padding=0,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def test_line_counter_zone_validation_when_valid_manifest_is_given(
"color": "#FFFFFF",
"opacity": 0.5,
"thickness": 3,
"text_thickness": 1,
"text_scale": 2.0,
"count_in": 7,
"count_out": 1,
}
Expand All @@ -44,6 +46,8 @@ def test_line_counter_zone_validation_when_valid_manifest_is_given(
color="#FFFFFF",
opacity=0.5,
thickness=3,
text_thickness=1,
text_scale=2.0,
count_in=7,
count_out=1,
)
Expand All @@ -59,6 +63,8 @@ def test_line_counter_zone_validation_when_invalid_image_is_given() -> None:
"color": "#FFFFFF",
"opacity": 0.5,
"thickness": 3,
"text_thickness": 1,
"text_scale": 2.0,
"count_in": 7,
"count_out": 1,
}
Expand All @@ -83,6 +89,8 @@ def test_line_counter_zone_visualization_block() -> None:
color="#FF0000",
opacity=1,
thickness=3,
text_thickness=1,
text_scale=1.0,
count_in=7,
count_out=1,
)
Expand Down

0 comments on commit 658cb3f

Please sign in to comment.