【问题标题】:How can you find the relative spherical coordinates of an object after changing the origin?改变原点后如何找到物体的相对球坐标?
【发布时间】:2021-11-29 07:46:22
【问题描述】:

我有一个算法问题。我目前正在编写一个脚本,该脚本从虚幻引擎内部的各个角度生成对象的图像,并将这些图像与对象的坐标配对。它的工作方式是我将对象放在原点,然后生成随机球坐标来放置我的相机。然后我旋转我的相机以面对对象并进行额外的旋转,以便对象可以位于我相机的 FOV 中的任何位置。我现在想将我的相机作为原点,并找到对象相对于图形的球坐标。

目前,我正在尝试按照下面的代码推导出坐标。我首先注意到物体和相机之间的径向距离是相同的,无论哪一个是原点。然后,我使用了这样一个事实,即我的相机和我的对象之间的角度完全由我的相机放置结束时的额外旋转决定。最后,我尝试找到一个旋转,该旋转将根据相机的角坐标以与图像中相同的方式定位对象(这样做是因为我想编码关于对象上除中心之外的点的信息。例如,我目前正在使用一个 1 米的立方体作为占位符对象,并且我想跟踪角落的坐标。我选择使用旋转,因为我可以使用它们来制作旋转矩阵并使用它来转换我的坐标)。下面是我用来执行此操作的代码(此处使用 AirSim 库,但您只需要知道airsim.Pose() 将欧几里德位置坐标和四元数旋转作为参数来定位我的相机)。

PRECISION_ANGLE = 4 # Fractions of a degree used in generating random pitch, roll, and yaw values
PRECISION_METER = 100 # Fractions of a meter used in generating random distance values
RADIUS_MAX = 20 # Maximum distance from the obstacle to be expected
#TODO: Replace minimum distace with a test for detecting if the camera is inside the obstacle
RADIUS_MIN = 3 # Minimum distance from the obstacle to be expected. Set this value large enough so that the camera will not spawn inside the object

# Camera details should match settings.json
IMAGE_HEIGHT = 144
IMAGE_WIDTH = 256
FOV = 90
# TODO: Vertical FOV rounds down for generating random integers. Some pictures will not be created
VERT_FOV = FOV * IMAGE_HEIGHT // IMAGE_WIDTH

def polarToCartesian(r, theta, phi):
    return [
         r * math.sin(theta) * math.cos(phi),
         r * math.sin(theta) * math.sin(phi),
         r * math.cos(theta)]

while 1:
    # generate a random position for our camera
    r = random.randint(RADIUS_MIN * PRECISION_METER, RADIUS_MAX * PRECISION_METER) / PRECISION_METER
    phi = random.randint(0, 360 * PRECISION_ANGLE) / PRECISION_ANGLE
    theta = random.randint(0, 180 * PRECISION_ANGLE) / PRECISION_ANGLE
    # Convert polar coordinates to cartesian for AirSim
    pos = polarToCartesian(r, math.radians(theta), math.radians(phi))

    # Generate a random offset for the camera angle
    pitch = random.randint(0, VERT_FOV * PRECISION_ANGLE) / PRECISION_ANGLE - VERT_FOV / 2
    # TODO: Rotating the drone causes the obstacle to be removed from the image because the camera is not square
    #roll = random.randint(0, 360 * PRECISION_ANGLE) / PRECISION_ANGLE
    roll = 0
    yaw = random.randint(0, FOV * PRECISION_ANGLE) / PRECISION_ANGLE - FOV/2

    # Calculate coordinates of the center of the obstacle relative to the drone's new position and orientation
    obs_r = r
    obs_phi = yaw
    obs_theta = 90 - pitch
    # Convert polar coordinates to cartesian for AirSim
    obs_pos = polarToCartesian(obs_r, math.radians(obs_theta), math.radians(obs_phi))

    # Record rotational transformation on obstacle for calculating coordinates of key locations relative to the center
    obs_phi_offset = -phi
    obs_theta_offset = 270 - theta

    # Move the camera to our calculated position
    camera_pose = airsim.Pose(airsim.Vector3r(pos[0], pos[1], pos[2]), airsim.to_quaternion(math.radians(90 - theta + pitch), math.radians(roll), math.radians(phi + 180 + yaw))) #radians

此算法是否正确实施?还有什么其他方法可以找到我的对象的坐标?我是否应该在虚幻引擎中做一些事情来获取我的坐标,而不是通过算法来做这个(尽管它需要很快)?

【问题讨论】:

  • 我对你的解释知之甚少。我只能说,对于球坐标原点的改变,你所做的任何事情都相当于转换为笛卡尔坐标,改变原点然后回到球坐标。没有捷径。

标签: python camera geometry computational-geometry unreal-engine4


【解决方案1】:

Vector3(i,j,k) 对原点的翻译只是对原始输出的翻译。

camera_pose = airsim.Pose(airsim.Vector3r(pos[0] + i, pos[1] + j, pos[2] + k), airsim.to_quaternion(math.radians(90 - theta + pitch), math.radians(roll), math.radians(phi + 180 + yaw))) #radians

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-07
    • 1970-01-01
    • 1970-01-01
    • 2014-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多