See how ML Kit and ARKit play together

栏目: IOS · 发布时间: 5年前

内容简介:We at the Firebase office all enjoyed playing with Hanley Weng’s “ML Kit for Firebaseis a mobile SDK that extends Google Cloud’s machine learning (ML) expertise into Android and iOS apps in a powerful yet easy-to-use package. It includes easy-to-use Base
See how ML Kit and ARKit play together

Ibrahim Ulukaya

Developer Programs Engineer

We at the Firebase office all enjoyed playing with Hanley Weng’s “ CoreML-in-ARKit ” project. It displays 3D labels on top of images it detects in the scene. While the on-device detection provides a fast response, we wanted to build a solution that gave you the speed of the on-device model with the accuracy you can get from a cloud-based solution. Well, that’s exactly what we built with our MLKit-ARKit project. Read on to find out more about how we did it!

See how ML Kit and ARKit play together

How it all works

ML Kit for Firebaseis a mobile SDK that extends Google Cloud’s machine learning (ML) expertise into Android and iOS apps in a powerful yet easy-to-use package. It includes easy-to-use Base APIs and also offers the ability to bring your own custom TFLite models.

ARKitis Apple’s framework that combines device motion tracking, camera scene capture, advanced scene processing, and display conveniences to simplify the task of building an AR experience. You can use these technologies to create many kinds of AR experiences using either the back camera or front camera of an iOS device.

In this project we are pushing ARKit frames from the back camera into a queue. ML Kit processes these to find out the objects in that frame.

When the user taps the screen, ML Kit returns the detected label with the highest confidence. We then create a 3D bubble text and add it into the user’s scene.

How ML Kit works

ML Kit makes ML easy for all mobile developers, whether you have experience in ML or are new to the space. For those with more advanced use cases, ML Kit allows you to bring your own TFLite models, but for more common use cases, you can implement one of the easy-to-use Base APIs. These APIs cover use cases such as text recognition, image labeling, face detection and more, and are backed by models trained by Google Cloud. We’ll be using image labeling in our example.

Base APIs are available in two flavors: On-device and cloud-based. The on-device APIs are free to use and run locally, while the cloud-based ones provide higher accuracy and more precise responses. Cloud-based Vision APIs are free for the first 1000/API calls and paid after that. They provide the power of full-sized models from Google’s Cloud Vision APIs.

Hybrid approach

We are using the ML Kit on-device image labeling API to get a live feed of results while keeping our frame rate steady at 60fps. When the user taps the screen we fire up an async call to the Cloud image labeling API with the current image. When we get a response from this higher accuracy model, we update the 3D label on the fly. So while we are continuously running the on-device API and using its result as the initial source of information, the higher accuracy Cloud API is called on-demand and its results replaces on-device label eventually.

Which result to show?

While the on-device API is real-time with all the processing happening locally, the Cloud Vision API makes a network request to the Google Cloud backend, leveraging a larger, higher accuracy model. Given that we consider this the more precise response, in our app we replace the label provided by the on-device API with the result from Cloud Vision API when it arrives.

Try it yourself!

1. Clone the project

$ git clone https://github.com/FirebaseExtended/MLKit-ARKit.git

2. Install the pods and open the .xcworkspace file to see the project in Xcode.

$ cd MLKit-ARKit
$ pod install --repo-update
$ open MLKit-ARKit.xcworkspace

3. To set up the Firebase ML Kit in the sample app:

  1. Follow these instructions for adding Firebase to your app .
  2. Make sure to specify “com.google.firebaseextended.MLKit-ARKit” as the iOS project bundle ID.
  3. Download the GoogleService-Info.plist file generated as part of adding Firebase to your app.
  4. In Xcode, add the GoogleService-Info.plist file to your app, next to Info.plist .

At this point, the app should work using the on-device recognition.

4. (Optional) To set up Cloud Vision API in the sample app:

  1. Switch your Firebase project to the Blaze plan

    Only Blaze-level projects can use the Cloud Vision APIs. Follow these steps to switch your project to the Blaze plan and enable pay-as-you-go billing.

    1. Open your project in the Firebase console .
    2. Click on the MODIFY link in the lower left corner next to the currently selected Spark plan.
    3. Select the Blaze plan and follow the instructions in the Firebase Console to add a billing account.

      ★ The cloud label detection feature is still free for first 1000 uses per month. Click here to see additional pricing details.

  • Go to the ML Kit section of the Firebase console and enable the “Cloud Based APIs” toggle at the top.
  • At this point, the app should update labels with more precise results from the Cloud Vision API.

    除非特别声明,此文章内容采用 知识共享署名 3.0 许可,代码示例采用 Apache 2.0 许可。更多细节请查看我们的 服务条款


    以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

    查看所有标签

    猜你喜欢:

    本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

    产品故事地图

    产品故事地图

    唐娜·理查(Donna Lichaw) / 向振东 / 机械工业出版社 / 2017-6 / 49.9元

    本书一共8章,分为三个部分:第1-2章讲述故事的作用、你该如何运用产品故事来吸引顾客,不是通过讲故事,而是创造故事。第3-5章阐述了不同情境和客户生命周期中的产品故事类型。第6-8章进一步研究如何在战略和策略层面发现、提升、用好你的产品故事。 《产品故事地图》写给那些想要通过创造出顾客喜欢用、经常用而且会推荐给别人用的产品来吸引客户的人。这里的“产品”包括网页、软件、APP、数字化或非数字化......一起来看看 《产品故事地图》 这本书的介绍吧!

    XML、JSON 在线转换
    XML、JSON 在线转换

    在线XML、JSON转换工具

    Markdown 在线编辑器
    Markdown 在线编辑器

    Markdown 在线编辑器

    RGB HSV 转换
    RGB HSV 转换

    RGB HSV 互转工具