Easiest way to rotate by 90 degrees an image using OpenCV?

后端 未结 7 1130
轮回少年
轮回少年 2020-11-29 05:52

What is the best way (in c/c++) to rotate an IplImage/cv::Mat by 90 degrees? I would assume that there must be something better than transforming it using a matrix, but I ca

7条回答
  •  没有蜡笔的小新
    2020-11-29 06:22

    Here is my python cv2 implementation:

    import cv2
    
    img=cv2.imread("path_to_image.jpg")
    
    # rotate ccw
    out=cv2.transpose(img)
    out=cv2.flip(out,flipCode=0)
    
    # rotate cw
    out=cv2.transpose(img)
    out=cv2.flip(out,flipCode=1)
    
    cv2.imwrite("rotated.jpg", out)
    

提交回复
热议问题