summaryrefslogtreecommitdiff
path: root/OCRImage
diff options
context:
space:
mode:
Diffstat (limited to 'OCRImage')
-rw-r--r--OCRImage/main.swift57
1 files changed, 37 insertions, 20 deletions
diff --git a/OCRImage/main.swift b/OCRImage/main.swift
index cd3fafd..7f7c9f6 100644
--- a/OCRImage/main.swift
+++ b/OCRImage/main.swift
@@ -118,42 +118,59 @@ if options.version {
exit(0)
}
-//exit if input-file isnot set
-//if nil == options.inputFile {
-// print("Set --input-file command argument to image")
-// exit(0)
-//}
-
guard let inputFile = options.inputFile else {
print("ERROR: Set --input-file command argument to image")
exit(0)
}
-
-print("OCR Input file: \(inputFile)")
+if options.debug {
+ print("OCR Input file: \(inputFile)")
+}
//Try to open file from URL
-var fm = FileManager.default.homeDirectoryForCurrentUser
-//let fm = FileManager.default
-print(fm)
-let path:String = inputFile
-fm.appendPathComponent(path)
-let ocrImageUrl = fm.absoluteURL
-print(fm)
+//var runPath = Bundle.main.executablePath!
+
+//return true if file excists
+func checkIfFileExists(_ fname: String) -> Bool {
+ let fm = FileManager.default
+ if fm.fileExists(atPath: fname) {
+ return true
+ }
+ return false
+}
+
+//get current run directory
+func getCurrentExecutableDir() -> String {
+ return Process().currentDirectoryPath
+}
+
+var executionPath = getCurrentExecutableDir()
+
+var fm_full_path = FileManager.default
+fm_full_path.changeCurrentDirectoryPath(executionPath)
+var inputURL = URL(fileURLWithPath: fm_full_path.currentDirectoryPath)
+inputURL.appendPathComponent(inputFile)
+var composePath = "/"+inputURL.pathComponents.filter { ($0 != ".") && ($0 != "/") }.joined(separator: "/")
+if (options.debug) {
+ print(composePath)
+ print(checkIfFileExists(composePath))
+ print(getCurrentExecutableDir())
+ print(executionPath)
+}
+
//load image
-let image = NSImage(contentsOf: ocrImageUrl)
+let composeUrl = URL(fileURLWithPath: composePath)
+let image = NSImage(contentsOf: composeUrl)
if (image == nil) {
- stderr.write("Cannot load image properly \(ocrImageUrl)".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(ocrImageUrl, err)
-
-
+ocr.recognizeImageUrl(composeUrl, err)
print("End programm")