환경 - python 3.11.3
base로 깔려있는 버전은 3.10 버전이었는데 가상환경 만들어줬어요.
저는 conda를 사용했기 때문에 콘다 기준임당.
conda create -n yolov8 python=3.11
conda activate yolov8
pip install opencv-python
pip install ultralytics
import cv2
from ultralytics import YOLO
# Load the YOLOv8 model
model = YOLO('yolov8n.pt')
# Open the video file
video_path = "C:/Users/(내이름)/Downloads/mountain_-_34779 (720p).mp4"
cap = cv2.VideoCapture(video_path)
# Loop through the video frames
while cap.isOpened():
# Read a frame from the video
success, frame = cap.read()
if success:
# Run YOLOv8 inference on the frame
results = model(frame)
# Visualize the results on the frame
annotated_frame = results[0].plot()
# Display the annotated frame
cv2.imshow("YOLOv8 Inference", annotated_frame)
# Break the loop if 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord("q"):
break
else:
# Break the loop if the end of the video is reached
break
# Release the video capture object and close the display window
cap.release()
cv2.destroyAllWindows()

0: 384x640 16 persons, 54.9ms
Speed: 5.0ms preprocess, 54.9ms inference, 1.0ms postprocess per image at shape (1, 3, 640, 640)

사람도 잘하구 사물도 잘해여 동물도 잘 했음!
애초에 yolov8이 coco dataset으로 학습된 가중치를 사용하는거라 코코셋에 있는 것들이라면 다 검출 잘 할 겁니다잉
아래 블로그에서 참조 했습니다! 감사합니다😊
https://webnautes.tistory.com/1821
https://docs.ultralytics.com/modes/predict/#streaming-source-for-loop