blob: 9eff1854a6089fd21932b98424063b97dee99ed8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
//
// main.swift
// OCRImage
//
// Created by Jacky Jack on 04/03/2021.
//
import Foundation
import ArgumentParser
import Vision
import AppKit
class TextPiece {
var text:String?;
var topLeft:CGPoint;
var topRight:CGPoint;
var bottomLeft:CGPoint;
var bottomRIght:CGPoint;
init(_ t: String, _ tl:CGPoint, _ tr:CGPoint, _ bl:CGPoint, _ br: CGPoint ) {
self.text = t;
self.topLeft = tl;
self.topRight = tr;
self.bottomLeft = bl;
self.bottomRIght = br;
}
}
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
if #available(macOS 10.15,*) {} else {
//Output to stderr if os version is not supported
stderr.write("Version of MacOS should be >=10.15".data(using: .utf8)!)
exit(0)
}
struct OCROptions : ParsableArguments {
@Option(help:"Input file for OCR")
var inputFile:String = "/Projects/OCRImage/ExampleInput/sample.png"
@Flag(name: .shortAndLong, help:"Show extra debugion info")
var debug=false
@Flag(name:.shortAndLong, help:"Show current version")
var version=false
}
let options = OCROptions.parseOrExit()
if options.version {
print("Version: 0.0.1")
}
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
print("End programm")
|