代码
import cv2 as cv
import numpy as np
src = cv.imread("./apple.jpg", cv.IMREAD_COLOR)
cv.namedWindow("input", cv.WINDOW_AUTOSIZE)
cv.imshow("input", src)
h, w = src.shape[:2]
print(h, w)
cy = h // 2
cx = w // 2
roi = src[cy - 200:cy + 200, cx - 200:cx + 200, :]
cv.imshow("roi", roi)
image = np.copy(roi)
roi[:, :, 0] = 0
cv.imshow("change roi will change src", src)
image[:, :, 2] = 0
cv.imshow("change image and src's output", src)
cv.imshow("change image", image)
result = np.zeros(src.shape, src.dtype)
result[:, :, 0] = 255
mask = cv.bitwise_not(src)
dst = cv.bitwise_or(src, result)
dst = cv.add(dst, src)
cv.imshow("dst", dst)
cv.waitKey(0)
cv.destroyAllWindows()
效果
解释