我正在尝试使用 OpenCV 和以下代码在 Python 中旋转图像:
import cv2
img = cv2.imread("image.png")
rows = img.shape[0]
cols = img.shape[1]
img_center = (cols / 2, rows / 2)
M = cv2.getRotationMatrix2D(img_center, 45, 1)
rotated_image = cv2.warpAffine(img, M, (cols, rows))
代码正常工作,但图像不再可见的背景变为黑色。我希望背景为白色,因此我想知道是否可以指定OpenCV旋转时应使用的颜色。
一只斗牛犬
慕慕森
随时随地看视频慕课网APP
相关分类