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 | |
parent | a80e5b22f6bfc6ef115b8e88ed495fe1f5c1663f (diff) | |
download | OCRImage-f4ec7ab52c4f78c7c75200122d87cd6840ecb2f1.tar.gz OCRImage-f4ec7ab52c4f78c7c75200122d87cd6840ecb2f1.zip |
Added basic file load and check if its Image
-rw-r--r-- | OCRImage.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved | 16 | ||||
-rw-r--r-- | OCRImage/main.swift | 38 |
2 files changed, 53 insertions, 1 deletions
diff --git a/OCRImage.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/OCRImage.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 0000000..dc80906 --- /dev/null +++ b/OCRImage.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,16 @@ +{ + "object": { + "pins": [ + { + "package": "swift-argument-parser", + "repositoryURL": "https://github.com/apple/swift-argument-parser", + "state": { + "branch": null, + "revision": "9564d61b08a5335ae0a36f789a7d71493eacadfc", + "version": "0.3.2" + } + } + ] + }, + "version": 1 +} 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 + |