video synth uses cv2.randn for noise -- much faster than np.random.normal
authorAlexander Mordvintsev <no@email>
Thu, 9 Jun 2011 08:21:37 +0000 (08:21 +0000)
committerAlexander Mordvintsev <no@email>
Thu, 9 Jun 2011 08:21:37 +0000 (08:21 +0000)
samples/python2/video.py

index 5cbcb91..762f01a 100644 (file)
@@ -20,11 +20,13 @@ class VideoSynth(object):
     def read(self, dst=None):\r
         w, h = self.frame_size\r
 \r
-        buf = np.zeros((h, w, 3), np.uint8)\r
-        if self.bg is not None:\r
-            buf[:] = self.bg\r
+        if self.bg is None:\r
+            buf = np.zeros((h, w, 3), np.uint8)\r
+        else:\r
+            buf = self.bg.copy()\r
         if self.noise > 0.0:\r
-            noise = np.random.normal(scale = 255*self.noise, size=(h, w, 3))\r
+            noise = np.zeros((h, w, 3), np.int8)\r
+            cv2.randn(noise, np.zeros(3), np.ones(3)*255*self.noise)\r
             buf = cv2.add(buf, noise, dtype=cv2.CV_8UC3)\r
         return True, buf\r
 \r