I just erased the object using image repair (inpaint) (OpenCV: Python)

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. capture_1.png

Method Create a mask image in advance and fill the area you want to repair (delete the object) with white.

mask1.png mask2.png

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

output_inpaint.png

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

I just erased the object using image repair (inpaint) (OpenCV: Python)
I just erased the object using image repair (inpaint) (OpenCV: C ++)
I tried "smoothing" the image with Python + OpenCV
I tried "differentiating" the image with Python + OpenCV
I tried object detection using Python and OpenCV
I tried "binarizing" the image with Python + OpenCV
I tried using the image filter of OpenCV
I tried "gamma correction" of the image with Python + OpenCV
[Python] Using OpenCV with Python (Image transformation)
vprof --I tried using the profiler for Python
I tried using the Datetime module by Python
[Python + OpenCV] Whiten the transparent part of the image
[Python] I tried to judge the member image of the idol group using Keras
I want to crop the image along the contour instead of the rectangle [python OpenCV]
Object tracking using OpenCV3 and Python3 (tracking feature points specified by the mouse using the Lucas-Kanade method)
[OpenCV / Python] I tried image analysis of cells with OpenCV
Rotate and scale the image before cropping [python] [OpenCV]
[Python] Mask the image into a circle using Pillow
Python OpenCV tried to display the image in text.
I tried to compress the image using machine learning
I made a function to crop the image of python openCV, so please use it.
I tried to find the entropy of the image with python
I tried using the Python library from Ruby with PyCall
I just changed the sample source of Python a little.
Try a similar search for Image Search using the Python SDK [Search]
I tried face recognition from the video (OpenCV: python version)
I just wrote the original material for the python sample code
Miscellaneous notes that I tried using python for the matter
[Python] I tried collecting data using the API of wikipedia
[Python] Accessing and cropping image pixels using OpenCV (for beginners)
[For beginners] I tried using the Tensorflow Object Detection API
Image editing with python OpenCV
[Python] Using OpenCV with Python (Basic)
[Python] I tried using OpenPose
Using OpenCV with Python @Mac
I downloaded the python source
I tried using the python module Kwant for quantum transport calculation
[Python] I wrote the route of the typhoon on the map using folium
I tried to process the image in "sketch style" with OpenCV
I tried to digitize the stamp stamped on paper using OpenCV
I tried to display the video playback time (OpenCV: Python version)
I tried to process the image in "pencil style" with OpenCV
Object extraction in images by pattern matching using OpenCV with Python
I tried to make an image similarity function with Python + OpenCV
[Ubuntu] [Python] Object tracking using dlib
I made a Line-bot using Python!
Judgment of backlit image using OpenCV
[Python] Using OpenCV with Python (Edge Detection)
I tried using Thonny (Python / IDE)
I liked the tweet with python. ..
Extract the targz file using python
I wrote the queue in Python
I calculated "Levenshtein distance" using Python
Try using the Python Cmd module
Find image similarity with Python + OpenCV
Try blurring the image with opencv2
Introduction to image analysis opencv python
I tried using the checkio API
[Python] I tried using YOLO v3
I wrote the stack in Python
I tried to transform the face image using sparse_image_warp of TensorFlow Addons