Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Kotlin 如何调整ViewRenderable以匹配增强图像大小?_Kotlin_Arcore_Sceneform_Android Augmented Reality - Fatal编程技术网

Kotlin 如何调整ViewRenderable以匹配增强图像大小?

Kotlin 如何调整ViewRenderable以匹配增强图像大小?,kotlin,arcore,sceneform,android-augmented-reality,Kotlin,Arcore,Sceneform,Android Augmented Reality,我正在Android上制作一个小型AR应用程序,从快照中检测GIF,并使用AugmentedImages覆盖实际GIF,但我无法获得ViewRenderable的大小,以匹配检测到的图像,从而使其完全覆盖 我正在跟踪来自Google的,将其更改为Kotlin,并使用手动添加到AugmentedImageDatabase中的我自己的图像 下面是我能得到的最接近的,但它仍然不完全匹配gifView使用ViewRenderable.builder()设置,并使用一个简单的XML文件,显示在代码块之后。

我正在Android上制作一个小型AR应用程序,从快照中检测GIF,并使用
AugmentedImages
覆盖实际GIF,但我无法获得
ViewRenderable
的大小,以匹配检测到的图像,从而使其完全覆盖

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

下面是我能得到的最接近的,但它仍然不完全匹配
gifView
使用
ViewRenderable.builder()
设置,并使用一个简单的XML文件,显示在代码块之后。我在生成器的
中使用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\u项目


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


查看并注意到检测到的图像略大,并且看起来像是在更清晰的渲染图像周围制作边框?(与此问题无关,但我的相机没有自动对焦,即使我设置了正确的配置设置)

我找到了一种更精确地计算比例的方法。我采用了这种方法,而不是尝试缩放可渲染的/
ImageView的大小以适应图像,我只是改变世界的“比例”,这样无论图像有多少像素宽,它都与检测到的增强图像大小相同(以米为单位)。我基本上必须计算出,如果放大后的图像有一定的尺寸,一米有多少像素。下面是我正在使用的代码:

val imageWidth = 400 // TODO Get actual width of image dynamically, just luck that GIPHY images are 400 pixels wide
val viewWidth = (imageWidth / image.extentX).toInt()
gifView?.sizer = DpToMetersViewSizer(viewWidth)

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
这使得渲染的GIF更接近检测到的图像的实际大小。我会继续寻找更好的方法