Python+OpenCV:仿射变换和透射变换

82 篇文章 20 订阅

Python+OpenCV:仿射变换和透射变换

仿射变换

####################################################################################################
# 仿射图像
def lmc_cv_affining():
    """
        函数功能: 仿射图像.
    """

    # 读取图像
    image = lmc_cv.imread('D:/99-Research/Python/Image/CheckerBoard.jpg')

    # 仿射图像
    rows, cols, channel = image.shape
    pts1 = np.float32([[50, 50], [200, 50], [50, 200]])
    pts2 = np.float32([[10, 100], [200, 50], [100, 250]])
    matrix = lmc_cv.getAffineTransform(pts1, pts2)
    affining_image = lmc_cv.warpAffine(image, matrix, (cols, rows))

    # 显示图像
    pyplot.figure('Image Display')
    pyplot.subplot(121)
    pyplot.imshow(image)
    pyplot.title('Input')
    pyplot.subplot(122)
    pyplot.imshow(affining_image)
    pyplot.title('Output')
    pyplot.show()

    # 根据用户输入保存图像
    if ord("q") == (lmc_cv.waitKey(0) & 0xFF):
        # 销毁窗口
        pyplot.close()
    return

透射变换

    image = lmc_cv.imread('D:/99-Research/Python/Image/Sudoku.jpg')

    # 透视图像
    rows, cols, channel = image.shape
    pts1 = np.float32([[33, 47], [424, 43], [2, 498], [441, 511]])
    pts2 = np.float32([[0, 0], [300, 0], [0, 300], [300, 300]])

    matrix = lmc_cv.getPerspectiveTransform(pts1, pts2)
    perspectiving_image = lmc_cv.warpPerspective(image, matrix, (300, 300))

    # 显示图像
    pyplot.figure('Image Display')
    pyplot.subplot(121)
    pyplot.imshow(image)
    pyplot.title('Input')
    pyplot.subplot(122)
    pyplot.imshow(perspectiving_image)
    pyplot.title('Output')
    pyplot.show()

    # 根据用户输入保存图像
    if ord("q") == (lmc_cv.waitKey(0) & 0xFF):
        # 销毁窗口
        pyplot.close()
    return

 

 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值