From afad87b5f2a1eebcf1f93be2c72b874851208bed Mon Sep 17 00:00:00 2001 From: Alexander Mordvintsev Date: Sat, 2 Jul 2011 07:13:31 +0000 Subject: [PATCH] inpaint.py sample added --- samples/python2/inpaint.py | 35 +++++++++++++++++++++++++++++++++++ samples/python2/watershed.py | 3 +-- 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 samples/python2/inpaint.py diff --git a/samples/python2/inpaint.py b/samples/python2/inpaint.py new file mode 100644 index 0000000000..ddd8abc99d --- /dev/null +++ b/samples/python2/inpaint.py @@ -0,0 +1,35 @@ +import numpy as np +import cv2 +from common import Sketcher + +help_message = '''USAGE: inpaint.py [] + +Keys: + SPACE - update inpaint + r - restore image + ESC - exit +''' + +if __name__ == '__main__': + import sys + try: fn = sys.argv[1] + except: fn = '../cpp/fruits.jpg' + print help_message + + img = cv2.imread(fn) + img_mark = img.copy() + mark = np.zeros(img.shape[:2], np.uint8) + sketch = Sketcher('img', [img_mark, mark], lambda : ((255, 255, 255), 255)) + + while True: + ch = cv2.waitKey() + if ch == 27: + break + if ch == ord(' '): + res = cv2.inpaint(img_mark, mark, 3, cv2.INPAINT_TELEA) + cv2.imshow('inpaint', res) + if ch == ord('r'): + img_mark[:] = img + mark[:] = 0 + sketch.show() + diff --git a/samples/python2/watershed.py b/samples/python2/watershed.py index 6f72d1c711..f35248a4c4 100644 --- a/samples/python2/watershed.py +++ b/samples/python2/watershed.py @@ -36,7 +36,7 @@ class App: def run(self): while True: - ch = cv2.waitKey(10) + ch = cv2.waitKey(50) if ch == 27: break if ch >= ord('1') and ch <= ord('7'): @@ -52,7 +52,6 @@ class App: self.markers[:] = 0 self.markers_vis[:] = self.img self.sketch.show() - cv2.destroyWindow('watershed') if __name__ == '__main__':