ARCore:获取所有检测点的3D坐标
创始人
2024-09-12 10:31:19
0

要获取ARCore中所有检测点的3D坐标,可以使用以下代码示例:

import com.google.ar.core.Frame;
import com.google.ar.core.PointCloud;
import com.google.ar.core.Session;
import com.google.ar.core.TrackingState;
import com.google.ar.core.exceptions.NotYetAvailableException;
import java.nio.FloatBuffer;

public class ARPointCloudUtils {

    public static float[] getAllPointCloudPoints(Session session) {
        Frame frame = session.update();
        PointCloud pointCloud = frame.acquirePointCloud();

        FloatBuffer points = pointCloud.getPoints();
        float[] pointCloudPoints = new float[points.remaining()];
        points.get(pointCloudPoints);

        pointCloud.release();

        return pointCloudPoints;
    }

    public static void main(String[] args) {
        Session session = new Session();
        session.resume();

        float[] pointCloudPoints = getAllPointCloudPoints(session);

        for (int i = 0; i < pointCloudPoints.length; i += 4) {
            float x = pointCloudPoints[i];
            float y = pointCloudPoints[i + 1];
            float z = pointCloudPoints[i + 2];
            float confidence = pointCloudPoints[i + 3];
            
            if (confidence > 0.5 && TrackingState.forNumber((int) confidence) == TrackingState.TRACKING) {
                System.out.println("Point " + (i / 4) + ": (" + x + ", " + y + ", " + z + ")");
            }
        }

        session.pause();
    }
}

上述代码示例中,我们使用ARCore的FramePointCloud类来获取当前帧的点云数据。然后,我们将点云数据存储在一个FloatBuffer中,再将其转换为一个浮点数组pointCloudPoints。最后,我们遍历该数组,通过每4个元素(x、y、z和confidence)获取每个点的3D坐标,并打印出来。

请注意,上述代码示例仅为了演示目的,实际使用时需要根据自己的需求进行适当修改和调整。另外,要使上述代码正常工作,需要提供ARCore SDK的依赖项和正确的配置。

相关内容

热门资讯

透视ai代打!wpk辅助软件多... 《透视ai代打!wpk辅助软件多少钱一个,hhpoker德州有挂吗,专业教程(最初是真的有挂)》 w...
透视模拟器!aapoker辅助... WePoker透视辅助版本稳定性对比与推荐‌:透视模拟器!aapoker辅助插件工具下载,wepok...
透视真的!wpk透视脚本下载,... 透视真的!wpk透视脚本下载,hhpoker外挂靠谱吗,德州教程(切实真的是有挂);支持2-10人实...
透视插件!wepoker辅助器... 透视插件!wepoker辅助器是真的的吗,wepokerplus开挂,新2025教程(最初真的有挂)...
透视有挂!红龙poker透视,... 透视有挂!红龙poker透视,hhpoker真的有透视吗,软件教程(起初是有挂);大神普及一款德州a...
透视ai代打!德普之星app安... 透视ai代打!德普之星app安卓版破解版,德普之星有辅助软件吗,普及教程(固有有挂);德普之星app...
辅助透视!wpk脚本辅助器,w... 辅助透视!wpk脚本辅助器,wepoker软件靠谱么,爆料教程(起初有挂)关于wpk脚本辅助器的基本...
透视新版!aapoker辅助插... 透视新版!aapoker辅助插件工具,来玩app破解版,曝光教程(本然是有挂);aapoker辅助插...
透视最新!aapoker辅助挂... 透视最新!aapoker辅助挂,hhpoker辅助挂下载,我来教教你(固有有挂)1、许多玩家不知道a...
透视透视!智星菠萝辅助器,we... 透视透视!智星菠萝辅助器,wepoker游戏下载,插件教程(其实是真的有挂);超受欢迎的智星菠萝辅助...