1. 二维图像顺逆时针旋转90度 参考链接:参考链接
#coding=utf-8
import cv2
#实现2维矩阵顺/逆时针旋转90°
def rotate(matrix):
"""
:type matrix: List[List[int]]
:rtype: void Do not return anything, modify matrix in-place instead.
"""
# matrix[::-1] 矩阵上下翻转
# map(list, zip(*list) 转置
matrix[:] = map(list, zip(*matrix[::-1]))
matrix[:] = map(list, zip(*matrix))[::-1] # 先转置,再上下翻转
img = cv2.imread('img.jpg', cv2.IMREAD_GRAYSCALE) #rgb转gray
rotate(img)
cv2.imwrite('rotate90.jpg', img)