【opencv学习】单应性变换Homography

import cv2
import numpy as np
import pylab as plt

if __name__ == '__main__':
    # 读取原始图像
    im_src = cv2.imread('images/build.jpeg')
    h, w, c = im_src.shape

    # 原始图像中物体的四个顶点的信息
    pts_src = np.array([(0, 0), (640, 0), (0, 520), (640, 520)])
    # 目标物体中的物体的四个顶点信息
    pts_dst = np.array([(265, 30), (796, 99), (100, 473), (932, 373)])

    # 计算单应性矩阵 Homography
    # 是一个3x3的矩阵,根据对应的两个点,计算出变换矩阵,由此将原始图像进行转换。
    homography, status = cv2.findHomography(pts_src, pts_dst)
    print(homography.shape)
    print(homography)

    # 基于单应性矩阵,将原始图像转换成目标图像
    im_out = cv2.warpPerspective(im_src, homography, (w, h))

    plt.figure()
    plt.subplot(1, 2, 1), plt.imshow(im_src[:, :, ::-1]), plt.title('src')
    plt.xticks([]), plt.yticks([])
    plt.subplot(1, 2, 2), plt.imshow(im_out[:, :, ::-1]), plt.title('out')
    plt.xticks([]), plt.yticks([])

    plt.show()  # show dst

请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值