繁体   English   中英

如何捕获ARCore中的每一帧

[英]How to capture every frame in ARCore

有什么解决方案可以将ARCore中的每个SceneView捕获为位图数组或类似的东西? 我想保存ARCamera捕获的每个帧,以便将来处理它们。

问题在于,使用当前代码,我的性能负担很重,这首先会使应用程序变慢,然后导致应用程序崩溃。 我是android / Java的新手,所以我不知道哪里错了。

除此之外,还有其他令人惊讶的事情。 当我记录负责将ARSenceview复制到bitmapsarray中的takePhoto()函数内部块时,每个函数调用的时间戳差异并不相同,而是等于1s / 30frame,尽管对我来说捕获图像非常重要。固定比率。

当应用程序处于捕获模式时,我每帧调用一次此函数。 一个可能的错误应该是由于在这里获取大量线程。

    private void takePhoto()
    {
        view = arFragment.getArSceneView();

        // NOTE: Create a handler thread to offload the processing of the image
        final HandlerThread handlerThread = new HandlerThread("PixelCopier");
        handlerThread.start();

        // NOTE: Make request to copy
        PixelCopy.request(view, bitmap, copyResult -> {
            if(copyResult == PixelCopy.SUCCESS)
            {
                bitmapsBuffer[bufferIndex] = bitmap;
                bufferIndex++;
                if(bufferIndex == 120)
                {
                    bufferIndex = 0;
                    FlushBitmapsBuffer();
                }
            }
            else
            {
                messenger.message("Failed to copyPixel: " + copyResult);
            }
            handlerThread.quitSafely();
        }, new Handler(handlerThread.getLooper()));
    }

然后收集120帧后,我尝试使用其他服务在SD上写入位图的临时数组。

    private void FlushBitmapsBuffer()
    {
        Intent intent = new Intent(MainActivity.this, DataCopyService.class);
        intent.putExtra("BitmapsBuffer", bitmapsBuffer);
        intent.putExtra("StorageDataRoot",
                storageData.getRootDir());
        intent.putExtra("StorageDataProj",
                storageData.getProjectDir().getAbsolutePath());
        startService(intent);
    }

该服务的工作方式如下:

    @Override
    public int onStartCommand(Intent intent, int flags, int startId)
    {
        messenger.log("Service " + TAG + " started.");

        bitmapsBuffer = (Bitmap[]) intent.getParcelableArrayExtra("BitmpasBuffer");

        File file;
        file = new File(intent.getStringExtra("StorageDataRoot"));
        storageData.setRootDir(file);
        file = new File(intent.getStringExtra("StorageDataProj"));
        storageData.setProjectDir(file);

        new Thread(new Runnable() {
            @Override
            public void run() {
                messenger.log("Service inner thread.");
                // Save the data here using a file manager class
                stopSelf();
            }
        }).start();

        return Service.START_STICKY;
    }

有人对我在做什么错有任何想法。

支持使用Sceneform捕获帧SceneView.startMirroringToSurface() 这会将当前视图每帧渲染到一个表面。

在“ 录像样本”中使用它来捕获视频。

暂无
暂无

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

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