OpenCV python 重映射–图片旋转90度
原图:[source.jpg]
import cv2
import numpy as np
def main():
# 1.随机创建图片
img_src = cv2.imread("source.jpg")
height, width = img_src.shape[:2]
print("img width:%d height:%d" % (width, height))
# 2.创建X,Y map
map_x = np.zeros([width, height], np.float32)
map_y = np.zeros([width, height], np.float32)
# 3.执行重映射 调整 X Y map位置
for i in range(width):
for j in range(height):
map_x.itemset((i, j), i)
map_y.itemset((i, j), j)
# 4.执行重映射处理
img_dst = cv2.remap(img_src, map_x, map_y, cv2.INTER_LINEAR)
# 5.显示结果
cv2.imshow("img_src", img_src)
cv2.imshow("img_dst", img_dst)
cv2.waitKey()
cv2.destroyAllWindows()
if __name__ == '__main__':
main()
结果图片: