OpenCV Python rotate image by X degrees around specific point

前端 未结 9 1680
谎友^
谎友^ 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条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 05:34

    def rotate(image, angle, center = None, scale = 1.0):
        (h, w) = image.shape[:2]
    
        if center is None:
            center = (w / 2, h / 2)
    
        # Perform the rotation
        M = cv2.getRotationMatrix2D(center, angle, scale)
        rotated = cv2.warpAffine(image, M, (w, h))
    
        return rotated
    

提交回复
热议问题