Skip to content

Commit

Permalink
Detect gray frames from OBS-Camera
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed Oct 25, 2022
1 parent e05f248 commit 1e8a535
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/AutoSplit.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ def __check_fps(self):
while count < CHECK_FPS_ITERATIONS:
capture, is_old_image = self.__get_capture_for_comparison()
_ = image.compare_with_capture(self, capture)
# TODO: If is_old_image=true is always returned, this becomes an infinite loop
if not is_old_image:
count += 1

Expand Down
22 changes: 21 additions & 1 deletion src/capture_method/VideoCaptureDeviceCaptureMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@
if TYPE_CHECKING:
from AutoSplit import AutoSplit

OBS_CAMERA_BLANK = [127, 129, 128]


def is_blank(image: cv2.Mat):
# Running np.all on the entire array is extremely slow.
# Because it always converts the entire array to boolean first
# So instead we loop manually to stop early.
for row in image:
for pixel in row:
if all(pixel != OBS_CAMERA_BLANK):
return False
return True


class VideoCaptureDeviceCaptureMethod(CaptureMethodBase):
capture_device: cv2.VideoCapture
Expand All @@ -36,7 +49,14 @@ def __read_loop(self, autosplit: AutoSplit):
# STS_ERROR most likely means the camera is occupied
result = False
image = None
self.last_captured_frame = image if result else None
if not result:
image = None

# Blank frame. Reuse the previous one.
if image is not None and is_blank(image):
continue

self.last_captured_frame = image
self.is_old_image = False
except Exception as exception: # pylint: disable=broad-except # We really want to catch everything here
error = exception
Expand Down

0 comments on commit 1e8a535

Please sign in to comment.