From 65d74480954b32fc51e609414b2f5a03bad3a0d9 Mon Sep 17 00:00:00 2001 From: awkrail Date: Thu, 6 Feb 2025 22:17:03 +0900 Subject: [PATCH] repace _compute_frame_average with numpy.mean --- scenedetect/detectors/threshold_detector.py | 28 +-------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/scenedetect/detectors/threshold_detector.py b/scenedetect/detectors/threshold_detector.py index b93987b2..4121d9c8 100644 --- a/scenedetect/detectors/threshold_detector.py +++ b/scenedetect/detectors/threshold_detector.py @@ -25,32 +25,6 @@ logger = getLogger("pyscenedetect") -## -## ThresholdDetector Helper Functions -## - - -def _compute_frame_average(frame: numpy.ndarray) -> float: - """Computes the average pixel value/intensity for all pixels in a frame. - - The value is computed by adding up the 8-bit R, G, and B values for - each pixel, and dividing by the number of pixels multiplied by 3. - - Arguments: - frame: Frame representing the RGB pixels to average. - - Returns: - Average pixel intensity across all 3 channels of `frame` - """ - num_pixel_values = float(frame.shape[0] * frame.shape[1] * frame.shape[2]) - avg_pixel_value = numpy.sum(frame[:, :, :]) / num_pixel_values - return avg_pixel_value - - -## -## ThresholdDetector Class Implementation -## - class ThresholdDetector(SceneDetector): """Detects fast cuts/slow fades in from and out to a given threshold level. @@ -150,7 +124,7 @@ def process_frame(self, frame_num: int, frame_img: numpy.ndarray) -> ty.List[int ): frame_avg = self.stats_manager.get_metrics(frame_num, self._metric_keys)[0] else: - frame_avg = _compute_frame_average(frame_img) + frame_avg = numpy.mean(frame_img) if self.stats_manager is not None: self.stats_manager.set_metrics(frame_num, {self._metric_keys[0]: frame_avg})