-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #652 from roboflow/feature/e2e_tests_for_describe_…
…workflow_and_examples E2E tests for describe workflow and examples
- Loading branch information
Showing
7 changed files
with
327 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
development/stream_interface/objects_passing_line_demo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import os | ||
from threading import Thread | ||
from typing import List, Optional, Union | ||
|
||
import cv2 | ||
import supervision as sv | ||
|
||
from inference import InferencePipeline | ||
from inference.core.interfaces.camera.entities import VideoFrame | ||
from inference.core.interfaces.stream.watchdog import PipelineWatchDog, BasePipelineWatchDog | ||
from inference.core.utils.drawing import create_tiles | ||
|
||
STOP = False | ||
|
||
TIME_IN_ZONE_WORKFLOW = { | ||
"version": "1.0", | ||
"inputs": [ | ||
{"type": "WorkflowImage", "name": "image"}, | ||
{"type": "WorkflowVideoMetadata", "name": "video_metadata"}, | ||
{"type": "WorkflowParameter", "name": "line"}, | ||
], | ||
"steps": [ | ||
{ | ||
"type": "ObjectDetectionModel", | ||
"name": "people_detector", | ||
"image": "$inputs.image", | ||
"model_id": "yolov8n-640", | ||
"confidence": 0.6, | ||
}, | ||
{ | ||
"type": "roboflow_core/byte_tracker@v1", | ||
"name": "byte_tracker", | ||
"detections": "$steps.people_detector.predictions", | ||
"metadata": "$inputs.video_metadata" | ||
}, | ||
{ | ||
"type": "roboflow_core/line_counter@v1", | ||
"name": "line_counter", | ||
"detections": f"$steps.byte_tracker.tracked_detections", | ||
"metadata": "$inputs.video_metadata", | ||
"line_segment": "$inputs.line", | ||
"image": "$inputs.image", | ||
}, | ||
{ | ||
"type": "roboflow_core/label_visualization@v1", | ||
"name": "label_visualization", | ||
"image": "$inputs.image", | ||
"predictions": "$steps.byte_tracker.tracked_detections", | ||
}, | ||
{ | ||
"type": "roboflow_core/bounding_box_visualization@v1", | ||
"name": "bbox_visualization", | ||
"image": "$steps.label_visualization.image", | ||
"predictions": "$steps.byte_tracker.tracked_detections", | ||
}, | ||
{ | ||
"type": "roboflow_core/line_counter_visualization@v1", | ||
"name": "zone_visualization", | ||
"image": "$steps.bbox_visualization.image", | ||
"zone": "$inputs.line", | ||
"count_in": "$steps.line_counter.count_in", | ||
"count_out": "$steps.line_counter.count_out" | ||
} | ||
], | ||
"outputs": [ | ||
{"type": "JsonField", "name": "label_visualization", "selector": "$steps.zone_visualization.image"}, | ||
], | ||
} | ||
|
||
|
||
def main() -> None: | ||
global STOP | ||
watchdog = BasePipelineWatchDog() | ||
pipeline = InferencePipeline.init_with_workflow( | ||
video_reference=os.environ["VIDEO_REFERENCE"], | ||
workflow_specification=TIME_IN_ZONE_WORKFLOW, | ||
watchdog=watchdog, | ||
on_prediction=workflows_sink, | ||
workflows_parameters={ | ||
"line": [[128, 512], [1900, 512]], | ||
} | ||
) | ||
control_thread = Thread(target=command_thread, args=(pipeline, watchdog)) | ||
control_thread.start() | ||
pipeline.start() | ||
STOP = True | ||
pipeline.join() | ||
|
||
|
||
def command_thread(pipeline: InferencePipeline, watchdog: PipelineWatchDog) -> None: | ||
global STOP | ||
while not STOP: | ||
key = input() | ||
if key == "i": | ||
print(watchdog.get_report()) | ||
if key == "t": | ||
pipeline.terminate() | ||
STOP = True | ||
elif key == "p": | ||
pipeline.pause_stream() | ||
elif key == "m": | ||
pipeline.mute_stream() | ||
elif key == "r": | ||
pipeline.resume_stream() | ||
|
||
|
||
def workflows_sink( | ||
predictions: Union[Optional[dict], List[Optional[dict]]], | ||
video_frames: Union[Optional[VideoFrame], List[Optional[VideoFrame]]], | ||
) -> None: | ||
images_to_show = [] | ||
if not isinstance(predictions, list): | ||
predictions = [predictions] | ||
video_frames = [video_frames] | ||
for prediction, frame in zip(predictions, video_frames): | ||
if prediction is None or frame is None: | ||
continue | ||
images_to_show.append(prediction["label_visualization"].numpy_image) | ||
tiles = create_tiles(images=images_to_show) | ||
cv2.imshow(f"Predictions", tiles) | ||
cv2.waitKey(1) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.