asif00/Realtime_Image_Segmentation_Using_YOLO_and_OpenCV
0
1import gradio as gr2import cv2 as cv3from ultralytics import YOLO4 5# Load the YOLO model6model = YOLO('yolov8n-seg.pt')7 8def resize_frame(frame, width=1280):9 height, width = frame.shape[:2]10 new_height = int(height * width / float(width))11 return cv.resize(frame, (width, new_height))12 13def process_frame(frame):14 frame = resize_frame(frame)15 results = model(frame)16 segments = results[0].plot()17 return segments18 19frame = gr.components.Video(label="Webcam Feed")20 21iface = gr.Interface(22 fn=process_frame,23 inputs=[frame],24 outputs=[gr.components.Image()],25 live=True,26 title="YOLO Image Segmentation",27 description="This application uses the YOLO model to perform image segmentation on a webcam feed.",28)29 30iface.launch()31 