yolo8 & python 3.10 이용한 객체 인식 #6 사람만 찾아서 바운딩 박스 컬러 변경
import cv2
from ultralytics import YOLO
model = YOLO('yolov8x.pt')
webcam = cv2.VideoCapture(0)
blue_color = (255,0,0)
if not webcam.isOpened():
print("Could not open webcam")
exit()
while webcam.isOpened():
status, frame = webcam.read()
if status:
results = model.predict(classes=0, device=0, conf=0.5, source=frame)
for result in results:
annotated_frame = result.plot(line_width=2, labels=False, boxes=False)
boxes = result.boxes
if boxes :
for box in boxes :
x1 = int(box.xyxy[0,0])
y1 = int(box.xyxy[0,1])
x2 = int(box.xyxy[0,2])
y2 = int(box.xyxy[0,3])
cv2.rectangle(annotated_frame, (x1,y1), (x2,y2), blue_color, 3 )
cv2.imshow("cam", annotated_frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
webcam.release()
cv2.destroyAllWindows()