D-Jobs 아카데미 2기 파이썬 / 인공지능 강의 자료
kanghoyong / d-jobs_24_02 Goto Github PK
View Code? Open in Web Editor NEWD-Jobs 아카데미 2기 파이썬 / 인공지능 강의 자료
D-Jobs 아카데미 2기 파이썬 / 인공지능 강의 자료
from collections import defaultdict
import cv2
import numpy as np
from ultralytics import YOLO
def webcam_play_run(cap, model, track_history):
# Loop through the video frames
while cap.isOpened():
# Read a frame from the webcam
success, frame = cap.read()
if success:
result = model.track(frame, persist=True, conf=0.5, iou=0.5)
# Check if any objects were detected
if result[0].boxes.cls.numel() > 0:
# Get the boxes and track IDs
cls = result[0].boxes.cls.int().cpu().item()
boxes = result[0].boxes.xywh.cpu()
track_ids = result[0].boxes.id.int().cpu().tolist()
name = result[0].names[cls]
# Visualize the results on the frame
annotated_frame = result[0].plot()
# Plot the tracks
for box, track_id in zip(boxes, track_ids):
x, y, w, h = box
track = track_history[track_id]
track.append((float(x), float(y))) # x, y center point
if len(track) > 30:
track.pop(0)
# Draw the tracking lines
points = np.array(track).astype(np.int32).reshape((-1, 1, 2))
print("cls number ", cls, "class name", name)
cv2.polylines(annotated_frame, [points], isClosed=False, color=(230, 230, 230), thickness=10)
# Display the annotated frame
cv2.imshow("YOLOv8 Tracking .... ", annotated_frame)
else:
# If no objects are detected, just display the frame
cv2.imshow("YOLOv8 Tracking .... ", frame)
# Break the loop if 'q' is pressed
if cv2.waitKey(1) & 0xFF == ord('q'):
break
else:
break
if name == "main":
# Load the YOLOv8 model
model = YOLO("yolov8n.pt")
cap = cv2.VideoCapture(0) # webcam device : 0
# Store the track history
track_history = defaultdict(lambda: [])
webcam_play_run(cap=cap, model=model, track_history=track_history)
오류 내용 (데이터 다운로드 후 체크섬에 의해서 데이터 체크 하는 중에 문제 발생)
datasets.utils.info_utils.NonMatchingSplitsSizesError: [{'expected': SplitInfo(name='train', num_bytes=8467781,
num_examples=51094, shard_lengths=None, dataset_name=None), 'recorded': SplitInfo(name='train', num_bytes=21073497,
num_examples=64727, shard_lengths=None, dataset_name='superb')}]
해결 방법 : dataset = load_dataset("superb", "ks", ignore_verifications=True)
--> ignore_verifications = True 설정 : 체크섬, 크기 분할 확인을 무시
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.