From: Alexander Mordvintsev Date: Thu, 9 Jun 2011 08:21:37 +0000 (+0000) Subject: video synth uses cv2.randn for noise -- much faster than np.random.normal X-Git-Tag: submit/tizen/20180620.034203~3^2~7061 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=07a4e52093123c9c3f5f174ccc26ac189ad8052e;p=platform%2Fupstream%2Fopencv.git video synth uses cv2.randn for noise -- much faster than np.random.normal --- diff --git a/samples/python2/video.py b/samples/python2/video.py index 5cbcb91c52..762f01a849 100644 --- a/samples/python2/video.py +++ b/samples/python2/video.py @@ -20,11 +20,13 @@ class VideoSynth(object): def read(self, dst=None): w, h = self.frame_size - buf = np.zeros((h, w, 3), np.uint8) - if self.bg is not None: - buf[:] = self.bg + if self.bg is None: + buf = np.zeros((h, w, 3), np.uint8) + else: + buf = self.bg.copy() 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) return True, buf