diff options
Diffstat (limited to 'OCRImage')
-rw-r--r-- | OCRImage/main.swift | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/OCRImage/main.swift b/OCRImage/main.swift index 7f7c9f6..e103c38 100644 --- a/OCRImage/main.swift +++ b/OCRImage/main.swift @@ -161,16 +161,27 @@ if (options.debug) { //load image -let composeUrl = URL(fileURLWithPath: composePath) -let image = NSImage(contentsOf: composeUrl) +var composeUrl:URL? = nil + +if checkIfFileExists(composePath) { + composeUrl = URL(fileURLWithPath: composePath) +} else if checkIfFileExists(inputFile) { + composeUrl = URL(fileURLWithPath: inputFile) +} else { + print("Canot open file path \(inputFile)") + exit(0) +} + +let image = NSImage(contentsOf: composeUrl!) if (image == nil) { - stderr.write("Cannot load image properly \(composeUrl)".data(using: .utf8)!) + stderr.write("Cannot load image properly \(composeUrl!)".data(using: .utf8)!) exit(0) } + //Start text recognition request var ocr = TextOCR() var err:NSError? -ocr.recognizeImageUrl(composeUrl, err) +ocr.recognizeImageUrl(composeUrl!, err) print("End programm") |