import cv2
import numpy as np
img = cv2.imread('damaged.jpg',1)
cv2.imshow('src',img)
imgInfo = img.shape
height=imgInfo[0]
width=imgInfo[1]
paint = np.zeros((height,width,1),np.uint8)
for i in range(200,300):
paint[i,200] = 255
#横坐标变化,纵坐标不变,+1及-1共占三个象素
paint[i,200+1] = 255
paint[i,200-1] = 255
#255,单通道
for i in range(150,250):
paint[i,200] = 255
paint[i,200+1] = 255
paint[i,200-1] = 255
cv2.imshow('paint',paint)
imgDst = cv2.inpaint(img,paint,3,cv2.INPAINT_TELEA)
cv2.imshow('image',imgDst)
cv2.waitKey(0)
cv2.destroyAllWindows()
先在图片中划十字叉
import cv2
import numpy as np
img = cv2.imread('BC03.jpg',1)
for i in range(200,300):
img[i,200] = (255,255,255)
#横坐标变化,纵坐标不变,+1及-1共占三个象素
img[i,200+1] = (255,255,255)
img[i,200-1] = (255,255,255)
for i in range(150,250):
img[250,i] = (255,255,255)
img[250+1,i] = (255,255,255)
img[250-1,i] = (255,255,255)
cv2.imwrite('damaged.jpg',img)
cv2.imshow('image',img)
cv2.waitKey(0)
#cv2.destroyAllWindows()