|
11 | 11 | from types import FrameType
|
12 | 12 | from typing import Dict, Optional, Tuple
|
13 | 13 |
|
| 14 | +import cv2 as cv |
14 | 15 | from pydantic import ValidationError
|
15 | 16 |
|
16 | 17 | from inference.core import logger
|
@@ -275,11 +276,37 @@ def start_loop(loop: asyncio.AbstractEventLoop):
|
275 | 276 | def webrtc_sink(
|
276 | 277 | prediction: Dict[str, WorkflowImageData], video_frame: VideoFrame
|
277 | 278 | ) -> None:
|
278 |
| - if parsed_payload.stream_output[0] not in prediction: |
279 |
| - from_inference_queue.sync_put(video_frame.image) |
280 |
| - return |
281 |
| - if prediction[parsed_payload.stream_output[0]] is None: |
282 |
| - from_inference_queue.sync_put(video_frame.image) |
| 279 | + errors = [] |
| 280 | + if not any( |
| 281 | + isinstance(v, WorkflowImageData) for v in prediction.values() |
| 282 | + ): |
| 283 | + errors.append("Visualisation blocks were not executed") |
| 284 | + errors.append("or workflow was not configured to output visuals.") |
| 285 | + errors.append( |
| 286 | + "Please try to adjust the scene so models detect objects" |
| 287 | + ) |
| 288 | + errors.append("or stop preview, update workflow and try again.") |
| 289 | + elif parsed_payload.stream_output[0] not in prediction: |
| 290 | + if not parsed_payload.stream_output[0]: |
| 291 | + errors.append("No stream output selected to show") |
| 292 | + else: |
| 293 | + errors.append( |
| 294 | + f"{parsed_payload.stream_output[0]} not available in results" |
| 295 | + ) |
| 296 | + errors.append("Please stop, update outputs and try again") |
| 297 | + if errors: |
| 298 | + result_frame = video_frame.image.copy() |
| 299 | + for row, error in enumerate(errors): |
| 300 | + result_frame = cv.putText( |
| 301 | + result_frame, |
| 302 | + error, |
| 303 | + (10, 20 + 30 * row), |
| 304 | + cv.FONT_HERSHEY_SIMPLEX, |
| 305 | + 0.7, |
| 306 | + (0, 255, 0), |
| 307 | + 2, |
| 308 | + ) |
| 309 | + from_inference_queue.sync_put(result_frame) |
283 | 310 | return
|
284 | 311 | from_inference_queue.sync_put(
|
285 | 312 | prediction[parsed_payload.stream_output[0]].numpy_image
|
|
0 commit comments