
%cd /content
!pip install ultralytics
from ultralytics import YOLO
import io ## https://github.com/ultralytics/ultralytics
from urllib import request
det_image_url = "https://i.ibb.co/r41nkjS/000000145569.jpg"
res = request.urlopen(det_image_url).read()
img2 = Image.open(io.BytesIO(res))
img_2 = np.array(img2) ## cv2를 쓰려면 넘파이로 해야함
model = YOLO('yolov8m.pt') ## yolov8m.pt : detection model
results = model.predict(source=det_image_url) ## yolov8은 source가 이미지이던, 넘파이이던, url이던 처리할 수 있게 구성되어 있음 ## predict는 inference ## save=True 하면 저장
## boxing한 사람을 가릴수 있을까?
## boxing한 영역을 가우시안 블러 처리
for r in results:
# print(r.boxes) ## bounding box의 클래스만 추출
box = r.boxes
for b in box:
cls, x_min, y_min, x_max, y_max = int(b.cls.item()), int(b.xyxy[0][0].item()), int(b.xyxy[0][1].item()), int(b.xyxy[0][2].item()), int(b.xyxy[0][3].item())
# print(cls, x_min, y_min, x_max, y_max)
if cls == 0:
img_2 = cv2.rectangle(img_2, (x_min, y_min), (x_max, y_max), (255,0,0), 3)
plt.imshow(img_2)
plt.show()
#결과 :
