아래 명령어를 통해 ultralytics
를 설치합니다.
pip install ultralytics
튜토리얼을 위한 스크립트를 작성합니다.
mkdir ~/yolov8_tutorial
cd ~/yolov8_tutorial
touch tutorial.py
from ultralytics import YOLO
import cv2
# Load a model
model = YOLO("yolov8n.pt") # COCO dataset으로 pretrained된 model을 불러옴
# ultralytics 패키지 내에 test용으로 이미 존재해 있는 버스 이미지를 이용해 object detection 수행
sample_img = "<https://ultralytics.com/images/bus.jpg>"
# sample_img = "test.jpg"
results = model(sample_img)
print(results[0]) # 이미지에 대한 정보 출력
print(results[0].boxes) # 좌상단 좌표, 우하단 좌표, confidence score, class id
# Display
plots = results[0].plot()
cv2.imshow("plot", plots)
cv2.waitKey(0)
cv2.destroyAllWindows()
스크립트를 실행하고 결과를 확인합니다.
python3 ~/yolov8_tutorial/tutorial.py
출력 결과