WebRTC 스트리밍
웹캠, RTSP 카메라, 비디오 파일 또는 수동 전송 프레임에서 모델 ID나 Workflow를 사용해 WebRTC를 통해 비디오를 Inference 서버로 스트리밍하고 실시간 예측을 받으세요.
pip install "inference-sdk[webrtc]"모델 스트리밍
import cv2
import supervision as sv
from inference_sdk import InferenceHTTPClient
from inference_sdk.webrtc import WebcamSource
# ROBOFLOW_API_KEY를 Roboflow API 키로 바꾸세요
client = InferenceHTTPClient(
api_url="http://localhost:9001",
api_key="ROBOFLOW_API_KEY",
)
session = client.webrtc.stream(
source=WebcamSource(),
model_id="rfdetr-nano",
)
box_annotator = sv.BoxAnnotator()
@session.on_frame
def show(frame, data):
# data는 원시 예측 dict이며, 서버가 반환한 그대로입니다
# (이 프레임에 대해 예측을 사용할 수 없으면 None)
if data is None:
return
detections = sv.Detections.from_inference(data)
annotated = box_annotator.annotate(frame.copy(), detections)
cv2.imshow("Preview", annotated)
if cv2.waitKey(1) & 0xFF == ord("q"):
session.close()
session.run() # 스트림이 끝나거나 session.close()가 호출될 때까지 차단됩니다Workflow 스트리밍
비디오 소스
WebcamSource
RTSPSource
LocalStreamSource
MJPEGSource
VideoFileSource
ManualSource
결과 소비
세션 수명
프레임 수신: on_frame 및 video()
데이터 수신: on_data
오류 처리: on_error
프레임 메타데이터
속성
설명
StreamConfig
필드
기본값
설명
실행 가능한 예제
마지막 업데이트
도움이 되었나요?