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

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

问题描述

请参考上图.我在屏幕中央有一个红色节点,距离为1.0单位(1米远).[请参阅iPhone Portrait Top View]

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屏幕相对于Red Circle的四个侧面(位于屏幕的死点)放置4个Red Square节点.我这样做是为了标记我做快照的位置.我想知道的是,如何在给定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天全站免登陆