Motive From How to save only a part of a long video using OpenCV, I have processed the image of the political broadcast video as a data set, but this time ʻinpaint` Try erasing the object using (Image Repair). The reason is that the background is monotonous and nothing is shown except the telop of the time and the placard of the party name, so I thought it would be easy to repair.
Dataset Here, we will use the following capture instead of the video.
Method Create a mask image in advance and fill the area you want to repair (delete the object) with white.
After that,
cv2.inpaint(src,mask,1,cv2.INPAINT_TELEA)
Process using.
Development
import cv2
import os
import numpy as np
def inpaint(src,top,bottom):
mask = np.zeros((*src.shape[:-1],1), dtype=np.uint8)
mask = cv2.rectangle(mask,
top,
bottom,
color=(255,255,255),
thickness=cv2.FILLED
)
dst = cv2.inpaint(src,mask,1,cv2.INPAINT_TELEA)
return dst
if __name__ == '__main__':
window_name = "Drop Out NHK"
mat = cv2.imread("capture_1.png ")
mat = cv2.resize(mat, None, fx = 0.5, fy = 0.5)
dst = inpaint(mat,(200,40),(440,110))
dst = inpaint(dst,(40,25),(115,65))
cv2.imshow(window_name, dst)
cv2.waitKey(0)
cv2.destroyWindow(window_name)
Result
I was able to process more than I expected. : sweat_smile: It's hard to believe that the time and party name were displayed.
Future
Development memo # 69 Using Inpaint with OpenCV 3.2 with Contrib module
Looking at, it seems that C ++ has a function with higher accuracy than cv2.inpaint
.
Perhaps you can use C ++ to erase the subtitles nicely.
Reference
-Image Inpainting --opencv-python -Development memo # 69 Using Inpaint with OpenCV 3.2 with Contrib module -OpenCV 3.4 + Python3 fill the image with a single color
Recommended Posts