2013-03-06 14:41:02 +08:00
|
|
|
#!/usr/bin/env python
|
2012-11-24 02:57:22 +08:00
|
|
|
|
2012-10-17 07:18:30 +08: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
|
|
|
|
'''
|
|
|
|
|
2015-09-14 00:00:22 +08:00
|
|
|
# Python 2/3 compatibility
|
|
|
|
from __future__ import print_function
|
|
|
|
|
2012-10-17 07:18:30 +08:00
|
|
|
import numpy as np
|
2017-12-11 17:55:03 +08:00
|
|
|
import cv2 as cv
|
2019-03-20 02:03:58 +08:00
|
|
|
|
2012-10-17 07:18:30 +08:00
|
|
|
from common import Sketcher
|
|
|
|
|
2019-03-20 02:03:58 +08:00
|
|
|
def main():
|
2012-10-17 07:18:30 +08:00
|
|
|
import sys
|
2013-03-06 14:41:02 +08:00
|
|
|
try:
|
|
|
|
fn = sys.argv[1]
|
2013-08-27 17:57:24 +08:00
|
|
|
except:
|
2018-11-14 23:56:21 +08:00
|
|
|
fn = 'fruits.jpg'
|
2013-08-27 17:57:24 +08:00
|
|
|
|
2018-11-14 23:56:21 +08:00
|
|
|
img = cv.imread(cv.samples.findFile(fn))
|
2013-03-06 14:41:02 +08:00
|
|
|
if img is None:
|
2015-09-14 00:00:22 +08:00
|
|
|
print('Failed to load image file:', fn)
|
2013-03-06 14:41:02 +08:00
|
|
|
sys.exit(1)
|
2013-08-27 17:57:24 +08:00
|
|
|
|
2012-10-17 07:18:30 +08: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:
|
2017-12-11 17:55:03 +08:00
|
|
|
ch = cv.waitKey()
|
2012-10-17 07:18:30 +08:00
|
|
|
if ch == 27:
|
|
|
|
break
|
|
|
|
if ch == ord(' '):
|
2017-12-11 17:55:03 +08:00
|
|
|
res = cv.inpaint(img_mark, mark, 3, cv.INPAINT_TELEA)
|
|
|
|
cv.imshow('inpaint', res)
|
2012-10-17 07:18:30 +08:00
|
|
|
if ch == ord('r'):
|
|
|
|
img_mark[:] = img
|
|
|
|
mark[:] = 0
|
|
|
|
sketch.show()
|
2019-03-20 02:03:58 +08:00
|
|
|
|
|
|
|
print('Done')
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
print(__doc__)
|
|
|
|
main()
|
2017-12-11 17:55:03 +08:00
|
|
|
cv.destroyAllWindows()
|