【发布时间】:2014-02-22 03:09:39
【问题描述】:
我正在试验 OpenCV 和 Python 的绑定。此代码旨在使用命令行参数值旋转图像。但是,它保存为输入图像的精确副本,没有任何旋转。
import cv2 as cv
def rotateImage(self, image, angle):
print "Rotating image to angle: %s" % (angle)
print type(image) #image is numpy.ndarray
print type(angle) #angle is float
center = tuple(np.array(image.shape[0:2])/2)
matrix = cv.getRotationMatrix2D(center, angle, 1.0)
rotate = cv.warpAffine(image, matrix, image.shape[0:2], flags=cv.INTER_LINEAR)
fileList = self.filename.split(".")
newFile = fileList[0] + "_rotate_%s." % (int(angle)) + fileList[1]
print "Saving to %s" % (newFile)
cv.imwrite(newFile, rotate)
我的问题是旋转后保存的图像不是输入的图像。
输入图片:
输出:
鉴于这些输入和输出,我如何更改图像尺寸以允许 30 度和 45 度旋转?
【问题讨论】:
标签: python opencv image-processing image-rotation