-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: | ||
""" | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add |
||
|
||
Returns: | ||
Detections: A new Detections object. | ||
|
||
Example: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: | ||
""" | ||
|
There was a problem hiding this comment.
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
tofrom_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.