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

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

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

enter image description here

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

最佳答案

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 插件。

关于android - Wikitude SDK (Android Native) 识别目标图像后显示叠加图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46491806/

相关文章:

c# - 使用 restful wcf 将图像发送到 android 应用程序

android - Material 设计 : Where to place elevation in android styles?

unity-game-engine - Android 设备不支持 ARCore 但实际上可以使用 Vuforia 运行 AR?

android - 在 android studio 项目中集成 DroidAR 时 Gradle 构建错误

javascript - 英特尔 XDK,基于地理定位

android - Google Maps Android API v2 检测 map 上的长按并添加标记不起作用

java - 使用 Java 中的日历删除一天?

c++ - 自然标记增强现实实现

php - PHP 中的一个简单 Web 服务,Get 方法

javascript - Wikitude 与 Android Studio