diff options
author | dianshi <dianshi@main.lv> | 2021-03-25 09:18:54 +0000 |
---|---|---|
committer | dianshi <dianshi@main.lv> | 2021-03-25 09:18:54 +0000 |
commit | c817e9897b83f82a3e5ef7ac123804220d224f50 (patch) | |
tree | 15b6bfff6f22a2312a5e75765138e80332392cdc /OCRImage | |
parent | 14e11dda03e022842135fd0ed5e7900d0c3e838b (diff) | |
download | OCRImage-c817e9897b83f82a3e5ef7ac123804220d224f50.tar.gz OCRImage-c817e9897b83f82a3e5ef7ac123804220d224f50.zip |
Removed default path directory
Diffstat (limited to 'OCRImage')
-rw-r--r-- | OCRImage/main.swift | 57 |
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") |