【发布时间】:2021-07-17 15:51:21
【问题描述】:
我在 Android 设备中获取旋转矩阵和方向(欧拉角)using a sensor。我想在opencv中使用这些进行仿射变换。仿射变换使用单应矩阵来完成它的工作。我的问题是如何将旋转矩阵或方向数组转换为可用于仿射变换的单应矩阵?
Android 代码获取旋转矩阵和方向:
final float[] rotationMatrix = new float[9];
SensorManager.getRotationMatrix(rotationMatrix, null, accelerometerReading, magnetometerReading);
final float[] orientationAngles = new float[3];
SensorManager.getOrientation(rotationMatrix, orientationAngles);
opencv 代码到仿射变换:
homographtMatrix = ... # to calc from rotation matrix or orientation angls
warped = cv2.warpPerspective(img, homographtMatrix, (cols, 600))
样本旋转矩阵:
[
[-0.39098227, -0.24775778, 0.8864249],
[0.9200034, -0.07699536, 0.38427263],
[-0.026955934, 0.96575755, 0.2580418]
]
欧拉角示例:
[1.3097044 0.0269592 1.97264932]
图像将进行仿射变换:
所需的变换(从左边剪切没关系,我可以修复它):
然后我将在分段图像中平铺地板。
【问题讨论】:
-
您想如何从 3d 旋转中扭曲 2d 图像?假设是什么?
-
我想用分段图像替换 3d 旋转图像。现在我只需要来自旋转矩阵或方向的单应矩阵。 @米卡
-
我编辑了@Micka 的帖子
-
如果您能够从这些角度构建 3D 对象旋转 (R),则图像单应性将类似于 K^-1 * R * K 与 K = 相机内在函数。必须阅读/尝试哪些边必须倒置。
-
对不起,没有 python 脚本。随意自己实现并添加答案。
标签: python android opencv computer-vision affinetransform