--- /dev/null
+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
\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
self.markers[:] = 0\r
self.markers_vis[:] = self.img\r
self.sketch.show()\r
- cv2.destroyWindow('watershed')\r
\r
\r
if __name__ == '__main__':\r