ARKit 和 ARCore原理介绍(转)

转自:http://blog.csdn.net/qq_21158525/article/details/78052644?locationNum=8&fps=1

ARKit 和 ARCore 都是三部分:相机姿态估计, 环境感知(平面估计)及光源感知。

ARCore 的部分源码:https://github.com/google-ar/arcore-unity-sdk/tree/master/Assets/GoogleARCore/SDK

ARKit API:https://developer.apple.com/documentation/arkit

ARCore API:https://developers.google.com/ar/reference/

-相机姿态估计

Motion Tracking方面都是VIO.

ARKit 是特征点法,稀疏的点云:https://www.youtube.com/watch?v=rCknUayCsjk

ARKit recognizes notable features in the scene image, tracks differences in the positions of those features across video frames, and compares that information with motion sensing data. —-https://developer.apple.com/documentation/arkit/about_augmented_reality_and_arkit

ARCore 有猜测说是直接法估计的半稠密点云。但是google自己说是特征点,应该也是稀疏的了:

ARCore detects visually distinct features in the captured camera image calledfeature pointsand uses these points to compute its change in location.

—–https://developers.google.com/ar/discover/concepts

-环境感知(平面检测)

不太了解原理,摘了一些原文。

ARKit:

“…can track and place objects on smaller feature points as well…”

“…Use hit-testing methods (see theARHitTestResultclass) to find real-world surfaces corresponding to a point in the camera image….”

“You can use hit-test results ordetected planesto place or interact with virtual content in your scene.”

检测不了垂直面

ARCore:

“ARCore looks for clusters of feature points that appear to lie on common horizontal surfaces…”

“…can also determine each plane’s boundary…”

” …flat surfaces without texture, such as a white desk, may not be detected properly…”

没有解决遮挡:https://www.youtube.com/watch?v=aSKgJEt9l-0

-光源感知

暂时不了解。

ARKit

参考博文:http://blog.csdn.net/u013263917/article/details/72903174

IPhone X添加了TrueDepth camera,也支持 ARKit使用。

一、简介

ARKit 框架

基于3D场景(SceneKit)实现的增强现实(主流)

基于2D场景(SpriktKit)实现的增强现实

ARKit与SceneKit的关系

ARKit并不是一个独立就能够运行的框架,而是必须要SceneKit一起用才可以。

ARKit 实现相机捕捉现实世界图像并恢复三维世界

SceneKit 实现在图像中现实虚拟的3D模型

我们focus ARKit

二、ARKit

ARKit框架中中显示3D虚拟增强现实的视图ARSCNView继承于SceneKit框架中的SCNView,而SCNView又继承于UIKit框架中的UIView。

在一个完整的虚拟增强现实体验中,ARKit框架只负责将真实世界画面转变为一个3D场景,这一个转变的过程主要分为两个环节:由ARCamera负责捕捉摄像头画面,由ARSession负责搭建3D场景。

ARSCNView与ARCamera两者之间并没有直接的关系,它们之间是通过AR会话,也就是ARKit框架中非常重量级的一个类ARSession来搭建沟通桥梁的。

要想运行一个ARSession会话,你必须要指定一个称之为会话追踪配置的对象:ARSessionConfiguration, ARSessionConfiguration的主要目的就是负责追踪相机在3D世界中的位置以及一些特征场景的捕捉(例如平面捕捉),这个类本身比较简单却作用巨大。

ARSessionConfiguration是一个父类,为了更好的看到增强现实的效果,苹果官方建议我们使用它的子类ARWorldTrackingSessionConfiguration,该类只支持A9芯片之后的机型,也就是iPhone6s之后的机型

2.1. ARWorldTrackingSessionConfiguration 与 ARFrame

ARSession搭建沟通桥梁的参与者主要有两个ARWorldTrackingSessionConfiguration与ARFrame。

ARWorldTrackingSessionConfiguration(会话追踪配置)的作用是跟踪设备的方向和位置,以及检测设备摄像头看到的现实世界的表面。它的内部实现了一系列非常庞大的算法计算以及调用了你的iPhone必要的传感器来检测手机的移动及旋转甚至是翻滚。

ARWorldTrackingSessionConfiguration 里面就是VIO系统

这里文中提到的ARWorldTrackingSessionConfiguration在最新的iOS 11 beta8中已被废弃,因此以下更改为ARWorldTrackingConfiguration

当ARWorldTrackingSessionConfiguration计算出相机在3D世界中的位置时,它本身并不持有这个位置数据,而是将其计算出的位置数据交给ARSession去管理(与前面说的session管理内存相呼应),而相机的位置数据对应的类就是ARFrame

ARSession类一个属性叫做currentFrame,维护的就是ARFrame这个对象

ARCamera只负责捕捉图像,不参与数据的处理。它属于3D场景中的一个环节,每一个3D Scene都会有一个Camera,它觉得了我们看物体的视野。

2.2. ARSession

ARSession获取相机位置数据主要有两种方式

第一种:push。 实时不断的获取相机位置,由ARSession主动告知用户。通过实现ARSession的代理- (void)session:(ARSession)session didUpdateFrame:(ARFrame)frame来获取

第二种:pull。 用户想要时,主动去获取。ARSession的属性currentFrame来获取

2.3. ARKit工作完整流程

ARSCNView加载场景SCNScene

SCNScene启动相机ARCamera开始捕捉场景

捕捉场景后ARSCNView开始将场景数据交给Session

Session通过管理ARSessionConfiguration实现场景的追踪并且返回一个ARFrame

给ARSCNView的scene添加一个子节点(3D物体模型)

ARSessionConfiguration捕捉相机3D位置的意义就在于能够在添加3D物体模型的时候计算出3D物体模型相对于相机的真实的矩阵位置

三、API分析

-AROrientationTrackingConfiguration

tracks the device’s movement with three degrees of freedom (3DOF): specifically, the three rotation axes;只跟踪三个,不如下面的这个。

-[ARWorldTrackingConfiguration](https://developer.apple.com/documentation/arkit/arworldtrackingconfiguration)

负责跟踪相机,检测平面。tracks the device’s movement with six degrees of freedom (6DOF)。

完成slam工作的主要内容应该就是在这个里面。

但启动一个最简单的AR, 只需要:

let configuration = ARWorldTrackingConfiguration()configuration.planeDetection=.horizontalsceneView.session.run(configuration)

1

2

3

具体的实现还是被封装了。。。

-ARCamera

ARCamera类里有很多相关的Topics:

Tablescolscols

Handling Tracking StatustrackingStateThe general quality of position tracking available when the camera captured a frame.

ARTrackingStatePossible values for position tracking quality.

trackingStateReasonA possible diagnosis for limited position tracking quality as of when the camera captured a frame.

ARTrackingStateReasonPossible causes for limited position tracking quality.

Examining Camera GeometrytransformThe position and orientation of the camera in world coordinate space.

eulerAnglesThe orientation of the camera, expressed as roll, pitch, and yaw values.

Examining Imaging ParametersimageResolutionThe width and height, in pixels, of the captured camera image.

intrinsicsA matrix that converts between the 2D camera plane and 3D world coordinate space.

Applying Camera GeometryprojectionMatrixA transform matrix appropriate for rendering 3D content to match the image captured by the camera.

projectionMatrixForOrientation:Returns a transform matrix appropriate for rendering 3D content to match the image captured by the camera, using the specified parameters.

viewMatrixForOrientation:Returns a transform matrix for converting from world space to camera space.

projectPoint:orientation:viewportSize:Returns the projection of a point from the 3D world space detected by ARKit into the 2D space of a view rendering the scene.

-ARFrame

ARFrame 类里的Topics 可以看到slam输入输出接口

Tablescolscols

Accessing Captured Video FramescapturedImageA pixel buffer containing the image captured by the camera.

timestampThe time at which the frame was captured.

capturedDepthDataThe depth map, if any, captured along with the video frame.

capturedDepthDataTimestampThe time at which depth data for the frame (if any) was captured.

Examining Scene ParameterscameraInformation about the camera position, orientation, and imaging parameters used to capture the frame.

lightEstimateAn estimate of lighting conditions based on the camera image.

displayTransformForOrientation:Returns an affine transform for converting between normalized image coordinates and a coordinate space appropriate for rendering the camera image onscreen.

Tracking and Finding ObjectsanchorsThe list of anchors representing positions tracked or objects detected in the scene.

hitTest:types:Searches for real-world objects or AR anchors in the captured camera image.

Debugging Scene DetectionrawFeaturePointsThe current intermediate results of the scene analysis ARKit uses to perform world tracking.

ARPointCloudA collection of points in the world coordinate space of the AR session.

关于特征点通过ARPointCloud可以看到特征点的个数和identitiers;

究竟是用的什么特征点?可能需要看下identitiers的维数等信息。SIFT 特征的descriptor是128维。

-ARLightEstimate

ARCore

google 发布了对应 Android studio、 Unity、Unreal以及Web的环境的ARCore,我们只看Unity。

API 官网:https://developers.google.com/ar/reference/unity/

SDK on Github :https://github.com/google-ar/arcore-unity-sdk;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 158,736评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,167评论 1 291
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,442评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,902评论 0 204
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,302评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,573评论 1 216
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,847评论 2 312
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,562评论 0 197
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,260评论 1 241
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,531评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,021评论 1 258
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,367评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,016评论 3 235
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,068评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,827评论 0 194
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,610评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,514评论 2 269

推荐阅读更多精彩内容

  • ARkit Introducing ARKit iOS 11引入ARKit,这是 个全新的框架,允许开发者轻松地为...
    坤哥爱卿阅读 1,276评论 0 1
  • 做你喜欢的事,不用刻意坚持,一样可以做的很久很久 靠意志力来坚持着做一件内心不认可的事,估计幸福感不高,那又能坚持...
    罗兰花粉阅读 114评论 0 0
  • 目录: 这是一篇饱含私心的文章,从web安全学习中去理解演绎推理。 推理的过程 逻辑学家在人类有限的认知领域里做出...
    fatfatEddy阅读 440评论 0 2
  • 用户阅读文章详细页有截屏行为时,目前在产品上没有任何提示,是单纯的截屏自动保存到手机相册。而我们可以优化对用户截屏...
    桃小月阅读 607评论 12 0
  • 这是九瓣 365天写作计划第60天的写作内容。 我经常在朋友面前嚷嚷着要重回娘胎,回炉重造。这世界太他妈可怕了,我...
    九瓣阅读 1,009评论 0 0