inpaint.py sample added
authorAlexander Mordvintsev <no@email>
Sat, 2 Jul 2011 07:13:31 +0000 (07:13 +0000)
committerAlexander Mordvintsev <no@email>
Sat, 2 Jul 2011 07:13:31 +0000 (07:13 +0000)
samples/python2/inpaint.py [new file with mode: 0644]
samples/python2/watershed.py

diff --git a/samples/python2/inpaint.py b/samples/python2/inpaint.py
new file mode 100644 (file)
index 0000000..ddd8abc
--- /dev/null
@@ -0,0 +1,35 @@
+import numpy as np\r
+import cv2\r
+from common import Sketcher\r
+\r
+help_message = '''USAGE: inpaint.py [<image>]\r
+\r
+Keys:\r
+  SPACE - update inpaint\r
+  r     - restore image\r
+  ESC   - exit\r
+'''\r
+\r
+if __name__ == '__main__':\r
+    import sys\r
+    try: fn = sys.argv[1]\r
+    except: fn = '../cpp/fruits.jpg'\r
+    print help_message\r
+\r
+    img = cv2.imread(fn)\r
+    img_mark = img.copy()\r
+    mark = np.zeros(img.shape[:2], np.uint8)\r
+    sketch = Sketcher('img', [img_mark, mark], lambda : ((255, 255, 255), 255))\r
+\r
+    while True:\r
+        ch = cv2.waitKey()\r
+        if ch == 27:\r
+            break\r
+        if ch == ord(' '):\r
+            res = cv2.inpaint(img_mark, mark, 3, cv2.INPAINT_TELEA)\r
+            cv2.imshow('inpaint', res)\r
+        if ch == ord('r'):\r
+            img_mark[:] = img\r
+            mark[:] = 0\r
+            sketch.show()\r
+            \r
index 6f72d1c..f35248a 100644 (file)
@@ -36,7 +36,7 @@ class App:
 \r
     def run(self):\r
         while True:\r
-            ch = cv2.waitKey(10)\r
+            ch = cv2.waitKey(50)\r
             if ch == 27:\r
                 break\r
             if ch >= ord('1') and ch <= ord('7'):\r
@@ -52,7 +52,6 @@ class App:
                 self.markers[:] = 0\r
                 self.markers_vis[:] = self.img\r
                 self.sketch.show()\r
-                cv2.destroyWindow('watershed')\r
 \r
 \r
 if __name__ == '__main__':\r