Browse Source

Fix `nan`-robust stream FPS (#6198)

Fix for Webcam stop working suddenly (Issue #6197)
modifyDataloader
Glenn Jocher GitHub 2 years ago
parent
commit
9e9219fe17
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions
  1. +3
    -1
      utils/datasets.py

+ 3
- 1
utils/datasets.py View File

@@ -6,6 +6,7 @@ Dataloaders and dataset utils
import glob
import hashlib
import json
import math
import os
import random
import shutil
@@ -308,8 +309,9 @@ class LoadStreams:
assert cap.isOpened(), f'{st}Failed to open {s}'
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
self.fps[i] = max(cap.get(cv2.CAP_PROP_FPS) % 100, 0) or 30.0 # 30 FPS fallback
fps = cap.get(cv2.CAP_PROP_FPS) # warning: may return 0 or nan
self.frames[i] = max(int(cap.get(cv2.CAP_PROP_FRAME_COUNT)), 0) or float('inf') # infinite stream fallback
self.fps[i] = max((fps if math.isfinite(fps) else 0) % 100, 0) or 30 # 30 FPS fallback

_, self.imgs[i] = cap.read() # guarantee first frame
self.threads[i] = Thread(target=self.update, args=([i, cap, s]), daemon=True)

Loading…
Cancel
Save