diff options
author | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2021-03-04 20:26:47 +0000 |
---|---|---|
committer | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2021-03-04 20:26:47 +0000 |
commit | f4ec7ab52c4f78c7c75200122d87cd6840ecb2f1 (patch) | |
tree | 069274de7701223997aab811cb86e5c8b0e55a1d /OCRImage | |
parent | a80e5b22f6bfc6ef115b8e88ed495fe1f5c1663f (diff) | |
download | OCRImage-f4ec7ab52c4f78c7c75200122d87cd6840ecb2f1.tar.gz OCRImage-f4ec7ab52c4f78c7c75200122d87cd6840ecb2f1.zip |
Added basic file load and check if its Image
Diffstat (limited to 'OCRImage')
-rw-r--r-- | OCRImage/main.swift | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/OCRImage/main.swift b/OCRImage/main.swift index 7669f06..9eff185 100644 --- a/OCRImage/main.swift +++ b/OCRImage/main.swift @@ -7,6 +7,8 @@ import Foundation import ArgumentParser +import Vision +import AppKit class TextPiece { var text:String?; @@ -24,6 +26,22 @@ class TextPiece { } } +class TextOCR { + var pieces:[TextPiece] = [] + + init() { + + } + + func recognizeImageUrl(_ url:URL, _ error: Error?) { + + } + + func handleTextRequest(_ request: VNRequest, error: Error?) { + + } +} + print("Start program") let stderr = FileHandle.standardError @@ -36,7 +54,7 @@ if #available(macOS 10.15,*) {} else { struct OCROptions : ParsableArguments { @Option(help:"Input file for OCR") - var inputFile:String = "/Users/jackyjack/Projects/OCRImage/ExampleInput/sample.png" + var inputFile:String = "/Projects/OCRImage/ExampleInput/sample.png" @Flag(name: .shortAndLong, help:"Show extra debugion info") var debug=false @@ -53,6 +71,24 @@ if options.version { print("OCR Input file: \(options.inputFile)") +//Try to open file from URL +var fm = FileManager.default.homeDirectoryForCurrentUser +//let fm = FileManager.default +print(fm) +let path:String = options.inputFile +fm.appendPathComponent(path) +let ocrImateUrl = fm.absoluteURL +print(fm) + +//load image +let image = NSImage(contentsOf: ocrImateUrl) +if (image == nil) { + stderr.write("Cannot load image properly \(ocrImateUrl)".data(using: .utf8)!) + exit(0) +} + +//Start text recognition request + |