这里图片修补分两步骤:
1.将需要使用的图片进行绘画
import cv2
import numpy as np
img = cv2.imread('image1.jpg',1)
for i in range(200,300):
img[i,200]=(255,0,255)
img[i,200+1]=(255,0,255)
img[i,200-1]=(255,0,255)
for i in range(150,250):
img[250,i] = (255,255,0)
img[250+1,i] = (255,255,0)
img[250-1,i] = (255,255,0)
cv2.imwrite('damaged.jpg',img)
cv2.imshow('image',img)
cv2.waitKey(0)
2.将进行绘画后的图片修补为原状
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
paint[i,200+1]=255
paint[i,200-1]=255
for i in range(150,250):
paint[250,i] = 255
paint[250+1,i] =255
paint[250-1,i] = 255
cv2.imshow('paint',paint)
imgDst = cv2.inpaint(img,paint,3,cv2.INPAINT_TELEA)
cv2.imshow('imgDst',imgDst)
cv2.waitKey(0)