• 透视变换Resize图像输入尺寸(深度学习)


    今日在读取代码时,发现我们平时数据增强Resize方法,除了CV最近邻、双线性、上下采样方法等,也知道图像透视变换等方法,但很少用在深度学习中的数据增强Resize处理,

    为此本文将记录这一方法,将透视变换用于模型输入Resize方法,因其简单,我将直接放入代码与结果:

    代码如下:

    import numpy as np
    import cv2
    import matplotlib.pyplot as plt
    def show_img(img):
        plt.imshow(img)
        plt.show()
    
    def affine(img, affine_size=(2048, 2048)):
        src, dst = np.zeros((3, 2), dtype=np.float32), np.zeros((3, 2), dtype=np.float32)
        h, w = img.shape[:2]
        affine_w, affine_h = affine_size[0], affine_size[1]
        src[0, :], src[1, :], src[2, :] = [0, 0], [w, 0], [w, h]
        dst[0, :], dst[1, :], dst[2, :] = [0, 0], [affine_w, 0], [affine_w, affine_h]
        trans_input = cv2.getAffineTransform(np.float32(src), np.float32(dst))
        affine_img = cv2.warpAffine(img, trans_input, (affine_w, affine_h), flags=cv2.INTER_LINEAR)
        return affine_img
    
    
    
    if __name__ == '__main__':
        root = r'C:\Users\Administrator\Desktop\company_data\a\50.jpg'
        img = cv2.imread(root)
        affine_img=affine(img)
        print(img.shape,affine_img.shape)
        show_img(img)
        show_img(affine_img)
    透视变换Resize

    结果显示:

      

                   原图                             透视resize图 

  • 相关阅读:
    Linux /dev/null详解
    Linux 重定向详解
    Linux history命令详解
    Linux echo命令详解
    Linux alias命令详解
    Linux fsck命令详解
    Linux blkid命令详解
    Linux mount命令详解
    Linux dd命令详解
    Linux free命令详解
  • 原文地址:https://www.cnblogs.com/tangjunjun/p/16390840.html
Copyright © 2020-2023  润新知