Skip to content

Commit

Permalink
Vision Credit Scanner Completed
Browse files Browse the repository at this point in the history
  • Loading branch information
anupamchugh committed Feb 5, 2020
1 parent 73226d9 commit 2dbbd68
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions VisionCreditScan/VisionCreditScan/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2020 iowncode. All rights reserved.
//


import UIKit
import AVFoundation
import Vision
Expand All @@ -21,6 +22,7 @@ class ViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDele

lazy var item : UINavigationItem = {
let item = UINavigationItem()

item.setRightBarButton(UIBarButtonItem(title: "Scan", style: .plain, target: self, action: #selector(doScan(sender:))), animated: false)

return item
Expand All @@ -30,14 +32,26 @@ class ViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDele

override func viewDidLoad() {
super.viewDidLoad()

self.setCameraInput()
self.showCameraFeed()
self.setCameraOutput()
self.captureSession.startRunning()

self.navigationController?.navigationBar.setItems([item], animated: false)
}

override func viewDidAppear(_ animated: Bool) {

self.videoDataOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "camera_frame_processing_queue"))
self.captureSession.startRunning()
}

override func viewDidDisappear(_ animated: Bool) {

self.videoDataOutput.setSampleBufferDelegate(nil, queue: nil)
self.captureSession.stopRunning()
}

func doPerspectiveCorrection(_ observation: VNRectangleObservation, from buffer: CVImageBuffer) {
var ciImage = CIImage(cvImageBuffer: buffer)

Expand All @@ -57,11 +71,11 @@ class ViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDele
let context = CIContext()
let cgImage = context.createCGImage(ciImage, from: ciImage.extent)
let output = UIImage(cgImage: cgImage!)
UIImageWriteToSavedPhotosAlbum(output, nil, nil, nil)
//UIImageWriteToSavedPhotosAlbum(output, nil, nil, nil)

// let secondVC = TextExtractorVC()
// secondVC.scannedImage = output
// self.present(secondVC, animated: false, completion: nil)
let secondVC = TextExtractorVC()
secondVC.scannedImage = output
self.navigationController?.pushViewController(secondVC, animated: false)

}

Expand Down Expand Up @@ -109,8 +123,8 @@ class ViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDele

self.videoDataOutput.alwaysDiscardsLateVideoFrames = true
self.videoDataOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "camera_frame_processing_queue"))

self.captureSession.addOutput(self.videoDataOutput)

guard let connection = self.videoDataOutput.connection(with: AVMediaType.video),
connection.isVideoOrientationSupported else { return }

Expand Down Expand Up @@ -180,3 +194,4 @@ extension CGPoint {
y: self.y * size.height)
}
}

0 comments on commit 2dbbd68

Please sign in to comment.