Commit 07a4e520 authored by Alexander Mordvintsev's avatar Alexander Mordvintsev

video synth uses cv2.randn for noise -- much faster than np.random.normal

parent 2e7e6ae8
...@@ -20,11 +20,13 @@ class VideoSynth(object): ...@@ -20,11 +20,13 @@ class VideoSynth(object):
def read(self, dst=None): def read(self, dst=None):
w, h = self.frame_size w, h = self.frame_size
buf = np.zeros((h, w, 3), np.uint8) if self.bg is None:
if self.bg is not None: buf = np.zeros((h, w, 3), np.uint8)
buf[:] = self.bg else:
buf = self.bg.copy()
if self.noise > 0.0: if self.noise > 0.0:
noise = np.random.normal(scale = 255*self.noise, size=(h, w, 3)) noise = np.zeros((h, w, 3), np.int8)
cv2.randn(noise, np.zeros(3), np.ones(3)*255*self.noise)
buf = cv2.add(buf, noise, dtype=cv2.CV_8UC3) buf = cv2.add(buf, noise, dtype=cv2.CV_8UC3)
return True, buf return True, buf
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment