Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/samples/python/inpaint.py
16337 views
1
#!/usr/bin/env python
2
3
'''
4
Inpainting sample.
5
6
Inpainting repairs damage to images by floodfilling
7
the damage with surrounding image areas.
8
9
Usage:
10
inpaint.py [<image>]
11
12
Keys:
13
SPACE - inpaint
14
r - reset the inpainting mask
15
ESC - exit
16
'''
17
18
# Python 2/3 compatibility
19
from __future__ import print_function
20
21
import numpy as np
22
import cv2 as cv
23
from common import Sketcher
24
25
if __name__ == '__main__':
26
import sys
27
try:
28
fn = sys.argv[1]
29
except:
30
fn = '../data/fruits.jpg'
31
32
print(__doc__)
33
34
img = cv.imread(fn)
35
if img is None:
36
print('Failed to load image file:', fn)
37
sys.exit(1)
38
39
img_mark = img.copy()
40
mark = np.zeros(img.shape[:2], np.uint8)
41
sketch = Sketcher('img', [img_mark, mark], lambda : ((255, 255, 255), 255))
42
43
while True:
44
ch = cv.waitKey()
45
if ch == 27:
46
break
47
if ch == ord(' '):
48
res = cv.inpaint(img_mark, mark, 3, cv.INPAINT_TELEA)
49
cv.imshow('inpaint', res)
50
if ch == ord('r'):
51
img_mark[:] = img
52
mark[:] = 0
53
sketch.show()
54
cv.destroyAllWindows()
55
56