opencv/samples/python2/inpaint.py

37 lines
903 B
Python
Raw Normal View History

2011-07-02 15:13:31 +08:00
import numpy as np
import cv2
from common import Sketcher
help_message = '''USAGE: inpaint.py [<image>]
Keys:
2011-07-13 14:19:21 +08:00
SPACE - inpaint
r - reset the inpainting mask
2011-07-02 15:13:31 +08:00
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 = 0xFF & cv2.waitKey()
2011-07-02 15:13:31 +08:00
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()
2012-03-15 11:45:15 +08:00
cv2.destroyAllWindows()
2011-07-02 15:13:31 +08:00