Wikitude SDK(Android Native)在识别目标图像后显示叠加图像

时间:2017-09-29 15:08:36

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

我希望在从wikitude sdk for Android成功识别图像后,在目标图像上显示一个图像。

enter image description here

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

1 个答案:

答案 0 :(得分:2)

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不满意,可以尝试使用Wikitude JS SDK或Unity插件。