首页 > 解决方案 > Convert 2D points with rotation to equirectangular projection coordinates

问题描述

I have create a simple cube and textured it with a cubemap extracted from a panorama image. In this cube I do rotations around it's origin and create images using glReadPixels. Once I have processed those images I get a few points per image for which I would like to calculate their equivalent coordinates on the equirectangular panorama image.

I have found a similar question here.

But that doesn't work out of the box because of the rotations. My attempt to solve this was to apply the same rotation to the points I got in each image to get x,y,z and pretty much use the method in the link above, but the coordinates I got were far off.

Rotation in OpenGL:

glLoadIdentity()
glRotatef(pitch, 1.0, 0.0, 0.0)
glRotatef(yaw, 0.0, 1.0, 0.0)

Here is some code for the rotation of the 2D point in a image:

q1 = Quaternion(axis=[0, 1, 0], degrees=rotation[0])
q2 = Quaternion(axis=[1, 0, 0], degrees=rotation[1])
q3 = q1*q2
res1 = q3.rotate(np.array([x1, y1, 1]))

I don't rotate about the z-axis. Btw I tried to switch q1 and q2 and I also tried using euler from the transforms3d library, which gave me the same values.

I think z which is set to 1 could be the issue here but I am not sure.

Any ideas?

标签: pythonopenglrotation

解决方案


Solved the problem.

Passed the x, y coords to OpenGL and got the depth using glReadPixels and the final point by gluUnProject.

depth = glReadPixels(x1, y1, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT)
point = gluUnProject(x1, y1, depth, model_view, proj, view)

The rest was done using the method "map_cube" in the link I posted. (Just some adjustments for u and v were necessary and the cube face can be determined by argmax(|x|, |y|, |z|))


推荐阅读