summaryrefslogtreecommitdiff
path: root/OCRImage
diff options
context:
space:
mode:
Diffstat (limited to 'OCRImage')
-rw-r--r--OCRImage/main.swift38
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
+