2013-03-06 07:41:02 +01:00
|
|
|
#!/usr/bin/env python
|
2012-11-23 19:57:22 +01:00
|
|
|
|
2012-10-17 01:18:30 +02:00
|
|
|
'''
|
|
|
|
Inpainting sample.
|
|
|
|
|
|
|
|
Inpainting repairs damage to images by floodfilling
|
|
|
|
the damage with surrounding image areas.
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
inpaint.py [<image>]
|
|
|
|
|
|
|
|
Keys:
|
|
|
|
SPACE - inpaint
|
|
|
|
r - reset the inpainting mask
|
|
|
|
ESC - exit
|
|
|
|
'''
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
import cv2
|
|
|
|
from common import Sketcher
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import sys
|
2013-03-06 07:41:02 +01:00
|
|
|
try:
|
|
|
|
fn = sys.argv[1]
|
2013-08-27 11:57:24 +02:00
|
|
|
except:
|
2014-09-13 16:28:41 +02:00
|
|
|
fn = '../data/fruits.jpg'
|
2013-08-27 11:57:24 +02:00
|
|
|
|
2012-10-17 01:18:30 +02:00
|
|
|
print __doc__
|
|
|
|
|
|
|
|
img = cv2.imread(fn)
|
2013-03-06 07:41:02 +01:00
|
|
|
if img is None:
|
|
|
|
print 'Failed to load image file:', fn
|
|
|
|
sys.exit(1)
|
2013-08-27 11:57:24 +02:00
|
|
|
|
2012-10-17 01:18:30 +02:00
|
|
|
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()
|
|
|
|
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()
|
|
|
|
cv2.destroyAllWindows()
|