python opencv旋转

目录

opencv 旋转图片

opencv旋转矩形框


opencv 旋转图片

opencv 旋转图片 python c++_AI视觉网奇的博客-CSDN博客_opencv 旋转

opencv旋转矩形框

def draw_rect(rect):
    # 在im画布上画矩形rect
    im = np.zeros([640, 640], dtype=np.uint8)
    cv2.polylines(im, [rect], 1, 255)
    plt.imshow(im)
    plt.show()
def rotate_rect(rect, angle):
    # 输出rect旋转后的矩形四个点的坐标,angle为正及顺时针旋转,为负及逆时针旋转
    #绕矩形框的中心旋转的:实际上以图像中心旋转,这个不对
    (x, y), (w, h), a = cv2.minAreaRect(rect)
    rect_r = ((x, y), (w, h), a + angle)
    print("angle",a)
    return cv2.boxPoints(rect_r).astype(np.int32)

if __name__ == '__main__':
    rect = np.array([[100, 50], [150, 50], [150, 150], [100, 150]], dtype=np.int32)

    # draw_rect(rect)

    rect_r=rotate_rect(rect,270)
    rect_2=rotate_rect(rect,0)
    points= cv2.minAreaRect(rect_r)
    print("rect_r",points)

    points= cv2.minAreaRect(rect_2)
    print("rect_2", points)

    im = np.zeros([640, 640], dtype=np.uint8)
    cv2.polylines(im, [rect_r], 1, 255)
    cv2.polylines(im, [rect_2], 1, 255)
    plt.imshow(im)
    plt.show()

猜你喜欢

转载自blog.csdn.net/jacke121/article/details/120098252