Merge branch 'master' of git.a2s.su:iiiypuk/snipplets.dev
This commit is contained in:
commit
f8ef8a3381
|
@ -10,11 +10,18 @@ model = YOLO('yolov8m.pt')
|
||||||
video_path = 'run.mp4'
|
video_path = 'run.mp4'
|
||||||
cap = cv2.VideoCapture(video_path)
|
cap = cv2.VideoCapture(video_path)
|
||||||
|
|
||||||
|
fps = 0
|
||||||
|
prev_frame_time = 0
|
||||||
|
new_frame_time = 0
|
||||||
|
|
||||||
# Loop through the video frames
|
# Loop through the video frames
|
||||||
while cap.isOpened():
|
while cap.isOpened():
|
||||||
# Read a frame from the video
|
# Read a frame from the video
|
||||||
success, frame = cap.read()
|
success, frame = cap.read()
|
||||||
|
|
||||||
|
# Set current frame time
|
||||||
|
new_frame_time = time.time()
|
||||||
|
|
||||||
if success:
|
if success:
|
||||||
# Run YOLOv8 inference on the frame
|
# Run YOLOv8 inference on the frame
|
||||||
results = model(frame)
|
results = model(frame)
|
||||||
|
@ -22,6 +29,10 @@ while cap.isOpened():
|
||||||
# Visualize the results on the frame
|
# Visualize the results on the frame
|
||||||
annotated_frame = results[0].plot()
|
annotated_frame = results[0].plot()
|
||||||
|
|
||||||
|
# Calculate FPS
|
||||||
|
fps = int(1 / (new_frame_time - prev_frame_time))
|
||||||
|
prev_frame_time = new_frame_time
|
||||||
|
|
||||||
# Display the annotated frame
|
# Display the annotated frame
|
||||||
cv2.imshow('YOLOv8 Inference', annotated_frame)
|
cv2.imshow('YOLOv8 Inference', annotated_frame)
|
||||||
|
|
||||||
|
@ -32,6 +43,8 @@ while cap.isOpened():
|
||||||
# Break the loop if the end of the video is reached
|
# Break the loop if the end of the video is reached
|
||||||
break
|
break
|
||||||
|
|
||||||
|
print(fps)
|
||||||
|
|
||||||
# Release the video capture object and close the display window
|
# Release the video capture object and close the display window
|
||||||
cap.release()
|
cap.release()
|
||||||
cv2.destroyAllWindows()
|
cv2.destroyAllWindows()
|
||||||
|
|
Loading…
Reference in New Issue