summaryrefslogtreecommitdiff
path: root/OCRImage/main.swift
diff options
context:
space:
mode:
authordianshi <dianshi@main.lv>2021-03-25 09:26:53 +0000
committerdianshi <dianshi@main.lv>2021-03-25 09:26:53 +0000
commit6e7acb16e75bd6628f9db15be4949e283cc18db8 (patch)
treea1ff27f8b286128e9b0f03b049b58cb850165043 /OCRImage/main.swift
parentc817e9897b83f82a3e5ef7ac123804220d224f50 (diff)
downloadOCRImage-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.swift19
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")