简体   繁体   English

Project Tango点云平移和旋转

[英]Project Tango Point Cloud Translations and Rotations

I want to use the Tango Device to capture Point Cloud images and save them to a file. 我想使用探戈设备捕获点云图像并将其保存到文件中。 From there I can stich the individual Point Clouds together to form a complete 3D image of a building interior. 从那里,我可以将各个点云混合在一起,以形成建筑物内部的完整3D图像。 I have modified the PointCloudJava app from (google tango's official github page) to include a button where each time you press it the currently viewable Point Cloud is saved to a file in binary format along with its Pose data. 我已经从(谷歌探戈的官方github页面)修改了PointCloudJava应用程序,以包括一个按钮,每当您按下该按钮时,当前可见的点云便会以其姿势数据以二进制格式保存到文件中。 An external app converts the binary Point Clouds into a human readable .PTS format. 外部应用程序将二进制点云转换为人类可读的.PTS格式。 Here is a snippet of this .PTS file… 这是此.PTS文件的摘要...

…
3.695209841412947 -0.473210369136531 -4.512059939636327
3.688643257302687 -0.479607720759112 -4.520564449562169
3.693362633866713 -0.489787657644946 -4.520674956573583
3.689930121583388 -0.445884992268283 -4.507568610443212
3.685492555779860 -0.462776307847697 -4.512719524635411
3.667657594365523 -0.480809484508235 -4.535319340957738
3.687827806157515 -0.496090938236911 -4.526998413337804
3.673954348248885 -0.508897741224963 -4.541318190826512
3.666625241918013 -0.498062555577952 -4.540336502327062
3.678675393742964 -0.474170316841799 -4.529156101478673
3.684755723161147 -0.485069070842463 -4.528201831115819
3.680454175156996 -0.519459594872195 -4.541313899292089
3.673863212747023 -0.492040087368685 -4.534148228897191
3.683874587697432 -0.502062504079539 -4.534162414802648
3.662268142384932 -0.486682941105563 -4.540854943527318
3.659110169095442 -0.521473725226123 -4.556032908691503
3.673068563622878 -0.526471559789378 -4.549449575676061
…

And here is a snippet of my Pose file… 这是我的姿势文件的片段...

Snapshot Event ID: 0
Translation: -2.828956167382643 3.18717159105692 0.4915560231473033
Quarternion: 0.7047427543062862 0.6239282881689626 0.23707690815727211 0.2405112909905187
Accuracy: 4.2E-45
Confidence: 1688685432

Snapshot Event ID: 1
Translation: -2.796160158125086 4.193282171082194 0.5346153464487627
Quarternion: 0.4973877606777205 0.4648489837872261 0.515537924119383 0.520328248891662
Accuracy: 4.2E-45
Confidence: 1687633528

Snapshot Event ID: 2
Translation: -3.504446692020165 3.1853833575251675 0.5117019018999412
Quarternion: 0.6256551950823549 0.5778181469917516 -0.3583361921431137 -0.3824616834061323
Accuracy: 4.2E-45
Confidence: 1687858272 

Where snapshot ID is my method of linking the Pose data to a Point Cloud; 其中快照ID是我将Pose数据链接到点云的方法; and Quaternion is in the format WXYZ. 四元数的格式为WXYZ。

This generally works correct for individual Point Clouds I think and after I swap the Y and Z axis of each point in the Point Cloud I see this… 这通常适用于我认为的单个点云,并且在交换点云中每个点的Y和Z轴后,我会看到此…

真正的沙发图片 Original image 原始图片

点云沙发 Point cloud image (loaded in Cloud Compare) 点云图像(加载到Cloud Compare中)

Which is generally what I expect. 通常这是我所期望的。

The problem comes when I try to stich multiple PCs together to form a complete 3D interior of a building. 当我尝试将多台PC连接在一起以形成建筑物的完整3D内部时,就会出现问题。

I have translated the Point Clouds by adding the XY and Z coordinates from the corresponding Pose data to each XY and Z point in the Point Cloud accordingly. 我已经通过将相应的“姿势”数据中的XY和Z坐标添加到点云中的每个XY和Z点,来平移了点云。 Not sure if that's the right thing to do. 不知道这是否是正确的事情。 Then I swapped Y and Z as before. 然后像以前一样交换Y和Z。 Most Point Clouds are dumped on top of each other if I do that, but this is to be expected because I haven't (and am not sure how to) applied rotations yet. 如果这样做的话,大多数点云都可以相互叠加,但这是可以预期的,因为我还没有(也不确定如何)应用旋转。

Here is my general method for doing this… 这是我执行此操作的一般方法…

for (File file : files) {
    if (FilenameUtils.getExtension(file.getAbsolutePath()).equals("dat")) {
        PointCloud cloud = PointCloud.newInstance(file.toURI().toURL());
        if (poseMap.containsKey(cloud.getEventID())) {
            Pose pose = poseMap.get(cloud.getEventID());
            //cloud = cloud.rotate(pose);
            cloud = cloud.translate(pose);
        }
        cloud = cloud.invertYandZ();
        //cloud = cloud.invertAllAxis();
        String absFilename = ptsFolderTxt.getText() + '\\' + FilenameUtils.getBaseName(cloud.getFilename()) + ".pts";
        cloud.write(absFilename);

As you can see I have attempted a rotate method but it didn't seem to work so I commented it out. 如您所见,我尝试了Rotate方法,但是它似乎没有用,所以我将其注释掉。

The rotate method was applying this to each point… 旋转方法是将其应用于每个点...

ThreeDPoint rotatePoint(ThreeDPoint oldPoint)
{
    float ox = oldPoint.getxPoint().floatValue();
    float oy = oldPoint.getyPoint().floatValue();
    float oz = oldPoint.getzPoint().floatValue();

    float qx = quaternion.getX().floatValue();
    float qy = quaternion.getY().floatValue();
    float qz = quaternion.getZ().floatValue();
    float qw = quaternion.getW().floatValue();

    float newX = (float)((1-2*qy*qy-2*qz*qz)*ox+(2*qx*qy+2*qw*qz)*oy+(2*qx*qz-2*qw*qy)*oz);
    float newY = (float)((2*qx*qy-2*qw*qz)*ox+(1-2*qx*qx-2*qz*qz)*oy+(2*qy*qz+2*qw*qx)*oz);
    float newZ = (float)((2*qx*qz+2*qw*qy)*ox+(2*qy*qz-2*qw*qx)*oy+(1-2*qx*qx-2*qy*qy)*oz);

    return ThreeDPoint.newInstance(BigDecimal.valueOf(newX), BigDecimal.valueOf(newY), BigDecimal.valueOf(newZ));
}

But as I said, this didn't seem to work right? 但是正如我所说,这似乎行不通吗?

Is my method of translation OK? 我的翻译方法可以吗?

How do I use the quaternion in the pose file to rotate each PC? 如何使用姿势文件中的四元数旋转每台PC? Some code examples would be excellent. 一些代码示例将是极好的。

What order do I apply these Transforms? 我应按什么顺序应用这些转换?

A push in the right direction would be much appreciated. 向正确方向的推动将不胜感激。

What happened is that you didn't transform the point cloud in correct frame of reference. 发生的事情是您没有在正确的参照系中变换点云。 Use the solution in this post: Convert device pose to camera pose 使用本文中的解决方案: 将设备姿势转换为相机姿势

In the answer it's assuming OpenGL convention, but you can use similar technic to transform the point to any convention. 在答案中,它假定使用OpenGL约定,但是您可以使用类似的技术将点转换为任何约定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM