利用python将图片镜像变换 opencv3.4

感谢博主的分享:点击打开链接
以下是本人的代码(以水平镜像为主,其他方向原理一样): 
# -*- coding:utf-8 -*-
"""
@author:lei 
"""
"""
#水平镜像可按公式

#I = i

#J = N - j + 1

#垂直镜像可按公式

#I = M - i + 1

#J = j

#对角镜像可按公式

#I = M - i + 1

#J = N - j + 1
"""

import cv2
import copy
import os


def mirror_imgs(imgs_path,save_path):

    for name in os.listdir(imgs_path):
        print name
        image = cv2.imread(os.path.join(imgs_path,name), 1);
        height = image.shape[0]
        width = image.shape[1]
        #channels = image.shape[2]
        iLR = copy.deepcopy(image)  # 获得一个和原始图像相同的图像,注意这里要使用深度复制

        for i in range(height):
            for j in range(width):
                iLR[i, width - 1 - j] = image[i, j]
        #cv2.imshow('image', image)
        #cv2.imshow('iLR', iLR)
        cv2.imwrite(os.path.join(save_path,name), iLR,
                    [int(cv2.IMWRITE_JPEG_QUALITY), 100])#保存图片
        #cv2.waitKey(0)
        #cv2.destroyAllWindows()




imgs_path='/home/ubuntu/python_coding/Mirror_Image/imgs'
save_path="/home/ubuntu/python_coding/Mirror_Image/save/"
mirror_imgs(imgs_path,save_path)

你可能感兴趣的:(python,opencv)