Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Vision for iOS

Avatar for Andy Bell Andy Bell
December 18, 2018

Vision for iOS

A brief introduction to Apples computer vision framework with examples of how we can use it get our devices seeing and processing the world around them.

Avatar for Andy Bell

Andy Bell

December 18, 2018

More Decks by Andy Bell

Other Decks in Programming

Transcript

  1. The Vision framework performs face and face landmark detection, text

    detection, barcode recognition, image registration, and general feature tracking. Vision also allows the use of custom Core ML models for tasks like classification or object detection.
  2. Image Classification: Object Recognition: Detecting information in an entire image

    or video frame Detecting bounding box and classification label for features within an entire image or video frame
  3. VNImageRequestHandler VNObservation VNRequest - handles the type of recognition required

    - performs the request(s) on the input data - data for the recognised object(s)
  4. VNObservation uses normalised coordinate space {0, 0} {1, 1} {0,

    1} {1, 0} Normalised coordinate space: (Origin is always lower-left corner)
  5. When using CoreML, Vision performs all image scaling and colour

    conversion for you e.g. if your model expects 300 x 300 RGB images
  6. let request = VNDetectBarcodesRequest() let roi = CGRect(...) request.regionOfInterest =

    roi Use regionOfInterest to focus on specific area of input image
  7. DispatchQueue.global(qos: .userInitiated).async { do { try imageRequestHandler.perform(requests) } catch {

    print(error.localizedDescription)) return } } let requests: [VNImageBasedRequest] = [faceRequest, textRequest] let imageRequestHandler = VNImageRequestHandler(cgImage: image, orientation: orientation, options: [:])
  8. if let model = try? VNCoreMLModel(for: MobileNet().model) { let coreMlRequest

    = VNCoreMLRequest(model: model, completionHandler: coreMLhandler) requests.append(coreMlRequest) } else { print("Could not create model for classifier") } let requests = [VNImageBasedRequest]()
  9. func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection)

    { guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return } let deviceOrientation = exifOrientationForCurrentDeviceOrientation() // create Vision request with the pixel buffer & orientation… } AVCapture session
  10. let requestHandler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer, orientation: deviceOrientation, options: [:]) do

    { try requestHandler.perform(requests) } catch { print(error) } AVCapture session
  11. WWDC 2018 Session 716 - Object Tracking in Vision Session

    717 - Vision with Core ML WWDC 2017 Session 506 - Vision Framework: Building on Core ML
  12. Behind the Magic: How we built the ARKit Sudoku Solver

    https://blog.prototypr.io/behind-the-magic-how- we-built-the-arkit-sudoku-solver-e586e5b685b0