Skip to content

Optimize blank OBS-Camera frames #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions src/capture_method/VideoCaptureDeviceCaptureMethod.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import TYPE_CHECKING

import cv2
import numpy as np
from pygrabber import dshow_graph

from capture_method.CaptureMethodBase import CaptureMethodBase
Expand All @@ -13,26 +14,22 @@
if TYPE_CHECKING:
from AutoSplit import AutoSplit

OBS_CAMERA_BLANK = [127, 129, 128]
OBS_CAMERA_BLANK_PIXEL = [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
# Running np.all on the entire array or looping manually through the
# entire array is extremely slow when we can't stop early.
# Instead we check for a few key pixels, in this case, corners
return np.all(image[::image.shape[0] - 1, ::image.shape[1] - 1] == OBS_CAMERA_BLANK_PIXEL)


class VideoCaptureDeviceCaptureMethod(CaptureMethodBase):
capture_device: cv2.VideoCapture
capture_thread: Thread | None
stop_thread: Event
last_captured_frame: cv2.Mat | None = None
is_old_image = False
stop_thread = Event()

def __read_loop(self, autosplit: AutoSplit):
try:
Expand Down