All Projects → duzexu → Aruler

duzexu / Aruler

Licence: gpl-2.0
Mesure distance using apple ARKit

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Aruler

Arpointcloud
A Basic Example Of Visualising Point Clouds In ARKit
Stars: ✭ 31 (-97.47%)
Mutual labels:  arkit, scenekit
Armeasuredemo
Place virtual objects into 3D space and calculate distance between objects
Stars: ✭ 42 (-96.58%)
Mutual labels:  arkit, scenekit
Arkit Occlusion
A demonstration of vertical planes "tracking" and occlusions with ARKit+Scenekit
Stars: ✭ 341 (-72.21%)
Mutual labels:  arkit, scenekit
Artargetshooting
An AR shooting game for the WWDC 2018 Scholarship [Accepted]. ARKit 飞盘射击游戏,WWDC 2018 奖学金入选作品
Stars: ✭ 77 (-93.72%)
Mutual labels:  arkit, scenekit
Augmentedsolarsystem
An Augmented reality experience to explore planets in our Solar System
Stars: ✭ 69 (-94.38%)
Mutual labels:  arkit, scenekit
Scenekit Scnline
Draw a tube or thick line in SceneKit
Stars: ✭ 49 (-96.01%)
Mutual labels:  arkit, scenekit
Arkit Line Drawing
Changed the default ARKit project to draw a line where the camera is positioned
Stars: ✭ 390 (-68.22%)
Mutual labels:  arkit, scenekit
Argithubcommits
Show your GitHub commit records in 3D with ARKit and SceneKit. 用 ARKit 展示你的 GitHub 提交图
Stars: ✭ 280 (-77.18%)
Mutual labels:  arkit, scenekit
Arkit Emperor
Power! Unlimited power for ARKit 2.0!
Stars: ✭ 464 (-62.18%)
Mutual labels:  arkit, scenekit
Arkit By Example
Apple ARKit example app
Stars: ✭ 458 (-62.67%)
Mutual labels:  arkit, scenekit
Scenekit Bezier Animations
Create animations over Bezier curves of any number of points
Stars: ✭ 35 (-97.15%)
Mutual labels:  arkit, scenekit
Arpaint
Draw with bare fingers in the air using ARKit
Stars: ✭ 672 (-45.23%)
Mutual labels:  arkit, scenekit
Arkit Scnpath
Create paths for your Augmented Reality environments using just points to represent the centre of the path.
Stars: ✭ 312 (-74.57%)
Mutual labels:  arkit, scenekit
Arkitbusinesscard
A Basic Example Creating An Interactive Business Card In ARKit2.
Stars: ✭ 33 (-97.31%)
Mutual labels:  arkit, scenekit
Arkit
ARKit Base Project. Place virtual objects based on WWDC example project
Stars: ✭ 297 (-75.79%)
Mutual labels:  arkit, scenekit
Arkit Tictactoe
Tic-Tac-Toe implemented using ARKit+Scenekit
Stars: ✭ 382 (-68.87%)
Mutual labels:  arkit, scenekit
SCNNodeVisualDebugger
A simple visual debugger for SceneKit
Stars: ✭ 18 (-98.53%)
Mutual labels:  scenekit, arkit
Arbottlejump
An ARKit version of WeChat Bottle Jump game. ARKit 版微信跳一跳游戏
Stars: ✭ 259 (-78.89%)
Mutual labels:  arkit, scenekit
3dsnakear
Well known game Snake written in Swift using ARKit.
Stars: ✭ 453 (-63.08%)
Mutual labels:  arkit, scenekit
Arsolarplay
通过ARKit实现的太阳系动画
Stars: ✭ 593 (-51.67%)
Mutual labels:  arkit, scenekit

ARuler

Mesure distance using apple ARKit

ENGLISH README

预览

   

运行

cd到工程目录下,运行pod install

安装

因为ARKit使用限制,设备要求为6s以上,系统最低要求为iOS11,Xcode版本为9以上

测量时需保证光线充足

问题

ARKit目前只能识别水平的平面,所以只能测量水平面的长度,不能测量垂直平面上的长度,不知道视频里的是怎么实现的,有知道的小伙伴可以一起交流一下

去除了识别平面后才进行测量的逻辑,采用最近的特征点,可以测量垂直的物体啦

说明

项目中确定起始和结束点的位置主要有以下几种

如果存在检测到的平面,返回平面上一点
let planeHitTestResults = sceneView.hitTest(position, types: .existingPlaneUsingExtent)
    if let result = planeHitTestResults.first {

        let planeHitTestPosition = SCNVector3.positionFromTransform(result.worldTransform)
        let planeAnchor = result.anchor

        // Return immediately - this is the best possible outcome.
        return (planeHitTestPosition, planeAnchor as? ARPlaneAnchor, true)
    }
根据当前ARFrame中的rawFeaturePoints计算点
  • 获取以摄像头和屏幕上一点对应的透视消失点为轴,角度为10度,最小距离为10cm,最大距离为三米组成的截锥体内的特征点
let highQualityfeatureHitTestResults = sceneView.hitTestWithFeatures(position, coneOpeningAngleInDegrees: 5, minDistance: 0.1, maxDistance: 3.0)
  • 假设抽样的特征点符合正态分布,过滤偏差值大于 3σ 的值
func fliterWithFeatures(_ features:[FeatureHitTestResult]) -> [SCNVector3] {
    guard features.count >= 3 else {
        return features.map { (featureHitTestResult) -> SCNVector3 in
            return featureHitTestResult.position
        };
    }
        
    var points = features.map { (featureHitTestResult) -> SCNVector3 in
        return featureHitTestResult.position
    }
    // 平均值
    let average = points.average!
    // 方差
    let variance = sqrtf(points.reduce(0) { (sum, point) -> Float in
        var sum = sum
        sum += (point-average).length()*100*(point-average).length()*100
        return sum
        }/Float(points.count-1))
    // 标准差
    let standard = sqrtf(variance)
    let σ = variance/standard
    points = points.filter { (point) -> Bool in
        if (point-average).length()*100 > 3*σ {
            print(point,average)
        }
        return (point-average).length()*100 < 3*σ
    }
    return points
}
let detectPlane = planeDetectWithFeatureCloud(featureCloud: warpFeatures)
  • 根据截锥体轴上的点和向量及平面上的点和法向量计算交点
var planePoint = SCNVector3Zero
if detectPlane.x != 0 {
	planePoint = SCNVector3(detectPlane.w/detectPlane.x,0,0)
}else if detectPlane.y != 0 {
    planePoint = SCNVector3(0,detectPlane.w/detectPlane.y,0)
}else {
    planePoint = SCNVector3(0,0,detectPlane.w/detectPlane.z)
}
    
let ray = sceneView.hitTestRayFromScreenPos(position)
let crossPoint = planeLineIntersectPoint(planeVector: SCNVector3(detectPlane.x,detectPlane.y,detectPlane.z), planePoint: planePoint, lineVector: ray!.direction, linePoint: ray!.origin)
  • 如果直线和平面平行或不符合平面推定条件,返回点平均值
  • 如果截锥体内没有符合的点,查找出距离轴最近的点

参考

看到微博上AR虚拟尺子视频,就想试着模仿着实现一下

部分代码来自苹果ARKitDemo

平面拟合代码参考这篇博客

建议

有任何建议或问题请提issue

开源协议

ARuler开源在 GPL 协议下,详细请查看 LICENSE 文件

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].