src/platform/python/cinema/__init__.py (view raw)
1from PIL.ImageChops import difference
2from PIL.ImageOps import autocontrast
3from PIL.Image import open as PIOpen
4
5class VideoFrame(object):
6 def __init__(self, pilImage):
7 self.image = pilImage.convert('RGB')
8
9 @staticmethod
10 def diff(a, b):
11 diff = difference(a.image, b.image)
12 diffNormalized = autocontrast(diff)
13 return (VideoFrame(diff), VideoFrame(diffNormalized))
14
15 @staticmethod
16 def load(path):
17 with open(path, 'rb') as f:
18 image = PIOpen(f)
19 image.load()
20 return VideoFrame(image)
21
22 def save(self, path):
23 return self.image.save(path)