Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions apps/99_streamlit_examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ Access to http://localhost:8501 and select the sample you want to run from the s

![Pose estimation](../../docs/images/99_streamlit_examples.poseestimation.png)

#### 12. Video processing

![Video processing](../../docs/images/99_streamlit_examples.videoprocessing.png)

## References

- [🎈 Streamlit + LLM Examples App](https://github.com/streamlit/llm-examples)
Expand Down
81 changes: 81 additions & 0 deletions apps/99_streamlit_examples/pages/12_Video_processing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import cv2
import streamlit as st
from dotenv import load_dotenv
from ultralytics import YOLO

load_dotenv()


class Processor:
def __init__(self, model_name):
self.model = YOLO(model_name)

def process(self, frame):
results = self.model(
frame,
conf=0.5,
classes=[0],
)
output_img = results[0].plot(
labels=True,
conf=True,
)
return cv2.cvtColor(
src=output_img,
code=cv2.COLOR_BGR2RGB,
)


with st.sidebar:
model_name = st.selectbox(
label="Select a model",
options=[
"yolov8n.pt",
"yolov9c.pt",
"yolov10n.pt",
# https://docs.ultralytics.com/models/yolov8/#supported-tasks-and-modes
],
key="model_name",
index=0,
)
device = st.text_input(
label="input your video/camera device",
value="0",
)
if device.isnumeric():
# e.g. "0" -> 0
device = int(device)

st.title("Video processing")

start_button = st.button("Start")
stop = st.button("Stop")

image_loc = st.empty()
processor = Processor(
model_name=model_name,
)

if start_button:
capture = cv2.VideoCapture(device)

while capture.isOpened:
ret, frame = capture.read()

if not ret:
st.error("Failed to capture image")
continue

processed_frame = processor.process(
frame=frame,
)

image_loc.image(
image=processed_frame,
use_column_width=True,
)

if stop:
break

capture.release()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 38 additions & 25 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ mediapipe = "^0.10.14"
azure-ai-documentintelligence = "^1.0.0b3"
azure-storage-blob = "^12.22.0"
requests = "^2.32.3"
opencv-python-headless = "^4.10.0.84"

[tool.poetry.group.dev.dependencies]
pre-commit = "^3.8.0"
Expand Down
6 changes: 5 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ langchain-openai==0.1.20
langchain-community==0.2.11
azure-search-documents==11.5.1
azure-identity==1.17.1
azure-ai-documentintelligence==1.0.0b3
azure-storage-blob==12.22.0
requests==2.32.3

# To run 99_streamlit_examples/pages/10_Object_Detection.py
# ultralytics==8.2.77

# To run 99_streamlit_examples/pages/11_Pose_Estimation.py
# mediapipe==0.10.14

azure-ai-documentintelligence==1.0.0b3
# To run 99_streamlit_examples/pages/12_Video_processing.py
# opencv-python-headless==4.10.0.84
1 change: 1 addition & 0 deletions tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def test_smoke():
# fixme: disabled due to flaky test
# "apps/99_streamlit_examples/pages/10_Object_detection.py",
# "apps/99_streamlit_examples/pages/11_Pose_estimation.py",
"apps/99_streamlit_examples/pages/12_Video_processing.py",
]
for path in paths:
at = AppTest(
Expand Down