【问题标题】:Wikitude SDK (Android Native) show overlay image after target image is recognizedWikitude SDK (Android Native) 识别目标图像后显示叠加图像
【发布时间】:2017-09-29 15:08:35
【问题描述】:

从 wikiitude sdk for Android 成功识别图像后,我想在目标图像上显示一张图像。

默认显示StrokedRectangle。我在文档中找不到任何关于显示图像的明确想法。所以一些建议将不胜感激。

【问题讨论】:

    标签: android augmented-reality wikitude android-augmented-reality wikitude-sdk


    【解决方案1】:

    Wikitude Native SDK 仅渲染相机和试用水印。 StrokedRectangle 是示例应用程序的一部分。

    您必须使用 OpenGL 来绘制图像。也许这个tutorial 会帮助你。

    public static int loadTexture(final Context context, final int resourceId)
    {
        final int[] textureHandle = new int[1];
    
        GLES20.glGenTextures(1, textureHandle, 0);
    
        if (textureHandle[0] != 0)
        {
            final BitmapFactory.Options options = new BitmapFactory.Options();
            options.inScaled = false;   // No pre-scaling
    
            // Read in the resource
            final Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);
    
            // Bind to the texture in OpenGL
            GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[0]);
    
            // Set filtering
            GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST);
            GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST);
    
            // Load the bitmap into the bound texture.
            GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
    
            // Recycle the bitmap, since its data has been loaded into OpenGL.
            bitmap.recycle();
        }
    
        if (textureHandle[0] == 0)
        {
            throw new RuntimeException("Error loading texture.");
        }
    
        return textureHandle[0];
    }
    

    这是来自 Wikitude 示例应用程序的顶点着色器,用于显示如何放置纹理:

    attribute vec4 v_position;
    uniform mat4 Projection; // from ImageTarget
    uniform mat4 ModelView;  // from ImageTarget
    uniform mat4 Scale;      // create scale matrix based on ImageTarget.getTargetScale
    void main()
    {
      gl_Position = Projection * ModelView * Scale * v_position;
    };
    

    如果您对 OpenGL 不满意,可以尝试 Wikiitude JS SDK 或 Unity 插件。

    【讨论】:

    • 好的。我将查看 Wikiitude JS SDK。
    猜你喜欢
    • 1970-01-01
    • 2018-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-09
    • 2018-12-11
    • 2015-02-03
    • 1970-01-01
    相关资源
    最近更新 更多