首页 > 解决方案 > iOS 上的 Vuforia - 如何抓取相机帧

问题描述

我正在开发一个Vuforia SDK用于检测图像目标的应用程序。我还需要实现文本识别,我希望使用CoreML. 应用程序是代码的混合SwiftObjective-C。首先认为我需要做的是从运行Vuforia会话中获取相机帧。我想把它作为CVPixelBufferor UIImage。我认为这可能是从这个函数中获取的(你不确定):

- (void)renderFrameVuforia
{
    if(!_manager.isCameraStarted) {
        return;
    }

    // Render video background and retrieve tracking state
    const Vuforia::State state = Vuforia::TrackerManager::getInstance().getStateUpdater().updateState();
    Vuforia::Renderer::getInstance().begin(state);


    if(Vuforia::Renderer::getInstance().getVideoBackgroundConfig().mReflection == Vuforia::VIDEO_BACKGROUND_REFLECTION_ON)
    glFrontFace(GL_CW);  //Front camera
    else
    glFrontFace(GL_CCW);   //Back camera

    if(_currentRenderingPrimitives == nullptr)
    [self updateRenderingPrimitives];

    Vuforia::ViewList& viewList = _currentRenderingPrimitives->getRenderingViews();

    // Clear colour and depth buffers
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

    // Iterate over the ViewList
    for (int viewIdx = 0; viewIdx < viewList.getNumViews(); viewIdx++) {
        Vuforia::VIEW vw = viewList.getView(viewIdx);
        _currentView = vw;

        // Set up the viewport
        Vuforia::Vec4I viewport;
        // We're writing directly to the screen, so the viewport is relative to the screen
        viewport = _currentRenderingPrimitives->getViewport(vw);

        // Set viewport for current view
        glViewport(viewport.data[0], viewport.data[1], viewport.data[2], viewport.data[3]);

        //set scissor
        glScissor(viewport.data[0], viewport.data[1], viewport.data[2], viewport.data[3]);

        Vuforia::Matrix34F projMatrix = _currentRenderingPrimitives->getProjectionMatrix(vw, state.getCameraCalibration());

        Vuforia::Matrix44F rawProjectionMatrixGL = Vuforia::Tool::convertPerspectiveProjection2GLMatrix(
                                                                                                        projMatrix,
                                                                                                        _nearPlane,
                                                                                                        _farPlane);

        // Apply the appropriate eye adjustment to the raw projection matrix, and assign to the global variable
        Vuforia::Matrix44F eyeAdjustmentGL = Vuforia::Tool::convert2GLMatrix(_currentRenderingPrimitives->getEyeDisplayAdjustmentMatrix(vw));

        Vuforia::Matrix44F projectionMatrix;
        VuforiaEAGLViewUtils::multiplyMatrix(&rawProjectionMatrixGL.data[0], &eyeAdjustmentGL.data[0], &projectionMatrix.data[0]);

        if (_currentView != Vuforia::VIEW_POSTPROCESS) {
            [self renderFrameWithState:state projectMatrix:projectionMatrix];
        }

        glDisable(GL_SCISSOR_TEST);

    }

    Vuforia::Renderer::getInstance().end();
}

有人可以指导我如何CVPixelBuffer从此类Vuforia会议中获得信息吗?

标签: iosobjective-cvuforia

解决方案


推荐阅读