Skip to content

Commit 0f6e8cb

Browse files
committed
Added rect information to JSON.
1 parent 5ca1a40 commit 0f6e8cb

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

OcrServer.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@
284284
ASSETCATALOG_COMPILER_APPICON_NAME = ocrserver_icon;
285285
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
286286
CODE_SIGN_STYLE = Automatic;
287-
CURRENT_PROJECT_VERSION = 25;
287+
CURRENT_PROJECT_VERSION = 26;
288288
ENABLE_PREVIEWS = YES;
289289
GENERATE_INFOPLIST_FILE = YES;
290290
INFOPLIST_KEY_CFBundleDisplayName = "OCR Server";
@@ -298,7 +298,7 @@
298298
"$(inherited)",
299299
"@executable_path/Frameworks",
300300
);
301-
MARKETING_VERSION = 1.3.5;
301+
MARKETING_VERSION = 1.3.6;
302302
PRODUCT_BUNDLE_IDENTIFIER = site.riddleling.app.OcrServer;
303303
PRODUCT_NAME = "$(TARGET_NAME)";
304304
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
@@ -317,7 +317,7 @@
317317
ASSETCATALOG_COMPILER_APPICON_NAME = ocrserver_icon;
318318
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
319319
CODE_SIGN_STYLE = Automatic;
320-
CURRENT_PROJECT_VERSION = 25;
320+
CURRENT_PROJECT_VERSION = 26;
321321
ENABLE_PREVIEWS = YES;
322322
GENERATE_INFOPLIST_FILE = YES;
323323
INFOPLIST_KEY_CFBundleDisplayName = "OCR Server";
@@ -331,7 +331,7 @@
331331
"$(inherited)",
332332
"@executable_path/Frameworks",
333333
);
334-
MARKETING_VERSION = 1.3.5;
334+
MARKETING_VERSION = 1.3.6;
335335
PRODUCT_BUNDLE_IDENTIFIER = site.riddleling.app.OcrServer;
336336
PRODUCT_NAME = "$(TARGET_NAME)";
337337
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";

OcrServer/TextRecognizer.swift

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ class TextRecognizer {
3737
var lines: [String] = []
3838
var items: [OCRBoxItem] = []
3939

40+
func toPixel(_ p: NormalizedPoint) -> (Double, Double) {
41+
let x = Double(p.x * Double(W))
42+
let y = Double((1 - p.y) * Double(H))
43+
return (x, y)
44+
}
45+
4046
for obs in observations {
4147
guard let best = obs.topCandidates(1).first else { continue }
4248
let text = best.string
@@ -61,7 +67,23 @@ class TextRecognizer {
6167
let rectW = Double(maxX - minX)
6268
let rectH = Double(maxY - minY)
6369

64-
items.append(OCRBoxItem(text: text, x: rectX, y: rectY, w: rectW, h: rectH))
70+
// 文字角度
71+
var rectItem: OCRRectItem? = nil
72+
if let rect = best.boundingBox(for: best.string.startIndex..<best.string.endIndex) {
73+
let tl = toPixel(rect.topLeft)
74+
let tr = toPixel(rect.topRight)
75+
let bl = toPixel(rect.bottomLeft)
76+
let br = toPixel(rect.bottomRight)
77+
78+
rectItem = OCRRectItem(
79+
topLeft_x: tl.0, topLeft_y: tl.1,
80+
topRight_x: tr.0, topRight_y: tr.1,
81+
bottomLeft_x: bl.0, bottomLeft_y: bl.1,
82+
bottomRight_x: br.0, bottomRight_y: br.1
83+
)
84+
}
85+
86+
items.append(OCRBoxItem(text: text, x: rectX, y: rectY, w: rectW, h: rectH, rect: rectItem))
6587
}
6688

6789
return OCRResult(

OcrServer/VaporServer.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,24 @@
88
import Vapor
99
import Vision
1010

11+
struct OCRRectItem: Content {
12+
let topLeft_x: Double
13+
let topLeft_y: Double
14+
let topRight_x: Double
15+
let topRight_y: Double
16+
let bottomLeft_x: Double
17+
let bottomLeft_y: Double
18+
let bottomRight_x: Double
19+
let bottomRight_y: Double
20+
}
21+
1122
struct OCRBoxItem: Content {
1223
let text: String
1324
let x: Double
1425
let y: Double
1526
let w: Double
1627
let h: Double
28+
let rect: OCRRectItem?
1729
}
1830

1931
struct OCRResult: Content {

0 commit comments

Comments
 (0)