This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// FirebaseML | |
// | |
// Created by Mohammad Azam on 5/8/18. | |
// Copyright © 2018 Mohammad Azam. All rights reserved. | |
// | |
import UIKit | |
import Firebase |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Uncomment the next line to define a global platform for your project | |
# platform :ios, '9.0' | |
target 'FirebaseML' do | |
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks | |
use_frameworks! | |
# Pods for FirebaseML | |
pod 'Firebase/Core' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func startLiveVideo() { | |
session.sessionPreset = AVCaptureSession.Preset.photo | |
let captureDevice = AVCaptureDevice.default(for: AVMediaType.video) | |
let deviceInput = try! AVCaptureDeviceInput(device: captureDevice!) | |
let deviceOutput = AVCaptureVideoDataOutput() | |
deviceOutput.videoSettings = [kCVPixelBufferPixelFormatTypeKey as String: Int(kCVPixelFormatType_32BGRA)] | |
deviceOutput.setSampleBufferDelegate(self, queue: DispatchQueue.global(qos: DispatchQoS.QoSClass.default)) | |
session.addInput(deviceInput) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { | |
if let barcodeDetector = self.barcodeDetector { | |
let visionImage = VisionImage(buffer: sampleBuffer) | |
barcodeDetector.detect(in: visionImage) { (barcodes, error) in | |
if let error = error { | |
print(error.localizedDescription) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBOutlet var sceneView: ARSCNView! | |
private var gSession :GARSession! | |
private var arAnchor :ARAnchor! | |
private var garAnchor :GARAnchor! | |
private var rootRef :DatabaseReference! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.rootRef = Database.database().reference() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func session(_ session: ARSession, didUpdate frame: ARFrame) { | |
try! self.gSession.update(frame) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func hitTestWithPlane(touch :CGPoint) { | |
let hitTestResults = sceneView.hitTest(touch, types: .existingPlane) | |
if !hitTestResults.isEmpty { | |
if let hitTestResult = hitTestResults.first { | |
print("plane hit test") | |
print(hitTestResult.worldTransform) | |
addAnchorWithTransform(transform: hitTestResult.worldTransform) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private func addAnchorWithTransform(transform :matrix_float4x4) { | |
self.arAnchor = ARAnchor(transform: transform) | |
self.sceneView.session.add(anchor: self.arAnchor) | |
// host the anchor | |
self.garAnchor = try! self.gSession.hostCloudAnchor(self.arAnchor) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func session(_ session: GARSession, didHostAnchor anchor: GARAnchor) { | |
if let cloudIdentifier = anchor.cloudIdentifier { | |
self.cloudIdentifier = cloudIdentifier | |
} | |
} |