我正在尝试使用opencv去除图像中的眩光,我也有面具

问题描述 投票:0回答:1

这是错误 它说(-210:不支持的格式或格式组合)掩码必须是函数“icvInpaint”中的8位1通道图像


import numpy as np
#from scipy.misc import bytescale
import cv2
import matplotlib.pyplot as plt

image = cv2.imread("C:/Users/lbollam/Documents/forpy/Image_with_glare.jpeg")
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
mask = cv2.imread("C:/Users/lbollam/Documents/forpy/Mask.jpeg")
mask = cv2.cvtColor(mask, cv2.COLOR_BGR2RGB)
#mask1=bytescale(mask1)

f = plt.figure(figsize=(12, 12))
f.add_subplot(1, 2, 1)
plt.imshow(image)
f.add_subplot(1, 2, 2)
plt.imshow(mask)
plt.show(block=True)
Image_withoutglare = cv2.inpaint(image,mask, 21, cv2.INPAINT_TELEA)
f = plt.figure(figsize=(12, 12))
f.add_subplot(1, 2, 1)
plt.imshow(Image_withoutglare)


python-3.x opencv
1个回答
0
投票

我通过

mask.astype(np.uint8)
将numpy数组更改为uint8 dtype。此外,修复算法的工作原理与通道维度(=颜色维度)无关,因此我将该函数分别应用于每个通道。

类似这样的:


inpainted_image = np.zeros_like(image)
mask = mask.astype(np.uint8)
_, _, num_channels = mask.shape
for c in range(num_channels):
    mask_channel = mask[:, :, c]
    inpainted_image[:, :, c] = cv2.inpaint(image[:, :, c], mask_channel, 21, cv2.INPAINT_TELEA)
© www.soinside.com 2019 - 2024. All rights reserved.