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 --- OCRImage/main.swift | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'OCRImage') 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