• 关于手机拍摄的图片在处理过程中出现问题的解决方法


    from PIL import Image
    import os
    
    
    # 图片旋转
    def image_route(in_file, out_file):
        img = Image.open(in_file)
        dict_exif = img.getexif()
        try:
            res = dict_exif[274]
            if res == 1:
                img = img.rotate(0, expand=True)
            elif res == 8:
                print("向右", in_file)
                img = img.rotate(90, expand=True)
            elif res == 6:
                print("向左", in_file)
                img = img.rotate(-90, expand=True)
            elif res == 3:
                print("翻转", in_file)
                img = img.rotate(180, expand=True)
            else:
                print(res, "不正常", in_file)
                img = img.rotate(0, expand=True)
            img.save(out_file)
        except:
            print("error:", in_file)
            img = img.rotate(0, expand=True)
            img.save(os.path.join(_save, i))
    
    
    if __name__ == '__main__':
        # 要调整的路径
        path = r"C:Users***Desktop301"
        # 调整之后保存的路径
        _save = r"C:Users***Desktop302"
        for i in os.listdir(path):
            in_file = os.path.join(path, i)
            out_file = os.path.join(_save, i)
            image_route(in_file, out_file)
    

      

  • 相关阅读:
    多项式学习笔记(二) NTT
    矩阵树定理学习笔记
    拓展BSGS 学习笔记
    P2257 YY的GCD
    P1891 疯狂的lcm
    友链
    关于我
    焚燃指间の回忆
    洛谷P4180
    洛谷P2292
  • 原文地址:https://www.cnblogs.com/ldsice/p/14582673.html
Copyright © 2020-2023  润新知