我将尝试从一张照片中去除灰色背景,并用白色背景替换它。
目前我有以下代码:
问题在于,由于我已经遮盖了灰色部分,所以图像现在具有黑色背景。我该如何用白色像素替换空白像素?
目前我有以下代码:
image = cv2.imread(args["image"])
r = 150.0 / image.shape[1]
dim = (150, int(image.shape[0] * r))
resized = cv2.resize(image, dim, interpolation=cv2.INTER_AREA)
lower_white = np.array([220, 220, 220], dtype=np.uint8)
upper_white = np.array([255, 255, 255], dtype=np.uint8)
mask = cv2.inRange(resized, lower_white, upper_white) # could also use threshold
res = cv2.bitwise_not(resized, resized, mask)
cv2.imshow('res', res) # gives black background
问题在于,由于我已经遮盖了灰色部分,所以图像现在具有黑色背景。我该如何用白色像素替换空白像素?