spherical.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:monodepth360 作者: srijanparmeshwar 项目源码 文件源码
def lat_long_to_rectilinear_uv(K, S, T):
    # Convert to Cartesian.
    x = tf.cos(T) * tf.sin(S)
    y = tf.sin(T)
    z = tf.cos(T) * tf.cos(S)

    argmax = tf.argmax(tf.abs([x, y, z]), axis = 0)

    # Check which face the ray lies on.
    front_check = tf.logical_and(
        tf.equal(argmax, 2),
        tf.greater_equal(z, 0.0)
    )
    back_check = tf.logical_and(
        tf.equal(argmax, 2),
        tf.less(z, 0.0)
    )
    left_check = tf.logical_and(
        tf.equal(argmax, 0),
        tf.less(x, 0.0)
    )
    right_check = tf.logical_and(
        tf.equal(argmax, 0),
        tf.greater_equal(x, 0.0)
    )
    up_check = tf.logical_and(
        tf.equal(argmax, 1),
        tf.less(y, 0.0)
    )
    down_check = tf.logical_and(
        tf.equal(argmax, 1),
        tf.greater_equal(y, 0.0)
    )

    def project_u(x, y, z, offset):
        return offset + 0.5 + (K[2] + K[0] * x / z) / 2.0

    def project_v(x, y, z):
        return 0.5 + (K[3] + K[1] * y / z) / 2.0

    # Calculate UV coordinates.
    u = tf.where(front_check, project_u(x, y, z, 0.0), tf.zeros_like(x))
    u = tf.where(back_check, project_u(x, -y, z, 1.0), u)
    u = tf.where(left_check, project_u(z, y, -x, 2.0), u)
    u = tf.where(right_check, project_u(-z, y, x, 3.0), u)
    u = tf.where(up_check, project_u(x, z, -y, 4.0), u)
    u = tf.where(down_check, project_u(x, -z, y, 5.0), u)
    u = u / 6.0

    v = tf.where(front_check, project_v(x, y, z), tf.zeros_like(y))
    v = tf.where(back_check, project_v(x, -y, z), v)
    v = tf.where(left_check, project_v(z, y, -x), v)
    v = tf.where(right_check, project_v(-z, y, x), v)
    v = tf.where(up_check, project_v(x, z, -y), v)
    v = tf.where(down_check, project_v(x, -z, y), v)

    return u, v
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号