From 6e7acb16e75bd6628f9db15be4949e283cc18db8 Mon Sep 17 00:00:00 2001 From: dianshi Date: Thu, 25 Mar 2021 09:26:53 +0000 Subject: Both full path and short path is working, relative path not supported --- OCRImage/main.swift | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'OCRImage/main.swift') 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") -- cgit v1.2.3