2022-09-25 15:27:12 +02:00
|
|
|
import cv2
|
|
|
|
from lama_cleaner.model.base import InpaintModel
|
|
|
|
from lama_cleaner.schema import Config
|
|
|
|
|
2023-02-11 06:30:09 +01:00
|
|
|
flag_map = {"INPAINT_NS": cv2.INPAINT_NS, "INPAINT_TELEA": cv2.INPAINT_TELEA}
|
|
|
|
|
2022-10-09 15:32:13 +02:00
|
|
|
|
2022-09-25 15:27:12 +02:00
|
|
|
class OpenCV2(InpaintModel):
|
2023-02-11 06:30:09 +01:00
|
|
|
name = "cv2"
|
2022-09-25 15:27:12 +02:00
|
|
|
pad_mod = 1
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def is_downloaded() -> bool:
|
|
|
|
return True
|
|
|
|
|
|
|
|
def forward(self, image, mask, config: Config):
|
|
|
|
"""Input image and output image have same size
|
|
|
|
image: [H, W, C] RGB
|
|
|
|
mask: [H, W, 1]
|
|
|
|
return: BGR IMAGE
|
|
|
|
"""
|
2023-02-11 06:30:09 +01:00
|
|
|
cur_res = cv2.inpaint(
|
|
|
|
image[:, :, ::-1],
|
|
|
|
mask,
|
|
|
|
inpaintRadius=config.cv2_radius,
|
|
|
|
flags=flag_map[config.cv2_flag],
|
|
|
|
)
|
2022-09-25 15:27:12 +02:00
|
|
|
return cur_res
|