IOPaint/iopaint/model/opencv2.py

30 lines
735 B
Python
Raw Normal View History

2022-09-25 15:27:12 +02:00
import cv2
2024-01-05 09:40:06 +01:00
from .base import InpaintModel
2024-01-05 08:19:23 +01:00
from iopaint.schema import InpaintRequest
2022-09-25 15:27:12 +02:00
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
2023-12-01 03:15:35 +01:00
is_erase_model = True
2022-09-25 15:27:12 +02:00
@staticmethod
def is_downloaded() -> bool:
return True
2023-12-30 16:36:44 +01:00
def forward(self, image, mask, config: InpaintRequest):
2022-09-25 15:27:12 +02:00
"""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