From f4ec7ab52c4f78c7c75200122d87cd6840ecb2f1 Mon Sep 17 00:00:00 2001 From: Arturs Artamonovs Date: Thu, 4 Mar 2021 20:26:47 +0000 Subject: Added basic file load and check if its Image --- .../xcshareddata/swiftpm/Package.resolved | 16 +++++++++ OCRImage/main.swift | 38 +++++++++++++++++++++- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 OCRImage.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved 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 + -- cgit v1.2.3