ARKit 与 ARCore比对(三)
ARKit 和 ARCore剖析、结构、原理介绍
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 (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(ARCore检测捕获的摄像机图像中视觉上不同的特征,称为特征点,并使用这些点计算其位置变化。) detects visually distinct features in the captured camera image called feature points and 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 the ARHitTestResult class) to find real-world surfaces corresponding to a point in the camera image….”
“You can use hit-test results or detected planes to place or interact with virtual content in your scene.”“...可以在较小的特征点上跟踪和放置对象...”
“...使用命中测试方法(请参阅ARHitTestResult类)来查找与相机图像中的点相对应的真实世界曲面...”。
“您可以使用命中测试结果或检测到的飞机来放置或与场景中的虚拟内容交互。”
检测不了垂直面检测不了垂直面
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…”“ARCore寻找似乎位于普通水平表面上的特征点集群...”
“...还可以确定每架平面的边界...”
“......没有纹理的平坦表面,如白色书桌,可能无法正确检测到......”demo视频: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 = .horizontal
sceneView.session.run(configuration)
- 1
- 2
- 3
具体的实现被封装了。
然后与重要的ARSession类和ARSCNView的接口:
由于接口很多,只列部分,详细的转官网or参考博文:http://blog.csdn.net/u013263917/article/category/6959089
苹果有个自己的特色功能,Face-based AR experience。可以使用TrueDepth camera追踪人脸的表情,pose, topology等。world based AR experience 对应其它厂商的sdk,比如ARCore。
比如一些常用的信息接口:
虚拟物体的位置,ARFrame–>ARAnchor中有transform
相机的位置,ARFrame–>ARCamera 中displayTransform包含位姿
视图矩阵,投影矩阵:ARFrame–>ARCamera 中有projectMatrix,viewMatrix
-ARSession
Tables | cols | cols |
---|---|---|
Configuring and Running a Session | func run(ARConfiguration, options: ARSession.RunOptions =) | Starts AR processing for the session with the specified configuration and options. |
var configuration: ARConfiguration | An object that defines motion and scene tracking behaviors for the session. | |
Responding to AR Updates | var delegate: ARSessionDelegate | An object you provide to receive captured video images and tracking information, or to respond to changes in session status. |
protocol ARSessionDelegate | Methods you can implement to receive captured video frame images and tracking state from an AR session. | |
Displaying and Interacting with AR Content | var currentFrame: ARFrame | |
func add(anchor: ARAnchor) | Adds the specified anchor to be tracked by the session. |
-ARSCNView
ARSCNView即用户见到的界面。
Tables | cols | cols |
---|---|---|
var session: ARSession | The AR session that manages motion tracking and camera image processing for the view’s contents. | |
var scene: SCNScene | The SceneKit scene to be displayed in the view. | |
Responding to AR Updates | protocol ARSCNViewDelegate | Methods you can implement to mediate the automatic synchronization of SceneKit content with an AR session. |
func hitTest(CGPoint, types: ARHitTestResult.ResultType) | Searches for real-world objects or AR anchors in the captured camera image corresponding to a point in the SceneKit view. |
-ARCamera
ARCamera类里有很多相关的Topics:
Tables | cols | cols |
---|---|---|
Handling Tracking Status | trackingState | The general quality of position tracking available when the camera captured a frame. |
ARTrackingState | Possible values for position tracking quality. | |
Examining Imaging Parameters | imageResolution | The width and height, in pixels, of the captured camera image. |
Applying Camera Geometry | projectionMatrix | A 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. |
-ARFrame
ARFrame 类里的Topics 可以看到slam输入输出接口
Tables | cols | cols |
---|---|---|
Accessing Captured Video Frames | capturedImage | A pixel buffer containing the image captured by the camera. |
capturedDepthData | The depth map, if any, captured along with the video frame. | |
Examining Scene Parameters | camera | Information about the camera position, orientation, and imaging parameters used to capture the frame. |
lightEstimate | An 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 Objects | anchors | The 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 Detection | rawFeaturePoints | The current intermediate results of the scene analysis ARKit uses to perform world tracking. |
ARPointCloud | A 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。
API 官网:https://developers.google.com/ar/reference/。
SDK on Github :https://github.com/google-ar;
2017.12.15更新:google 添加了java ,C平台的支持。(原来的Android Studio部分放到了Java里)
ARCore的结构比较灵活,
AR中,在一个真实场景中绘制一个虚拟物体,在绘制之前,开发者所必需知道的信息:
虚拟物体的位置姿态
视图矩阵,投影矩阵
虚拟物体的光照信息
这些信息都可以从ARCore中得到。我们先看google提供的java平台里的Sample。
先理一下Sample里的绘制逻辑,关于绘制的类有:
BackgroundRenderer用于绘制摄像头采集到的数据。
VirtualObject用于绘制Android小机器人。
VirtualObjectShadow用于给Android机器人绘制阴影。
PlaneRenderer用于绘制SDK识别出来的平面。
PointCloud用于绘制SDK识别出来的点云。
采用的是Opengl ES绘制:配置GLSurfaceView,实现GLSurfaceView.Renderer接口。关于绘制的部分都可以替换,可以用一些更现代化的3D图形框架等。
提一下Renderer接口;
`public interface Renderer {
void onSurfaceCreated(GL10 gl, EGLConfig config);
void onSurfaceChanged(GL10 gl, int width, int height);
void onDrawFrame(GL10 gl);
}
onSurfaceCreated这个方法在可绘制表面创建或重新创建的时候被调用。在这个回调里,可以做一些初始化的事情。注意,此方法运行在OpenGL线程中,具有OpenGL上下文,因此这里可以进行执行OpenGL调用。
onSurfaceChanged 这个方法在可绘制表面发生变化的时候被调用。此时外部可能改变了控件的大小,因此我们需要在这个调用里更新我们的视口信息,以便绘制的时候能准确绘制到屏幕中来。
void onDrawFrame 核心方法。在绘制的时候调用。每绘制一次,就会调用一次,即每一帧触发一次。这里是主要的绘制逻辑。
参考:https://juejin.im/post/59ac1f2bf265da249517ac72
具体的实现见Sample吧。
获取虚拟物体的POSE,ViewMatrix 和ProjectMatrix以及光照这些必要信息的具体接口:
我们先看java平台。https://developers.google.com/ar/reference/java/com/google/ar/core/package-summary
虚拟物体的Pose:
ARCore规定,当你想放置的虚拟对象,你需要定义一个 锚Anchor,以确保ARCORE跟踪对象的位置随着时间的推移。
Anchor类
getPose就可以得到Anchor的当前位置。Sample 里调用 anchor.getPose().toMatrix(mAnchorMatrix, 0);得到了Anchor的位置矩阵,一个4x4 model-to-world transformation matrix, stored in column-major order。
视图矩阵和投影矩阵:
Camera类存储了这些信息:
Camera的属性会随着Session.update() is called update. 所以我们再看下Session类如何更新Camera。
Session类,Session类管理着AR 系统的状态, Session is the main entry point to ARCore API.
最后的update() 更新ARCore系统的状态,包括得到一个新的camera frame,更新device的位置,更新Anchor的位置,更新检测到的平面。新的camera 属性通过frame的getCamera()得到。
Frame类
hitTest是google的命中测试接口,检测用户是否点击到平面,是否加载虚拟物体。
光照暂时不关心。
C平台与Java 大同小异。
Session类:
Frame类,包括了Java中的Frame,Camera,HitResult,光照等类:
Anchor包括在Trackable类里:
相关文章:
前端开发之retina屏幕
像素 && ppi 首先先说一下pixel(picture element),显示图像的最小单位,有多个带色彩的像素点组成的整体就是一张图像。然后再说一下ppi(pixel per inch)这个概念,其实就是在每英寸显示的像素数。 设备像素 && 逻辑像素 &…

【ACM】Uva 1152 (4 Values whose Sum is 0) 二分查找lower_bound() 和upper_bound()的使用
【问题描述】 The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute how many quadruplet (a, b, c, d) ∈ A B C D are such that a b c d 0. In the following, we assume that all lists have the same size n. …

广东“基因编辑婴儿事件”调查组:将对贺建奎依法依规严肃处理
雷锋网(公众号:雷锋网)消息,1 月 21 日,新华社报道了关于“基因编辑婴儿事件”的初步调查结果,该结果宣称,该事件是南方科技大学副教授为了追逐个人名利而进行的人类胚胎基因编辑活动;而在此过程中…

测试我的第一个随笔
# encodingutf-8## Python Version 3.5# 利用数学中的复数 求解 一元一次方程(从网上看来的)def solve(qx, var): qx qx.replace(, -() ) c eval(qx , {var: 1j}) return -c.real/c.imagres solve(2*x 4 8,x)print(res)转载于:https://www.cnblogs.com/imyjy/p/…

ubuntu16.04 下安装Opencv2.4.9
ubuntu16.04 下安装Opencv2.4.9 OpenCV的源码download from: https://sourceforge.net/projects/opencvlibrary/?sourcetyp_redirect[plain] view plaincopycd opencv-2.4.9 mkdir build sudo chmod -R 777 build cd build [plain] view plaincopycmake -D CMAKE_…

UVa 167(八皇后)、POJ2258 The Settlers of Catan——记两个简单回溯搜索
UVa 167 题意:八行八列的棋盘每行每列都要有一个皇后,每个对角线上最多放一个皇后,让你放八个,使摆放位置上的数字加起来最大。 参考:https://blog.csdn.net/xiaoxiede_wo/article/details/79973171 1 #include <io…
AR + ROS +UBUNTU16.04+ORB-SLAM2
ORB SLAM2 USB摄像头 实验环境ubuntu 16.04ros kinetic OPencv2.4.9 Step1: 配置环境变量 $ mkdir -p ~/catkin_ws/src $ cd ~/catkin_ws/src 在’src’目录中可能没有任何软件包,只有一个CMakeLists.txt,依然可以编译它: …

Cross-validation
2019独角兽企业重金招聘Python工程师标准>>> 1: Introduction To Validation So far, weve been evaluating accuracy of trained models on the data the model was trained on. While this is an essential first step, this doesnt tell us much about how well …

【ACM】杭电OJ 1877 又一版A+B(进制转换)
注意:A和B都是0的情况 A和B为int也可以AC #include<cstdio> #include <iostream> using namespace std;const int maxn 10000;int a[maxn];int main() {long long A,B;int m,k;while(scanf("%d",&m)!EOF){if(m0) return 0;scanf("…

[POI2009]KAM-Pebbles BZOJ1115 [ 待填坑 ] 博弈
有N堆石子,除了第一堆外,每堆石子个数都不少于前一堆的石子个数。两人轮流操作每次操作可以从一堆石子中移走任意多石子,但是要保证操作后仍然满足初始时的条件谁没有石子可移时输掉游戏。问先手是否必胜。 感谢MT大牛翻译. Sample OutputNIE…

ROS中使用摄像头的问题
ROS中使用摄像头的问题 0.prepare 4 . 安装uvc_cam $ sudo apt-get install ros-indigo-uvc-camera $ source /opt/ros/indigo/setup.bash 采用apt-get的方式,直接装在了ROS的安装路径中,并设置工作路径。 安装成功后在/opt/ros/hydro/的路径中就…

EmEditor Professional(文本编辑) 下载地址
http://www.greenxf.com/soft/2126.html 16.1.5 http://www.cr173.com/soft/3031.html 16.3.0 http://www.pc6.com/softview/SoftView_43146.html 17.8.1 绿色注册版 EmEditor 71 个实用插件汉化版 http://www.onlinedown.net/soft/35609.htm

【ACM】杭电OJ 4548 美素数(二次打表)
二次打表,第一次是标记哪些是素数,哪些不是。 第二次是前n个数中 “本身是素数 && 各个位上的和是素数 ” 的个数 TLE: #include <iostream> #include <cstdio> using namespace std;int fun1(int x) {int sum0…

animation与transition区别
transition: 过渡属性 过渡所需要时间 过渡动画函数 过渡延迟时间;默认值分别为:all 0 ease 0 1、局限性: 1)只能设置一个属性 2)需要伪类/事件触发才执行 3)只能设置动画初始值和结束值 2、过…

如何将cocos2d-x程序分别移植到ios,android,windowsphone三个手机平台上
作者:方格子链接:https://www.zhihu.com/question/21505500/answer/22152464来源:知乎著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。面向android的移植 0. 这移植过程简直…… 1. 完成以上工具的下载安装…

【数据结构】顺序循环队列及其实现(C语言)
给定一个大小为MAXSIZE的数组储存一个队列,经过若干次的插入和删除以后,当队尾指针 rear MAXSIZE 时,呈现队列满的状态,而事实上数组的前部可能还有空闲的位置。为了有效地利用空间,引入循环队列(环状&…

C++中Reference与指针(Pointer)的使用对比
了解引用reference与指针pointer到底有什么不同可以帮助你决定什么时候该用reference,什么时候该用pointer。在C 中,reference在很多方面与指针(pointer)具有同样的能力。虽然多数C程序员对于何时使用reference何时使用pointer 都会有一些直觉࿰…
云南实现手机自主补(换)领居民身份证
图为云南首位通过手机自主补领居民身份证的申领人付宏强。 缪超 摄 中新网昆明1月22日电 (缪超)春节临近,云南实现手机自主补(换)领居民身份证,首张通过手机补办的居民身份证于22日在武定县公安局狮山派出所成功申领。 据悉,为方便民众因遗失…
NDK JNI 安装与配置(一)(UBUNTU16.04 )
1、下载Android NDK自解压包,官方地址:https://developer.android.com/ndk/downloads/index.html#download下载:$ wget -c http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86_64.bin2、解压,将Android NDK压缩包解压到…

【数据结构】顺序表的应用(4)(C语言)
【数据结构】顺序表的应用(1)(C语言) 【数据结构】顺序表的应用(2)(C语言) 【数据结构】顺序表的应用(3)(C语言) 设计一个算法&…

Java泛型:泛型类、泛型接口和泛型方法
2019独角兽企业重金招聘Python工程师标准>>> 根据《Java编程思想 (第4版)》中的描述,泛型出现的动机在于:有许多原因促成了泛型的出现,而最引人注意的一个原因,就是为了创建容器类。 泛型类 容器…

POJ 2456 Aggressive cows(二分答案)
Aggressive cowsTime Limit: 1000MS Memory Limit: 65536KTotal Submissions: 22674 Accepted: 10636Description Farmer John has built a new long barn, with N (2 < N < 100,000) stalls. The stalls are located along a straight line at positions x1,...,xN (0…

JMeter打开脚本报错处理方法
今天电脑重装了系统,安装好jmeter后打开以前写的脚本,总是报错如下图,研究了半天也没搞明白。 后来一个群里的人员提醒才想起来,是脚本的问题,为啥捏? 因为之前写的脚本用了一些监听,而这些监听…

Android开发中libs包下面的mips、armeabi、armeabi-v7a和x86
简介 在Android日常的开发过程中有的项目需要引入第三方的库,有时候大家可能会在libs文件夹下看到 mips、armeabi、armeabi-v7a和x86这四个文件夹。那么这三个文件夹下面的包是干什么用的? 这三个包下面存放的用C编译的本地库文件(各类『.…

【数据结构】判断一个单链表中各结点的值是否有序
count记录的是单链表的总长 count1记录的是升序的结点的个数 count2记录的是降序的结点的个数 如果count1或者count2等于count,那么就说明该序列是升序或者降序的。 稍加改进可以在准确判断是升序还是降序还是无序 (个人认为链表中只有一个结点或者…

MSSQL-最佳实践-行级别安全解决方案
title: MSSQL-最佳实践-行级别安全解决方案 author: 风移 摘要 在SQL Server安全系列专题月报分享中,我们已经分享了:如何使用对称密钥实现SQL Server列加密技术、使用非对称密钥加密方式实现SQL Server列加密、使用混合密钥实现SQL Server列加密技术和列…
浮点数运算原理详解
导读: 浮点数运算是一个非常有技术含量的话题,不太容易掌握。许多程序员都不清楚使用操作符比较float/double类型的话到底出现什么问题。 许多人使用float/double进行货币计算时经常会犯错。这篇文章是这一系列中的精华,所有的软件开发人员都…

vCenter的安装
转载于:https://blog.51cto.com/yht1990/1857211

【数据结构】双链表的应用
1、设计一个算法,在双链表中值为y的结点前面插入一个值为x的新结点,即使得值为x的新结点成为值为y的结点的前驱结点。 2、设计一个算法,将一个双链表改建成一个循环双链表。 #include <stdio.h> #include <stdlib.h>typedef st…

Eclipse for Tricore 的安装方法
1.安装JDK32位版 2.安装Eclipse for Tricore 32位版(应该也只有32位的) 3.OK(如果打开Tricore提示找不到JDK的话,在网上搜索如何配置JDK,修改环境变量) 注意:Eclipse的位数必须和JDK位数相同 转…