TENSORFLOW.JS 3D姿态估计无法工作。

3

一年前,我使用OpenCV和Mediapipe在Python中完成了很多姿势估计。最近我读了Tensorflow博客(https://blog.tensorflow.org/2021/08/3d-pose-detection-with-mediapipe-blazepose-ghum-tfjs.html),关于可能实现三维姿势估计的内容。这引起了我的兴趣,所以我学了一点JavaScript开始我的旅程。经过3天的尝试,我意识到我的代码不起作用,JavaScript没有报错,但什么都没发生。我与一个已经使用JavaScript一个月的朋友密切合作,但他无法帮助我,因为他从未涉及过AI。我从未接触过它,所以我不知道在JS中await如何工作。这可能是个问题呢。

    <body>
        <div id="app"></div>
        <video id="video" controls><source src="vid.mp4" type="video/mp4"/></video>
        <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/pose-detection"></script>
        <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core"></script>
        <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-converter"></script>
        <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgl"></script>
        <script src="https://cdn.jsdelivr.net/npm/@mediapipe/pose"></script>
    <script>
        const model = poseDetection.SupportedModels.BlazePose;
        const detectorConfig = {
          runtime: 'tfjs',
          modelType: 'full'
        };
        const detector = await poseDetection.createDetector(model, detectorConfig);
        const video = document.getElementById('video');
        const poses = await detector.estimatePoses(video);
        document.getElementById("app").innerHTML = str(poses[0].keypoints3D);
    </script>
    </body>

我的目标是将检测到的姿势数组“打印”到屏幕上,以便我可以看到它是否起作用。有什么想法吗?
    import * as poseDetection from '@tensorflow-models/pose-detection';
    import '@mediapipe/pose';
    
    async function estimatePosesOfVideo(videoelement) {
        const model = poseDetection.SupportedModels.BlazePose;
        const detectorConfig = {runtime:'mediapipe',modelType:'full'};
        const detector = await poseDetection.createDetector(model, detectorConfig);
        const poses = await detector.estimatePoses(videoelement);
        return poses
    }
    
    const videoelement = document.getElementById('video');
    const poses = estimatePosesOfVideo(videoelement);
    
    console.log(poses)

这里插入图片描述

我对这些完全没有头绪。


我也遇到了同样的问题,你找到出错的原因了吗? - Omnia69
1个回答

1
我建议在测试时使用console.log。这将打印您输入的内容到检查器中(Crtl+Shift+I)。 或者,您可以使用document.innerText来“打印”出一些内容。
编辑回复
首先,您的异步函数estimatePosesOfVideo返回一个Promise,所有异步函数都是如此。当将结果打印到控制台时,您实际上是在打印Promise对象。我建议改用promise对象的.then方法。
关于其他问题,由于我缺乏关于错误发生在哪一行的信息,很难给出任何有意义的答复。请在代码框内添加该信息作为注释,或通过其他方式添加。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接