我想從照片刪除灰色背景和一個白色的OpenCV的Python的 - 設置背景顏色
取代它到目前爲止,我有這樣的代碼:
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
的問題是,圖像現在有一個黑色的背景,因爲我已經掩蓋了灰色。我怎樣才能用白色的替換空像素?
我收到錯誤AttributeError:'numpy.ndarray'對象沒有屬性'setTo'。這對你來說意味着什麼?謝謝 –