2012-08-22 15:42:19 +02:00
|
|
|
'''
|
|
|
|
Inpainting sample.
|
|
|
|
|
|
|
|
Inpainting repairs damage to images by floodfilling
|
|
|
|
the damage with surrounding image areas.
|
2011-07-02 09:13:31 +02:00
|
|
|
|
2012-08-22 15:42:19 +02:00
|
|
|
Usage:
|
|
|
|
inpaint.py [<image>]
|
2011-07-02 09:13:31 +02:00
|
|
|
|
|
|
|
Keys:
|
2011-07-13 08:19:21 +02:00
|
|
|
SPACE - inpaint
|
|
|
|
r - reset the inpainting mask
|
2011-07-02 09:13:31 +02:00
|
|
|
ESC - exit
|
|
|
|
'''
|
|
|
|
|
2012-08-22 15:42:19 +02:00
|
|
|
import numpy as np
|
|
|
|
import cv2
|
|
|
|
from common import Sketcher
|
|
|
|
|
2011-07-02 09:13:31 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
|
|
|
try: fn = sys.argv[1]
|
|
|
|
except: fn = '../cpp/fruits.jpg'
|
2012-08-22 15:42:19 +02:00
|
|
|
print __doc__
|
2011-07-02 09:13:31 +02:00
|
|
|
|
|
|
|
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:
|
2012-03-14 22:46:34 +01:00
|
|
|
ch = 0xFF & cv2.waitKey()
|
2011-07-02 09:13:31 +02: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 04:45:15 +01:00
|
|
|
cv2.destroyAllWindows()
|
2011-07-02 09:13:31 +02:00
|
|
|
|