import streamlit as st
import cv2
from ultralytics import YOLO
import time
Load the YOLOv8 model
model = YOLO(ābest.ptā)
def perform_inference(frame):
results = model.predict(frame, conf=0.25, iou=0.1, half=True, retina_masks=True, agnostic_nms=True)
annotated_frame = results[0].plot()
return annotated_frame
def main():
st.title(āReal-Time Hand Detectionā)
cap = cv2.VideoCapture(0)
if not cap.isOpened():
st.error("Cannot access the camera.")
return
stframe = st.empty()
st_info = st.empty()
while cap.isOpened():
ret, frame = cap.read()
if ret:
#frame = cv2.resize(frame, (480,640))
start_time = time.time()
annotated_frame = perform_inference(frame)
stframe.image(annotated_frame, channels='BGR', use_column_width=True)
end_time = time.time()
inference_time = end_time - start_time
#st_info.text("Inference Time: {:.2f} ms".format(inference_time))
st_info.markdown(
f'<div style="background-color: #F1C40F; color: #000033; padding: 10px; font-size: 22px;">Inference Time: {inference_time:.2f} ms</div>',
unsafe_allow_html=True
)
if name == āmainā:
main()
i have deployed app but it showing me error of āCannot access the camera.ā from cap is not opening. I have tried some ways but still could not get the solution.
it is working good on local host but not working on deployed app,
please someone help me in that.
thank you very much in advance