Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Distance Measurement Block #731

Merged
merged 18 commits into from
Oct 11, 2024

Conversation

ediardo
Copy link
Contributor

@ediardo ediardo commented Oct 7, 2024

Description

image

image

Measure the distance between two bounding boxes on a 2D plane using a camera positioned perpendicular to the plane. This method requires footage from this specific perspective, along with either a reference object of known dimensions placed in the same plane as the bounding boxes or a pixel-to-centimeter ratio that defines how many pixels correspond to one centimeter.

Key features include:

  • Distance Calculation: Compute the distance or gap between two bounding boxes using their closest edges for measurement.
  • Calibration via Pixel to centimeter & Reference Object:
    • Calibrate the pixel to centimeter ratio by using either a known “pixel-ratio”
    • Use a reference object with known dimensions (width and height) to approximate scale distances.
  • Measurement Outputs: Obtain the distance between bounding boxes in both centimeters and pixels, providing flexibility for various use cases.

Screen Recording 2024-10-07 at 14 50 15

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How has this change been tested, please provide a testcase or example of how you tested the change?

Created 10 unit tests to check various scenario, including different calibration methods, empty required inputs, incorrect value formats, and overlapping bounding boxes.

Docs

N/A

@ediardo ediardo changed the title Feat/measure distance Add Distance Measurement Block Oct 7, 2024
if not reference_bbox_1 or not reference_bbox_2:
raise ValueError(f"Reference class '{object_1_class_name}' or '{object_2_class_name}' not found in predictions.")

if has_overlap(reference_bbox_1, reference_bbox_2) or has_axis_overlap(reference_bbox_1, reference_bbox_2, reference_axis):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this if statement hard to understand - especially the latter part.
The root source of my confusion is the choice to measure distance along single dimension - why not to calculate distance in 2D?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the confusion.

The goal is to measure the distance or gap between the closest edges of two bounding boxes on a 2D plane.

I'm adding an illustration to clarify this further:

image
  • has_overlap: check if bboxes overlap.
  • has_axis_overlap: check if there isn't a vertical or horizontal gap between the bboxes.

@PawelPeczek-Roboflow
Copy link
Collaborator

Also - for future contributions - could you use direct pushes to the repository to make CI run smoothly?

@ediardo
Copy link
Contributor Author

ediardo commented Oct 10, 2024

Hey @PawelPeczek-Roboflow , thanks for reviewing my PR. I will address more requests tomorrow.

@ediardo
Copy link
Contributor Author

ediardo commented Oct 10, 2024

Also - for future contributions - could you use direct pushes to the repository to make CI run smoothly?

Now that I have access, future contributions will be made this way. thanks!

@PawelPeczek-Roboflow
Copy link
Collaborator

@ediardo I have concerns that this block may not be easy to adopt by clients and may produce errors - for instance when model do not provide reference object.

I do understand that the block solves a particular issue for the client, hence I am going to approve it, but in case of any future problems you will be in charge of solving them.

@PawelPeczek-Roboflow PawelPeczek-Roboflow merged commit 7e0773a into roboflow:main Oct 11, 2024
25 of 54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants