我想在从 wikitude sdk for Android 成功识别图像后在目标图像之上显示一张图像。
默认显示 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/