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

'from_depthai' conversion function added #909

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions supervision/detection/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,57 @@ def from_paddledet(cls, paddledet_result) -> Detections:
class_id=paddledet_result["bbox"][:, 0].astype(int),
)

@classmethod
def from_depthai(cls, depthai_results) -> Detections:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we rename it from from_depthai to from_luxonis? I think the Luxonis brand is much more recognizable than DepthAI. To be honest, I did not know what DepthAI is, but I'm absolutely familiar with Luxonis.

"""
Creates a Detections instance from a
[DepthAI](https://https://github.com/luxonis/depthai) inference result.

Args:
depthai_results (depthai/resources/nn):
The output Detections instance from DepthAI
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add . at the end of the sentence.


Returns:
Detections: A new Detections object.

Example:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we make this example a bit simpler? Maybe show how it works for a single frame. For sure, drop tracker.

```python
import depthai as dai
import supervision as sv

tracker = sv.ByteTrack()

with dai.Device(pipeline) as device:
qDet = device.getOutputQueue(name="nn", maxSize=4, blocking=False)
while True:
inDet = qDet.get()
detections = inDet.detections
for detection in detections:
results = sv.Detections.from_depthai(detection)
tracks = tracker.update_with_detections(results)
```
# For device and nn setup, refer:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd move this to the very top of the docstring.

[RGB & TinyYOLO](https://docs.luxonis.com/projects/api/en/latest/samples/SpatialDetection/spatial_tiny_yolo/)
"""
depthai_detections_predictions = np.array(
[
[
depthai_results.xmin,
depthai_results.ymin,
depthai_results.xmax,
depthai_results.ymax,
depthai_results.confidence,
depthai_results.label,
]
]
)

return cls(
xyxy=depthai_detections_predictions[:, :4],
confidence=depthai_detections_predictions[:, 4],
class_id=depthai_detections_predictions[:, 5].astype(int),
)

@classmethod
def empty(cls) -> Detections:
"""
Expand Down