Skip to content

Commit 1e8a535

Browse files
committed
Detect gray frames from OBS-Camera
1 parent e05f248 commit 1e8a535

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/AutoSplit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ def __check_fps(self):
408408
while count < CHECK_FPS_ITERATIONS:
409409
capture, is_old_image = self.__get_capture_for_comparison()
410410
_ = image.compare_with_capture(self, capture)
411+
# TODO: If is_old_image=true is always returned, this becomes an infinite loop
411412
if not is_old_image:
412413
count += 1
413414

src/capture_method/VideoCaptureDeviceCaptureMethod.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@
1313
if TYPE_CHECKING:
1414
from AutoSplit import AutoSplit
1515

16+
OBS_CAMERA_BLANK = [127, 129, 128]
17+
18+
19+
def is_blank(image: cv2.Mat):
20+
# Running np.all on the entire array is extremely slow.
21+
# Because it always converts the entire array to boolean first
22+
# So instead we loop manually to stop early.
23+
for row in image:
24+
for pixel in row:
25+
if all(pixel != OBS_CAMERA_BLANK):
26+
return False
27+
return True
28+
1629

1730
class VideoCaptureDeviceCaptureMethod(CaptureMethodBase):
1831
capture_device: cv2.VideoCapture
@@ -36,7 +49,14 @@ def __read_loop(self, autosplit: AutoSplit):
3649
# STS_ERROR most likely means the camera is occupied
3750
result = False
3851
image = None
39-
self.last_captured_frame = image if result else None
52+
if not result:
53+
image = None
54+
55+
# Blank frame. Reuse the previous one.
56+
if image is not None and is_blank(image):
57+
continue
58+
59+
self.last_captured_frame = image
4060
self.is_old_image = False
4161
except Exception as exception: # pylint: disable=broad-except # We really want to catch everything here
4262
error = exception

0 commit comments

Comments
 (0)