Simple project to detect objects and display 3D labels above them in AR. This serves as a basic Template for an ARKit project to use CoreML.

Overview

CoreML-in-ARKit

This simple project detects objects in Augmented Reality and displays 3D labels on top of them. This serves as a basic template for an ARKit project to use CoreML.

image of scene with 3d labels on objects

Demo Video - on Youtube

Model: Inception V3

Language: Swift 4.0

Written in: Xcode 9.0 GM (9A235) (Updated) XCode 9 beta 3 (9M174d)

Content Technology: SceneKit

Tested on iPhone 7 plus running iOS 11 beta 3 (15A5318g)

Note: SceneKit can achieve a 60 FPS on iPhone7+ - though when it gets hot, it'll drop to 30 FPS.

Instructions

You'll have to download "Inceptionv3.mlmodel" from Apple's Machine Learning page, and copy it into your XCode project. (As depicted in the following gif)

Gif to show dragging and dropping of model into XCode

(Gif via Atomic14)

If you're having issues, double check that the model is part of a target (source: stackoverflow).

Footnotes

  • SceneKit Text Labels are expensive to render. Too many polygons (too much text, smoothness, characters) - can cause crashes. In future, SpriteKit would be more efficient for text-labels.

  • Not entirely certain if the code is actually transferring RGB data to the Vision Model (as opposed to YUV). Proof-of-concept-wise, it appears to work just fine with the Inception V3 model for now.

  • Whilst ARKit's FPS , is displayed - CoreML's speed is not. However, it does appear sufficiently fast for real-time ARKit applications.

  • Placement of the label is simply determined by the raycast screen centre-point to a ARKit feature-point. This could be altered for more stable placement.

Building Blocks (Overview)

Get CoreML running in real time in ARKit

  • There are some good tutorials / sample projects for getting CoreML running. See: [ 1 ] [ 2 ] [ 3 ]

  • What we do differently here is we're using ARKit's ARFrame as the image to be fed into CoreML.

let pixbuff : CVPixelBuffer? = (sceneView.session.currentFrame?.capturedImage)
  • We also use Threading to continuously run requests to CoreML in realtime, and without disturbing ARKit / SceneView
let dispatchQueueML = DispatchQueue(label: "com.hw.dispatchqueueml")
...
loopCoreMLUpdate() // on viewLoad
...
func loopCoreMLUpdate() {
    dispatchQueueML.async {
        // 1. Run Update.
        self.updateCoreML()
        // 2. Loop this function.
        self.loopCoreMLUpdate()
    }
}

Add 3D Text

  • Add a Tap Gesture.
  • On Tap. Get the raycast centre point, translating it to appropriate coordinates.
  • Render 3D text at that location. Use the most likely object.
Comments
  • dyld: Library not loaded - Error while running on iphone x

    dyld: Library not loaded - Error while running on iphone x

    Xcode Version: 9.2 (9C40b) Phone: iphone x

    I am getting the following error message while running. Followed a few instructions on StackOverflow with no help. I have (1) my developer certificate set to always trust and (2) "Always embed swift standard libraries" set to Yes in Build Settings as suggested by some threads on StackOverflow. Also, tried running after cleaning build folder.

    Error message:

    dyld: Library not loaded: @rpath/libswiftARKit.dylib
      Referenced from: /var/containers/Bundle/Application/5CE8F604-58A4-48E3-8172-7C615161D3ED/CoreML in ARKit.app/CoreML in ARKit
      Reason: no suitable image found.  Did find:
    	/private/var/containers/Bundle/Application/5CE8F604-58A4-48E3-8172-7C615161D3ED/CoreML in ARKit.app/Frameworks/libswiftARKit.dylib: code signing blocked mmap() of '/private/var/containers/Bundle/Application/5CE8F604-58A4-48E3-8172-7C615161D3ED/CoreML in ARKit.app/Frameworks/libswiftARKit.dylib'
    

    Screenshot: screen shot 2018-01-29 at 12 01 37 pm

    opened by saikatbsk 1
  • How is the Label move as i move the object?

    How is the Label move as i move the object?

    I tried running the project in iPhone 7 plus and it is working fine. I noticed as i move the object slowly, even the label moves. But in source code position updation of the node is not happening. Then how come, the text node is moving as i move the object slowly?

    opened by yaalisri 1
  • something wrong with inceptionv3.mlmodel

    something wrong with inceptionv3.mlmodel

    I already copy the inceptionv3.mlmodel into project.but when i click Inceptionv3.mlmodel,it shows " Interface generation only available with valid target",which dont like the gif of yours.

    opened by jbtxwd 1
  • Incorrect distance on object placement

    Incorrect distance on object placement

    I was using an iPhone 12. Sometimes, when I tap the screen, the AR dot and text gets placed right at the camera instead of in the object.

    Any idea why?

    opened by mikeazo 0
  • Code Updated

    Code Updated

    Fixed the on tap keyboard pop up issue Fixed UI for iPhone X and above Cleaned some code and removed the FPS anD Node count Modified Accuracy as Confidence Percentage

    opened by das-anubhav 0
  • Code cleaned up, Swift 4.1 compliance replacement

    Code cleaned up, Swift 4.1 compliance replacement

    I cleaned up the code a bit. Large method in ViewController.swift has been split into few smaller ones. I also replaced flatMap method call with compactMap according to Swift 4.1 changes.

    opened by DamianMarkowski 0
  • updated Main.storyboard to work with iPhone X

    updated Main.storyboard to work with iPhone X

    Prior to this commit, the "debug" text field was partially obscured by the rounded corner and notch of the iPhone X. This commit constraints the text field with the safe area instead of the whole view to make it clearly visible on all devices.

    opened by antonrohr 0
Owner
Hanley
Interaction Designer πŸ•΅οΈ/ Design Technologist πŸš€
Hanley
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
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
Placing Virtual Objects in Augmented Reality

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

Yuchao 279 Dec 11, 2022
A minimal iOS AR app that displays virtual objects at specific geographical locations, in an AR scene.

AR Simple GeoLocation A minimal iOS AR, Augmented Reality, app that displays virtual objects at specific geographical location, in an AR scene. With t

Yasuhito Nagatomo 23 Dec 16, 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
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
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
A sample collection of basic functions of Apple's AR framework for iOS.

RealityKit-Sampler RealityKitSampler is a sample collection of basic functions of RealityKit, Apple's AR framework for iOS. How to build 1, Download o

MLBoy 74 Dec 21, 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
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
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
IOS example app to generate point clouds in ARKit using scenedepth

Visualizing a Point Cloud Using Scene Depth Place points in the real-world using the scene's depth data to visualize the shape of the physical environ

Isak Diaz 20 Oct 31, 2022
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
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
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
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