DevStory

Part 1. Building a More Realistic AR App with Deep Learning

Sharing the story of developing a more realistic AR application using deep learning.

✔︎ Part 1. Building a More Realistic AR App with Deep Learning
Part 2. Building an iOS AR App with ARKit
Part 3. Creating a Custom YOLO v3 Model
Part 4. Deploying a YOLO v3 Model on iOS with CoreML


Project Introduction

Many applications using AR (Augmented Reality) are being released. However, for various reasons, the virtual objects in AR applications feel far from real, which seems to lower how immersive the service is.

Those who want to get rich, develop AR (..?)
Source : http://www.etoland.co.kr/

The 3D models used in most AR applications have a fixed shadow image, like the lamp model used in Apple's sample code Placing Objects and Handling 3D Interaction below. Such fixed shadows usually take a generic form that doesn't look awkward in any situation, but depending on the situation, they're one cause of a sense of mismatch with surrounding objects.

The lamp model used in Apple's Sample Code Source - Placing Objects and Handling 3D Interaction

The lamp model used in Apple's Sample Code
Source - Placing Objects and Handling 3D Interaction

Some AR applications create arbitrary virtual lights and render shadows on objects instead of using a fixed shadow image, but since the position and brightness of the virtual light differ from the real lights in the room, they produce inconsistent shadows that actually reduce realism.

So in this project, I'll solve the inconsistent shadow problem by collecting the position and brightness information of real lights.

✔︎ Project goal
Let's build a more realistic AR application that reflects the position and brightness of real lights!


Project Results


Development Environment

It was developed solo over a total of four months, using the following languages and frameworks.

The tech used for development: Python, Keras, Core ML, TensorFlow, Jupyter, YOLO, Swift, Xcode, ARKit and Google Cloud.
Languages, frameworks, and tools used in development

✔︎ Development environment


Demo Video


Features

The overall application runs its service logic in the following six steps.

✔︎ AR development with ARKit & SceneKit

  • Plane Detection
  • Recommending virtual objects that can be placed
  • Placing virtual objects and interacting with them

✔︎ Light recognition using deep learning

  • Google Vision API method
  • YOLO (real time object detection) method

AR Development with ARKit & SceneKit

1. Plane Detection
2. Recommending virtual objects that can be placed
3. Placing virtual objects and interacting with them

The application recognizes the real space and detects walls and floors. Once the space is recognized, it shows a list of furniture that can be placed where you're currently looking, and you can pick the furniture you want and place it. Basic interactions such as moving or rotating the placed furniture are also possible.


Light Recognition Using Deep Learning

This application implements two light recognition methods. One uses the Google Vision API, and the other uses a deep learning model called YOLO, with the following characteristics.

✔︎ Google Vision API method✔︎ YOLO (real time object detection) method
• Requires network communication• No network communication needed
• Can't track lights in real time• Can track lights in real time
• Can't get the exact coordinates of a light• Can get the 2D coordinates of a light
• Can't tell whether a light is on or off• Can tell whether a light is on or off
• Can recognize lights in general• Can only recognize the 5 lights it was trained on

1. Google Vision API Method

Placing a virtual light using the Google Vision API

In the Google Vision API method, when the user looks at a light and presses the recognize button, the image is sent to the Google Vision API server to ask whether a light exists, and the 3D coordinates of the image's center are obtained through the hitTest method. Then, if the Google Vision API returns that a light exists, a virtual light is placed at the 3D coordinates obtained earlier.

The downsides of this method are that the virtual light may be placed somewhere other than the light's actual 3D coordinates, and it doesn't recognize lights in real time, so the user has to press the recognize button once for each light they want recognized. Even so, since it uses Google's vast trained model, it has the advantage of recognizing lights in general.


2. YOLO (real time object detection) Method

YOLO recognizing a light in the on state
YOLO recognizing a light in the off state

This method uses the YOLO model, one of the Realtime Object Detection models. The YOLO model returns the on/off state, type, confidence, and bounding box (the coordinates of two diagonal points of a 2D box) of the light in the image. For every frame, the bounding box coordinates are fed into the hitTest method to calculate the light's 3D coordinates, and depending on the light's state, a virtual light is added to or removed from those coordinates.

Since it uses a YOLO deep learning model deployed on the mobile device, it needs no network communication and has the advantage of recognizing the light's state and coordinates in real time. However, it has the downside of only recognizing the lights it was trained on.


Closing

Since information about real lights is reflected in the virtual objects, you can see in the video below that the objects' shadows are rendered realistically according to their position relative to the light.

Shadows are rendered centered on the light.

On top of that, the brightness (lm) and color temperature (Kelvin) coming in through the camera are reflected in the virtual light in real time every frame, so the virtual objects are rendered with textures similar to their surroundings, making them even more realistic.

Before light recognition (left) the AR plant casts no shadow; after it (right) a shadow matching the Edison bulb's warm light makes it look more real.
The warm color temperature of the Edison bulb is reflected, making the object look more realistic. - Left : before light recognition / Right : after light recognition

By reproducing the position, brightness, and color temperature of real lights as virtual lights, I could achieve the goal of building a more realistic AR application. 🎉

That concludes the overall introduction to the project, and in Part 2, I'll share how to develop an iOS AR application.

✔︎ Part 1. Building a More Realistic AR App with Deep Learning
Part 2. Building an iOS AR App with ARKit
Part 3. Creating a Custom YOLO v3 Model
Part 4. Deploying a YOLO v3 Model on iOS with CoreML

Comments