如何调整ViewRenderable以匹配AugmentedImage大小?

问题描述 投票:0回答:1

[我正在Android上制作一个小型AR应用,以从快照中检测GIF并使用AugmentedImages覆盖实际的GIF,但是我无法获得ViewRenderable的大小来与检测到的图像相匹配,因此完美叠加。

我正在跟踪Google的AugmentedImages Sceneform sample,将其更改为Kotlin,并使用自己添加的图像手动添加到AugmentedImageDatabase

下面是我所能获得的最接近的数字,但是仍然不能完全匹配。 gifViewViewRenderable.builder()设置,并使用一个简单的XML文件,显示在代码块后面。我在构建器的.thenAccept中使用Glide来从URL加载正确的GIF。

AugmentedImageNode

private var gifView: ViewRenderable? = null
...
fun setImageToNode(image: AugmentedImage) {
    anchor = image.createAnchor(image.centerPose)

    gifView?.sizer = FixedHeightViewSizer(image.extentZ)

    val pose = Pose.makeTranslation(0.0f, 0.0f, 0.0f)
    val localPosition = Vector3(pose.tx(), pose.ty(), pose.tz())
    val centerNode = Node()
    centerNode.setParent(this)
    centerNode.localPosition = localPosition
    centerNode.localRotation = Quaternion(pose.qx(), 90f, -90f, pose.qw())
    centerNode.renderable = gifView
    centerNode.localScale = Vector3(image.extentX * 15f, image.extentZ * 30f, 1.0f)
}   

R.layout.image_item

<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/imageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/easy_button" />

没有出现错误消息,但是渲染的图像与检测到的图像尺寸不匹配。我希望这是动态的,因为显然不是每个GIF都有相同的尺寸。

请参见this screenshot,请注意,检测到的图像是如何稍大一些,看起来像是在较清晰的渲染图像周围形成边框? (与此问题无关,但是即使我设置了正确的配置设置,我的相机也无法自动对焦)

kotlin arcore sceneform android-augmented-reality
1个回答
0
投票

我找到了一种更精确地计算比例的方法。我采用的方法不是尝试缩放renderable / ImageView的大小以适合图像,而是改变世界的“比例”,以便无论图像有多少像素宽,它都是一样的以米为单位的大小作为检测到的增强图像。我基本上必须弄清楚,如果放大后的图像达到一定大小,那么一米将有多少像素。下面是我正在使用的代码:

© www.soinside.com 2019 - 2024. All rights reserved.