#!/usr/bin/env python
# Pyctools - a picture processing algorithm development kit.
# http://github.com/jim-easterbrook/pyctools
# Copyright (C) 2014-22 Pyctools contributors
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see
# <http://www.gnu.org/licenses/>.
__all__ = ['DumpMetadata', 'Stats']
__docformat__ = 'restructuredtext en'
import math
import pprint
import numpy
from pyctools.core.base import Transformer
from pyctools.core.config import ConfigBool
[docs]
class Stats(Transformer):
"""Print information about input video.
Note that the data is only printed out for the first frame
and if it subsequently changes.
"""
def initialise(self):
self.config['rms'] = ConfigBool()
self.config['mean'] = ConfigBool()
self.config['variance'] = ConfigBool()
self.last_result = None
def on_set_config(self):
self.last_result = None
def transform(self, in_frame, out_frame):
self.update_config()
result = {}
data = in_frame.as_numpy(dtype=numpy.float64)
if self.config['rms']:
result['rms'] = list(numpy.sqrt(numpy.mean(
numpy.square(data), axis=(0, 1))))
if self.config['mean']:
result['mean'] = list(numpy.mean(data, axis=(0, 1)))
if self.config['variance']:
result['variance'] = list(numpy.var(data, axis=(0, 1)))
if self.last_result == result:
return True
self.last_result = result
print('Frame %04d' % in_frame.frame_no)
print('==========')
pprint.pprint(result)
return True