OpenCV-Python系列·第四集:图像旋转

# -*- coding: utf-8 -*-
"""
Created on Fri Aug 24 16:04:24 2018

@author: Miracle
"""

import cv2
import numpy as np

image = cv2.imread('../data/lena.jpg')
rows,cols,channel = image.shape
#旋转矩阵:旋转中心、旋转角度、尺度大小
rotation_matrix = cv2.getRotationMatrix2D(
        (cols/2.0,rows/2.0),30,1)
#变换矩阵 3×3
translation_matrix = np.float32(
        [[1,0,int(0.25*cols)],[0,1,int(0.25*rows)]])
#图像变换:src、变换矩阵、图像大小
translation_image = cv2.warpAffine(image,translation_matrix,
                                   (2*cols,2*rows))
rotation_image = cv2.warpAffine(translation_image,
                                rotation_matrix,(2*cols,2*rows))
cv2.imshow('Rotation Image',rotation_image)
cv2.waitKey()

 

你可能感兴趣的:(OpenCV-Python)