OpenCV Python rotate image by X degrees around specific point

前端 未结 9 1690
谎友^
谎友^ 2020-11-27 05:08

I\'m having a hard time finding examples for rotating an image around a specific point by a specific (often very small) angle in Python using OpenCV.

This is what I

9条回答
  •  旧时难觅i
    2020-11-27 05:25

    Quick tweak to @alex-rodrigues answer... deals with shape including the number of channels.

    import cv2
    import numpy as np
    
    def rotateImage(image, angle):
        center=tuple(np.array(image.shape[0:2])/2)
        rot_mat = cv2.getRotationMatrix2D(center,angle,1.0)
        return cv2.warpAffine(image, rot_mat, image.shape[0:2],flags=cv2.INTER_LINEAR)
    

提交回复
热议问题