博客
关于我
基于OpenCV的透视图转化为不同平面
阅读量:329 次
发布时间:2019-03-04

本文共 2877 字,大约阅读时间需要 9 分钟。

??????????????????????????????????????????????????????????????????????????????????????????????????

???????????????????????????????????????????????????????????????

??????????????????????????????????????????????????????2D???????????????????????????

?????????3D???????????????????????????????????????????????????????????????????????????

????????????????3D???????2D????????????3D????3x4????????????2D???

?????3x4???????3D???????x?y?z????2D??????????u?v??????????2D???????3D??????????????z=0??

????

  • ???????

    ????????z????????????????????z??????3x4???????3x3????????????????????????????????????

  • ??????

    ??????????????????????????????????????????????????????????u?v????????????x?y???OpenCV??????cv2.findHomography??????????

  • ????

    import cv2
    import numpy as np
    def get_inverse_perspective(perspective_matrix: np.array) -> np.array:
    """ This method calculates the inverse of perspective matrix by homography. """
    # Take 5 homogeneous points on the floor plane (Unit is in Meters)
    pts_dst = np.array([[0, 0, 0, 1],
    [0, 1, 0, 1],
    [1, 0, 0, 1],
    [1, 1, 0, 1],
    [0, 0, 0, 1]])
    # Obtain respective homogeneous points on the image plane
    pts_src = (perspective_matrix @ pts_dst.T).T
    # Convert homogeneous coordinates to Cartesian coordinates
    pts_src_cart = np.array([[x/w, y/w] for x, y, w in pts_src])
    pts_dst_cart = np.array([[x/w, y/w] for x, y, z, w in pts_dst])
    # Find the 3x3 Homography Matrix for transforming image plane to floorplane
    H, status = cv2.findHomography(pts_src_cart, pts_dst_cart)
    return H
    def project_to_floor(image_coordinates: List[int], H: np.array) -> List[int]:
    """ This method takes the Homography matrix and the 2D image Cartesian coordinates.
    It returns the (x, y) Cartesian coordinates in 3D world coordinates on floorplane (z=0). """
    # Adding 1 for homogeneous coordinate system
    x, y, w = H @ np.array([[*image_coordinates, 1]]).T
    return [x/w, y/w]
    # Example usage
    p = np.random.rand(3, 4)
    H = get_inverse_perspective(p)
    src_point = (5, 10)
    dst_point = project_to_floor(src_point, H)

    ????

  • ?????????

    ???????z=0???????z??????3x4???????3x3???????????

  • ????

    ???????????????????????????????4?????

  • OpenCV??

    ?OpenCV??????cv2.findHomography??????????

  • ????????????2D????????????3D????????????

    ????

  • OpenCV-Contrib?????????

    ???????????????????????????????????OpenCV???????????????????SFM????????????????????????????????

  • Python??????52?

    ????????????????Python???????????????????????????????????????????????????????????????????31????????????????????

  • OpenCV????20?

    ????????????????OpenCV????20?????????20???OpenCV????????????OpenCV???

  • ??????????????????SLAM??????????????????????????????????GAN???????????????????????????+??/??+???????????? ???? ??SLAM????????????????????????????????????????????????????????????~

    转载地址:http://yyaq.baihongyu.com/

    你可能感兴趣的文章
    NOI-1.3-11-计算浮点数相除的余数
    查看>>
    noi.ac #36 模拟
    查看>>
    NOI2010 海拔(平面图最大流)
    查看>>
    NOIp2005 过河
    查看>>
    NOIP2011T1 数字反转
    查看>>
    NOIP2014 提高组 Day2——寻找道路
    查看>>
    noip借教室 题解
    查看>>
    NOIP模拟测试19
    查看>>
    NOIp模拟赛二十九
    查看>>
    Vue3+element plus+sortablejs实现table列表拖拽
    查看>>
    Nokia5233手机和我装的几个symbian V5手机软件
    查看>>
    non linear processor
    查看>>
    Non-final field ‘code‘ in enum StateEnum‘
    查看>>
    none 和 host 网络的适用场景 - 每天5分钟玩转 Docker 容器技术(31)
    查看>>
    None还可以是函数定义可选参数的一个默认值,设置成默认值时实参在调用该函数时可以不输入与None绑定的元素...
    查看>>