Mesure distance using apple ARKit

Overview

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 文件

Comments
  • May I ask a question?

    May I ask a question?

    Can I measure distance from somewhere far away from here to here, for example, when I am on the road, I saw a tower is just 500 meter away from here, can this measure the distance?

    请问,我可以测量水平距离吗?比如说,我在路上,看到一个距离我500米左右的灯塔,我能不能测量我和灯塔之间的具体距离?

    opened by hzhou81 1
  • OpenVC

    OpenVC

    你好,请问下,我安装完该项目需要的三方库后,OpenVC重的type.app就报错 member initializer 'xywh' does not name a non-static data member or base class : x(pt.x), y(pt.y), z(pt.z) {} ^~~~~~~ 怎么回事,是和什么冲突吗?

    opened by jidanLiu 0
  • Adding CocoaPods and the OpenCV pod to the project

    Adding CocoaPods and the OpenCV pod to the project

    I added a pod file which will install opencv for you when you run: pod install in this project. This will solve the "Undefined symbols for architecture arm64" issue and also the large file checkin to git.

    I also updated the ARWorldTrackingSessionConfiguration to use the latest ARWorldTrackingConfiguration.

    opened by mhanlon 0
  • Improve accuracy in this IOS App

    Improve accuracy in this IOS App

    I have downloaded this project and tried to build it.

    I want to know the following things:

    any method or improvisations in the code, which can improve the accuracy. In General, when is the accuracy in measurement fine. Does that completely depend upon the feature points or is there any other factor which influences them? If you have already conducted real life experiments with measurement,then it would be really great if you can share your experiences.

    Thanks in advance!

    opened by sriharsha48 0
  • podfile.lock no such file or directory, how can I delete the pod part ?

    podfile.lock no such file or directory, how can I delete the pod part ?

    As I see so far, the project includes some 3-rd party framework like Pods_ARuler.framework. If so, can I exclude this pod library or not ? If not, any suggestion for me to build this project without any error? Anyway, thanks a lot.

    opened by papamex 0
  • Undefined symbols for architecture arm64

    Undefined symbols for architecture arm64

    Hey, I am having trouble building your app I am using following setup: Xcode Version 9.0 beta 6 (9M214v) opencv 3.2.0 (I reimported it as suggested)

    but i am still getting this error:

    Undefined symbols for architecture arm64: "cv::String::deallocate()", referenced from: cv::String::~String() in PlaneDetector.o cv::String::operator=(cv::String const&) in PlaneDetector.o "_cvGEMM", referenced from: cvFitPlane(CvMat const*, float*) in PlaneDetector.o "_cvSVD", referenced from: cvFitPlane(CvMat const*, float*) in PlaneDetector.o "_cvSet", referenced from: cvFitPlane(CvMat const*, float*) in PlaneDetector.o "_cvReleaseMat", referenced from: cvFitPlane(CvMat const*, float*) in PlaneDetector.o "_cvCreateMat", referenced from: +[PlaneDetector detectPlaneWithPoints:] in PlaneDetector.o cvFitPlane(CvMat const*, float*) in PlaneDetector.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

    As I understand it this is symbols are referenced from the opencv library which does have arm64 references.

    So where could be the problem ?

    opened by neutrum 8
  • PlaneDetector.mm:9:9: 'opencv2/stitching.hpp' file not found Xcode Beta 6

    PlaneDetector.mm:9:9: 'opencv2/stitching.hpp' file not found Xcode Beta 6

    Hi, I am getting this compile error when I try to build it in Xcode Beta 6. I have deleted and reimported the opencv 3.2 library as per the suggestions on a similar post, but it didn't work. I also tried using Tower to clone from git but that didn't work either. Any other solutions? Does this project work on beta 6? Thanks.

    opened by timnlupo 1
Owner
ZeXu Du
ZeXu Du
A library that allows you to generate and update environment maps in real-time using the camera feed and ARKit's tracking capabilities.

ARKitEnvironmentMapper Example To run the example project, clone the repo, and run pod install from the Example directory first. Installation ARKitEnv

SV Hawks 91 Dec 4, 2022
PlacenoteSDK Sample app in native iOS using ARKit, written primarily in Swift

Placenote SDK for iOS Placenote SDK lets you easily build cloud-based Augmented Reality (AR) apps that pin digital content to locations in the real wo

Placenote 93 Nov 15, 2022
A library that allows you to generate and update environment maps in real-time using the camera feed and ARKit's tracking capabilities.

ARKitEnvironmentMapper Example To run the example project, clone the repo, and run pod install from the Example directory first. Installation ARKitEnv

SV Hawks 91 Dec 4, 2022
ARDicee - Simple augmented reality app using SceneKit and ARKit

ARDicee Simple augmented reality app using SceneKit and ARKit Requirements Xcode

donggyu 3 Feb 4, 2022
AR Ruler - A simple iOS app made using ARKit and SceneKit

A simple iOS app made using ARKit and SceneKit.Which can try to simplify little things in your life such as measuring stuff.

Dishant Nagpal 5 Aug 31, 2022
Using ARKit and LiDAR to save depth data and export point cloud, based on WWDC20-10611 sample code

Save iOS ARFrame and Point Cloud This project improves the usability of the sample code from WWDC20 session 10611: Explore ARKit 4. Note that the samp

null 4 Dec 22, 2022
ARKit + CoreLocation: Combines the high accuracy of AR with the scale of GPS data.

ARKit: Uses camera and motion data to map out the local world as you move around. CoreLocation: Uses wifi and GPS data to determine your global locati

Andrew Hart 5.3k Dec 27, 2022
ARKit Demo Application

ARKitNavigationDemo Work in progress. In Progress Region — For one, we could render far fewer nodes. In fact, it’s a bit distracting that the entire t

Christopher Webb 296 Dec 16, 2022
An iOS Framework Capture & record ARKit videos 📹, photos 🌄, Live Photos 🎇, and GIFs 🎆.

An iOS Framework that enables developers to capture videos ?? , photos ?? , Live Photos ?? , and GIFs ?? with ARKit content.

Ahmed Bekhit 1.5k Dec 24, 2022
ARKit Base Project. Place virtual objects based on WWDC example project

ARKit - Placing Virtual Objects in Augmented Reality Learn best practices for visual feedback, gesture interactions, and realistic rendering in AR exp

Ignacio Chiazzo Cardarello 338 Jan 5, 2023
This library uses ARKit Face Tracking in order to catch user's smile.

SmileToUnlock Make your users smile before opening the app :) Gif with the demonstration Installation Cocoapods The most preferable way to use this li

Ruslan Serebriakov 628 Oct 22, 2022
Power! Unlimited power for ARKit 2.0!

A long time ago in a galaxy, far, far away... It is a period when iPhone SE and iPhone X were destroyed from the apple store, the AR market was under

KBOY (Kei Fujikawa) 516 Dec 1, 2022
Augmented Reality image tracking with SwiftUI, RealityKit and ARKit 4.

ARImageTracking This is an Augmented Reality Xcode project that uses Apple's newest RealityKit framework and ARKit 4 features, to dynamically track a

Richard Qi 198 Dec 7, 2022
A simple application created for educational purposes for mastering ARKit

ARDrawing AR Drawing is a simple application created for educational purposes for mastering ARKit. The basis of the project is copied from the project

NIKOLAY NIKITIN 0 Oct 20, 2022
Trying TDD with ARKit

ARPlacer BDD Spec As a user I want to place a random object in real world. I also want to see the distance between AR object and my phone. Use Cases

null 0 Dec 21, 2021
Draw VR content over live camera feed with ARKit

funny-ar Exercise with ARKit: draw VR content over live camera feed: work is in

pavel 3 Dec 18, 2021
ARKit: Projecting 3D mesh to 2D coordinate

ARKitDemo ARKit: Projecting 3D mesh to 2D coordinate A simple utility to project 3D face mesh in 2D coordinate on device screen. Sources: https://deve

Tushar Chitnavis 0 Dec 28, 2021
Furniture E-Commerce Augmented Reality(AR) app in iOS powered by ARKit

HomeMax-iOS Furniture E-Commerce Augmented Reality(AR) app in iOS powered by ARKit and SceneKit. Inspired by IKEA place app. Description Experience on

Ikmal Azman 5 Oct 14, 2022
Reality-iOS - NFT Augmented Reality(AR) app that demonstrate application of ARImageTracking in iOS powered by ARKit 2

Reality-iOS NFT Augmented Reality(AR) app that demonstrate application of ARImag

Ikmal Azman 6 Nov 28, 2022