Giter Club home page Giter Club logo

aruler's Introduction

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

aruler's People

Contributors

devsc avatar duzexu avatar lexrus avatar mhanlon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aruler's Issues

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 ?

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.

Custome LineNode

I want to custom LineNode like the video show,can you give me some advice ?thank you

Update please

Good day!
You can be asked to update the project, as there are a lot of errors now on Xcode 12.3 and swift 5.3

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) {} ^~~~~~~
怎么回事,是和什么冲突吗?

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米左右的灯塔,我能不能测量我和灯塔之间的具体距离?

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!

测量稳定性和线条属性

  1. 有时候起始点会自动移动,然后移动手机,终点会瞎跑;
  2. 可以测量斜面吗;
  3. 能不能修改线条的属性(线宽、颜色等)。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.