美文网首页
32.仿射变换

32.仿射变换

作者: 十里江城 | 来源:发表于2019-11-12 15:19 被阅读0次

    通过组合矩阵进行的仿射变换:

    import cv2
    import numpy as np
    
    # 三点决定仿射后的新的三个位置
    img = cv2.imread('face.jpg', 1)
    cv2.imshow('src', img)
    imgInfo = img.shape
    height = imgInfo[0]
    width = imgInfo[1]
    # 左上 左下 右上
    matSrc = np.float32([[0, 0], [0, height - 1], [width - 1, 0]])
    matDst = np.float32([[50, 50], [300, height - 200], [width - 300, 100]])
    
    # 组合矩阵
    matAffine = cv2.getAffineTransform(matSrc, matDst)
    # 仿射变换: img, matAffine, info
    dst = cv2.warpAffine(img, matAffine, (height, width))
    
    cv2.imshow('dst', dst)
    cv2.waitKey(0)
                         
    

    结果如下:


    image.png

    相关文章

      网友评论

          本文标题:32.仿射变换

          本文链接:https://www.haomeiwen.com/subject/hncqictx.html