Skip to content

Commit

Permalink
Merge pull request #987 from roboflow/feat/extend-size-measurement-to…
Browse files Browse the repository at this point in the history
…-produce-longer-shorter

Add 'longer' and 'shorter' keys to the output of size_measurement block
  • Loading branch information
grzegorz-roboflow authored Jan 29, 2025
2 parents 29de265 + ec6e0ea commit 21f627e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,14 @@ def run(
if obj_w_pixels > 0 and obj_h_pixels > 0:
obj_w_actual = obj_w_pixels * width_scale
obj_h_actual = obj_h_pixels * height_scale
dimensions.append({"width": obj_w_actual, "height": obj_h_actual})
dimensions.append(
{
"width": obj_w_actual,
"height": obj_h_actual,
"longer": max(obj_w_actual, obj_h_actual),
"shorter": min(obj_w_actual, obj_h_actual),
}
)
else:
dimensions.append(None)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ def test_size_measurement_block():
result = block.run(reference_predictions, object_predictions, reference_dimensions)

# then
expected_dimensions = [{"width": 5.0, "height": 5.0}, {"width": 5.0, "height": 5.0}]
expected_dimensions = [
{"width": 5.0, "height": 5.0, "longer": 5.0, "shorter": 5.0},
{"width": 5.0, "height": 5.0, "longer": 5.0, "shorter": 5.0},
]
assert result == {
OUTPUT_KEY: expected_dimensions
}, f"Expected {expected_dimensions}, but got {result}"
Expand Down Expand Up @@ -59,7 +62,10 @@ def test_size_measurement_block_with_mask():
result = block.run(reference_predictions, object_predictions, reference_dimensions)

# then
expected_dimensions = [{"width": 5.0, "height": 5.0}, {"width": 5.0, "height": 5.0}]
expected_dimensions = [
{"width": 5.0, "height": 5.0, "longer": 5.0, "shorter": 5.0},
{"width": 5.0, "height": 5.0, "longer": 5.0, "shorter": 5.0},
]
assert result == {
OUTPUT_KEY: expected_dimensions
}, f"Expected {expected_dimensions}, but got {result}"
Expand Down

0 comments on commit 21f627e

Please sign in to comment.