python - 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?
解决方案
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|))
推荐阅读
- django - 使用 Apache mod_wsgi 在 CentOS7 上配置 Django WebApp
- laravel - 由于尝试将总和放入数组而导致的未定义偏移错误
- python - 如何为我的 y_pred 分配正确的 ID?
- javascript - a 标签上的 Onclick 事件
- javascript - Java将十六进制解析为整数
- python-3.x - 如何使用 Python 删除网格线以区分格点?
- php - 带有 PHP 7.4 的 MongoDB 3.6:未知运算符 $text
- scala - 装配 scala 项目导致重复数据删除错误
- linux - 我如何理解内核 oops 错误代码?
- postgresql - 使用 JPA 的 Criteria API 按日期间隔分组