ARKit:在距相机特定 Z 距离的特定像素处绘制节点 [英] ARKit: Plot a Node at a specific pixel at a specific Z distance from Camera

查看:18
本文介绍了ARKit:在距相机特定 Z 距离的特定像素处绘制节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

参考上图.我在屏幕中央有一个红色节点,距离为 1.0 个单位(1 米远)[见 iPhone 纵向顶视图]

Referring to the image above. I have a Red Node at the center of the screen with a distance of 1.0 unit (1 meter away) [See iPhone Portrait Top View]

我所做的是截取 iPhone 屏幕的屏幕截图,生成的图像为 750 x 1334 像素 [请参阅 iPhone 纵向前视图]

What I do is I capture a screenshot of the iPhone screen and the resulting image is 750 x 1334 pixels [See iPhone Portrait Front View]

sceneView.snapshot()

我想要做的是在 iPhone 屏幕相对于红圈的四边(屏幕的死点)放置 4 个红方节点.我做这个是为了标记我在哪里做快照.我想知道的是如何在给定 z 距离的某个 x,y 点处精确地绘制一个框节点.(Z 的值不固定,我只是使用 1.0 作为示例场景).我想在给定的位置绘制 (0,0)、(750,0)、(0, 1334) 和 (750, 1334)z 为 1.0 并假设我在三脚架上,绘制的节点将出现在我 iPhone 屏幕的四个边上.

What I want to do is put 4 Red Square Nodes located on the four sides of the iPhone screen relative to the Red Circle (at the dead center of the screen). I am making this to mark where I did a snapshot. What I want to know is how can I plot a box node precisely at a certain x,y point given z distance. (The value of Z is not fixed, I just used 1.0 as a sample scenario).. I want to plot (0,0), (750,0), (0, 1334) and (750, 1334) at a given z of 1.0 and assuming I am on a tripod, the plotted nodes would appear on the four sides of my iPhone screen.

我的数学很差,这个问题太复杂了,以我目前的数学技能无法单独解决.任何人都可以帮忙吗?请?

I am very terrible at math and this problem is so complicated for me to solve alone with my current math skills. Can anyone help? Please?

推荐答案

因为您需要使用来自相机的实时信息而不是快照的 ARnchor 节点(以标记快照完成的位置)可能会更容易.特别是由于 2D 图像中的像素是从左到右和从上到下引用的(0,0"坐标位于左上角)...我们知道 AR 节点在 3D 坐标中引用,本地节点的中心为 0,0,0 坐标.

Since you need ARnchor nodes (to mark where a snapshot was done) using the real time information from the camera instead of a snapshot would be probably easier. In special due to pixels in a 2D image are referenced from left to right and from top to bottom (with "0,0" coords located in the top left side) ... and we know the AR nodes are referenced in 3D coordinates with the center of the local node as the 0,0,0 coords.

我还没有要测试的代码,但我认为以下属性应该会有所帮助:

I haven't yet code to test but I think the following properties should help:

    let pPoint  = sceneView.projectPoint(self.centerBall.position)
    let fieldW  = sceneView.session.currentFrame?.camera.imageResolution.width
    let fieldH  = sceneView.session.currentFrame?.camera.imageResolution.height

pPoint"应该返回对应于centerBall"的 (0,0,0) 3D 坐标的 2D 坐标,它应该只是添加或减去计算以获得 2D 中的所有 4 个角

The "pPoint" should return the 2D coords corresponding to the (0,0,0) 3D coords of "centerBall" from there it should be just add or subtract calculations to obtain all 4 corners in 2D

最后将每个角落的 2D 坐标传递给unprojectPoint(:)"方法应该提供 3D世界"坐标,并且可以使用convertPosition("将其转换为centerBall"坐标位置:SCNVector3,来自节点:SCNNode?)"方法

Finally passing the 2D coords of every corner to the "unprojectPoint(:)" method should provide the 3D "world" coords and that can be converted to "centerBall" coordinates with the "convertPosition( position: SCNVector3, from node: SCNNode?)" method

看起来很有趣,所以会在周末之前尝试编写代码

It seems interesting so will try to code this before weekend

最后我怀疑 ARanchor 节点可能不是 100% 稳定

At the end I suspect ARanchor nodes may not be 100% stables

这篇关于ARKit:在距相机特定 Z 距离的特定像素处绘制节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆