Search code examples
swiftxcodeavcapturesessionios15

Why does the Breakfast Finder sample code result in a blank screen after adding it to a new xcodeproj file?


Goal

I am trying to apply the object detection functionality of the Breakfast Finder sample code to my app. When I add my personal model to the Breakfast Finder sample code and run it, it detects my objects and presents labels just fine.

Problem

When I attempt to add the sample code to a test app (new xcodeproj file), I can't get the live camera feed. I just get the security pop-up and a blank screen.

What I did to get the problem

  1. Copy over the ViewController and ViewObjectRecognitionViewController swift files
  2. Link the Preview View referencing outlet to the @IBOutlet in the ViewController - line 17
  3. Add the mlmodel file (from the sample code, not my mlmodel file)
  4. Add the NSCameraUsageDescription to the Info file (with a value).

On another attempt, I tried just copying all the files (swift, plist, mlmodel, etc.) over from the sample code and troubleshooting connection issues, but got the same problem.

Final Thoughts

Why does the Breakfast Finder sample code result in a blank screen after adding it to a new xcodeproj file? I have never dealt with live camera feed so I might have overlooked a simple problem. I have an iPhone XR running on ios15. You can find a link to the sample code here or google Breakfast Finder.


Solution

  • I eventually noticed that the view controller in the storyboard was actually VisionObjectRecognitionViewController. So I replaced the view controller by doing the following:

    1. Selected the View Controller in the document outline in main.storyboard
    2. Selected the identity inspector on the top right side of the screen
    3. Changed the class to VisionObjectRecognitionViewController (you need to add the VisionObjectRecognitionViewController.swift file to your project before doing this step)

    And, that fixed it! I could not only see the live video feed, but also see my model detecting objects! Thank you @Iker Solozabal for providing similar steps on another question.