Skip to content

Commit

Permalink
Merge pull request #173 from msztech/master
Browse files Browse the repository at this point in the history
Upgrade to Swift 5
  • Loading branch information
NMAC427 authored Nov 19, 2019
2 parents bd9b194 + 9c9b76c commit 131d206
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions framework/SwiftOCR.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand Down Expand Up @@ -739,7 +739,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
8 changes: 4 additions & 4 deletions framework/SwiftOCR/FFNN/Matrix.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import Accelerate

open class Matrix {

open let columns: Int
open let rows: Int
open let shape: (Int, Int)
open let size: Int
public let columns: Int
public let rows: Int
public let shape: (Int, Int)
public let size: Int
var flat: Vector

open var vectorView: Vector {
Expand Down
6 changes: 3 additions & 3 deletions framework/SwiftOCR/SwiftOCR.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ open class SwiftOCR {
open func recognize(_ image: OCRImage, _ completionHandler: @escaping (String) -> Void){

func indexToCharacter(_ index: Int) -> Character {
return Array(characters.characters)[index]
return Array(characters)[index]
}

func checkWhiteAndBlackListForCharacter(_ character: Character) -> Bool {
let whiteList = characterWhiteList?.characters.contains(character) ?? true
let blackList = !(characterBlackList?.characters.contains(character) ?? false)
let whiteList = characterWhiteList?.contains(character) ?? true
let blackList = !(characterBlackList?.contains(character) ?? false)

return whiteList && blackList
}
Expand Down
16 changes: 8 additions & 8 deletions framework/SwiftOCR/SwiftOCRTraining.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ open class SwiftOCRTraining {
let randomCode: () -> String = {
let randomCharacter: () -> String = {

let charArray = Array(recognizableCharacters.characters)
let charArray = Array(recognizableCharacters)
let randomDouble = Double(arc4random())/(Double(UINT32_MAX) + 1)
let randomIndex = Int(floor(randomDouble * Double(charArray.count)))
return String(charArray[randomIndex])
Expand Down Expand Up @@ -190,8 +190,8 @@ open class SwiftOCRTraining {

let imageData = ocrInstance.convertImageToFloatArray(blob.0)

var imageAnswer = [Float](repeating: 0, count: recognizableCharacters.characters.count)
if let index = Array(recognizableCharacters.characters).index(of: Array(code.characters)[blobIndex]) {
var imageAnswer = [Float](repeating: 0, count: recognizableCharacters.count)
if let index = Array(recognizableCharacters).index(of: Array(code)[blobIndex]) {
imageAnswer[index] = 1
}

Expand Down Expand Up @@ -275,8 +275,8 @@ open class SwiftOCRTraining {
for (blobIndex, blob) in blobs.enumerated() {
let imageData = ocrInstance.convertImageToFloatArray(blob.0)

var imageAnswer = [Float](repeating: 0, count: recognizableCharacters.characters.count)
if let index = Array(recognizableCharacters.characters).index(of: characters[blobIndex]) {
var imageAnswer = [Float](repeating: 0, count: recognizableCharacters.count)
if let index = Array(recognizableCharacters).index(of: characters[blobIndex]) {
imageAnswer[index] = 1
}

Expand Down Expand Up @@ -308,7 +308,7 @@ open class SwiftOCRTraining {
*/

open func testOCR(_ completionHandler: (Double) -> Void) {
let testData = generateRealisticCharSet(recognizableCharacters.characters.count)
let testData = generateRealisticCharSet(recognizableCharacters.count)

var correctCount = 0
var totalCount = 0
Expand All @@ -318,8 +318,8 @@ open class SwiftOCRTraining {
do {
let networkResult = try globalNetwork.update(inputs: i.0)

let input = Array(recognizableCharacters.characters)[i.1.index(of: 1)!]
let recognized = Array(recognizableCharacters.characters)[networkResult.index(of: networkResult.max() ?? 0) ?? 0]
let input = Array(recognizableCharacters)[i.1.index(of: 1)!]
let recognized = Array(recognizableCharacters)[networkResult.index(of: networkResult.max() ?? 0) ?? 0]

print(input, recognized)

Expand Down

0 comments on commit 131d206

Please sign in to comment.