![]() The ViewController.swift implements the class ViewController which both defines the app’s root view and reads and displays a live feed from the phone’s back camera. The app uses SwiftUI for most of its interface on top of Storyboard and is organized into three folders:įor detecting and visualizing results in real time, only three files are relevant. To see the full working code check out the repository. Also, to keep the post readable, I extracted the relevant sections from the code only and omitted less relevant parts in understanding the code structure such as try catch statements. For details on how to read and display frames from the camera or how to build user interfaces, please see other tutorials. This post focuses on sending frames to the model and processing detections only. There are some transformations required to display a live view with bounding boxes properly which are the focus of this post. Unfortunately, it might take more than just swapping out the model file to make a detector work. To get started with object detection in iOS, Apple provides an example. It can then be used directly by the Vision framework in Swift to be used in an iOS app. This approach is to convert the model into the Core ML format. However, I find interfacing the model here quite complicated which is why I decided for a second approach. There is a tutorial available for this solution. The first one uses ObjectiveC++ on the iOS side which interfaces with libtorch’s C++ api. As a side note, the app is the first time I worked with Swift, so if there are any obvious mistakes or inefficiencies please let me know.Ĭurrently I am aware of two ways to integrate a model trained in Python. ![]() After developing the user interface in Swift, I had to find a way to integrate my PyTorch model. It is now possible to even run some of the latest neural network models on a phone, so I wanted to observe how well object detection works on an iPhone. Technology has advanced far enough that phones now have enough processing power to connect to the internet, play games, and watch videos. Nowadays almost everyone carries a portable computer and camera in their pocket via their phones. ViewController Detection: Detect and visualizeĬoming soon: Updated app code with SwiftUI, hosted UIKit, and clean(er) code.ViewController: Root view, get and show frames.
0 Comments
Leave a Reply. |