OpenCV python 将黑色图片中心正方形区域变白?怎么写?
import cv2
img = cv2.imread('black_image.jpg', 0) # 读入图片并转化为灰度图
height, width = img.shape[:2] # 获取图片长宽
x = width // 4 # 左上角x坐标
y = height // 4 # 左上角y坐标
w = width // 2 # 正方形宽度
img[y:y+w, x:x+w] = 255 # 将正方形区域变白
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite('white_image.jpg', img)