iOS上的Vuforia-如何抓取相机框架

时间:2018-09-05 10:18:33

标签: ios objective-c vuforia

我正在开发一个使用Vuforia SDK来检测图像目标的应用程序。我还需要实现文本识别,这是我希望使用CoreML来实现的。应用程序是SwiftObjective-C代码的混合。首先,我需要做的是从运行Vuforia会话中获取相机框架。我想将其设为CVPixelBufferUIImage。我认为这可以从此功能中获取(不确定):

- (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吗?

0 个答案:

没有答案