diff options
author | dianshi <dianshi@main.lv> | 2021-03-25 09:26:53 +0000 |
---|---|---|
committer | dianshi <dianshi@main.lv> | 2021-03-25 09:26:53 +0000 |
commit | 6e7acb16e75bd6628f9db15be4949e283cc18db8 (patch) | |
tree | a1ff27f8b286128e9b0f03b049b58cb850165043 /OCRImage/main.swift | |
parent | c817e9897b83f82a3e5ef7ac123804220d224f50 (diff) | |
download | OCRImage-6e7acb16e75bd6628f9db15be4949e283cc18db8.tar.gz OCRImage-6e7acb16e75bd6628f9db15be4949e283cc18db8.zip |
Both full path and short path is working, relative path not supported
Diffstat (limited to 'OCRImage/main.swift')
-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") |