Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
733 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# OS X | ||
.DS_Store | ||
|
||
# Xcode | ||
build/ | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata | ||
*.xccheckout | ||
profile | ||
*.moved-aside | ||
DerivedData | ||
*.hmap | ||
*.xccheckout | ||
# AppCode | ||
.idea/ | ||
|
||
Carthage | ||
|
||
Demo/Pods | ||
.ruby-version | ||
.ruby-gemset | ||
# Swift Package Manager | ||
.build | ||
Packages |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// BarcodesDetectViewController.swift | ||
// HelloVision | ||
// | ||
// Created by 郭朋 on 10/06/2017. | ||
// Copyright © 2017 Peng Guo. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import Vision | ||
|
||
class BarcodesDetectViewController: UIViewController { | ||
|
||
@IBOutlet weak var result: UILabel! | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
let barcodeImage = UIImage(named: "QRCode.png")! | ||
|
||
let barcodeRequest = VNDetectBarcodesRequest(completionHandler: {(request, error) in | ||
|
||
for result in request.results! { | ||
|
||
if let barcode = result as? VNBarcodeObservation { | ||
|
||
if let desc = barcode.barcodeDescriptor as? CIQRCodeDescriptor { | ||
print(desc.symbolVersion) | ||
let content = String(data: desc.errorCorrectedPayload, encoding: .utf8) | ||
|
||
let resultStr = """ | ||
Symbology: \(barcode.symbology.rawValue)\n | ||
Payload: \(String(describing: content))\n | ||
Error-Correction-Level:\(desc.errorCorrectionLevel)\n | ||
Symbol-Version: \(desc.symbolVersion)\n | ||
""" | ||
DispatchQueue.main.async { | ||
self.result.text = resultStr | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
|
||
let handler = VNImageRequestHandler(cgImage: barcodeImage.cgImage!, options: [:]) | ||
|
||
guard let _ = try? handler.perform([barcodeRequest]) else { | ||
return print("Could not perform barcode-request!") | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.