Python - Rotate Image

前端 未结 5 1753
时光说笑
时光说笑 2021-01-06 17:41

How can I rotate an image in Python with the help of OpenCv library, and by changing the value of height and width of the image (without using the built-in methods for rotat

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-06 18:23

    Does it have to be OpenCv? Cause if not you can easily do it with PIL:

    from PIL import Image
    
    def rotate_img(img_path, rt_degr):
        img = Image.open(img_path)
        return img.rotate(rt_degr, expand=1)
    
    img_rt_90 = rotate_img('Images/Screenshot.png', 90)
    img_rt_90.save('img_rt_90.png')
    

提交回复
热议问题