Skip to content

Commit 47af599

Browse files
authored
Merge pull request #125 from what3words/app/staging
App/staging to main
2 parents 2783581 + f7ace8a commit 47af599

File tree

72 files changed

+2813
-401
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+2813
-401
lines changed

Package.swift

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let package = Package(
77
name: "w3w-swift-components-ocr",
88
defaultLocalization: "en",
99
platforms: [
10-
.macOS(.v10_13), .iOS(.v12), .tvOS(.v11), .watchOS(.v4)
10+
.macOS(.v10_13), .iOS(.v13), .tvOS(.v13), .watchOS(.v6)
1111
],
1212
products: [
1313
// Products define the executables and libraries a package produces, and make them visible to other packages.
@@ -17,17 +17,25 @@ let package = Package(
1717
],
1818
dependencies: [
1919
// Dependencies declare other packages that this package depends on.
20-
.package(url: "https://github.com/what3words/w3w-swift-wrapper.git", "4.0.0"..<"5.0.0"),
21-
.package(url: "https://github.com/what3words/w3w-swift-design.git", "1.0.0" ..< "2.0.0")
20+
//.package(url: "https://github.com/what3words/w3w-swift-wrapper.git", "4.0.0"..<"5.0.0"),
21+
.package(url: "https://github.com/what3words/w3w-swift-core.git", "1.0.0"..<"2.0.0"),
22+
.package(url: "https://github.com/what3words/w3w-swift-design.git", "1.0.0" ..< "2.0.0"),
23+
.package(url: "git@github.com:what3words/w3w-swift-design-swiftui.git", "1.0.0" ..< "2.0.0"),
24+
.package(url: "git@github.com:w3w-internal/w3w-swift-app-events.git", "5.0.0" ..< "6.0.0"),
25+
.package(url: "https://github.com/what3words/w3w-swift-presenters.git", branch: "staging")
2226
],
2327
targets: [
2428
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
2529
// Targets can depend on other targets in this package, and on products in packages this package depends on.
2630
.target(
2731
name: "W3WSwiftComponentsOcr",
2832
dependencies: [
29-
.product(name: "W3WSwiftApi", package: "w3w-swift-wrapper"),
30-
.product(name: "W3WSwiftDesign", package: "w3w-swift-design")
33+
//.product(name: "W3WSwiftApi", package: "w3w-swift-wrapper"),
34+
.product(name: "W3WSwiftCore", package: "w3w-swift-core"),
35+
.product(name: "W3WSwiftDesign", package: "w3w-swift-design"),
36+
.product(name: "W3WSwiftDesignSwiftUI", package: "w3w-swift-design-swiftui"),
37+
.product(name: "W3WSwiftPresenters", package: "w3w-swift-presenters"),
38+
.product(name: "W3WSwiftAppEvents", package: "w3w-swift-app-events")
3139
],
3240
resources: [.process("Resources")]
3341
),

Sources/W3WSwiftComponentsOcr/Export.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,4 @@
77
//
88

99
// Expose types and the api wrapper to whomever imports this module
10-
@_exported import W3WSwiftApi
1110
@_exported import W3WSwiftCore

Sources/W3WSwiftComponentsOcr/Extensions/W3WViewPosition+.swift

Lines changed: 0 additions & 25 deletions
This file was deleted.

Sources/W3WSwiftComponentsOcr/Camera/W3WCameraImageProcessor.swift renamed to Sources/W3WSwiftComponentsOcr/Lib/Camera/W3WCameraImageProcessor.swift

Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -19,35 +19,15 @@ import W3WOcrSdk
1919
class W3WCameraImageProcessor: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate {
2020

2121
// MARK: Vars
22-
22+
2323
/// callback for any new images
2424
var onNewImage: (CGImage) -> () = { _ in }
25-
//var onNewVideoBuffer: (CMSampleBuffer) -> () = { _ in }
26-
27-
/// orientaion of the camera
28-
var orientation: AVCaptureVideoOrientation = .portrait
29-
30-
/// this monitors device orientation
31-
lazy var orientationObserver = W3WOcrOrientationObserver()
32-
25+
3326
/// resultution of the camera
3427
var resolution: CGSize?
3528

3629
/// region to crop output images to
37-
var crop: CGRect?
38-
39-
40-
// MARK: Init
41-
42-
override init() {
43-
super.init()
44-
45-
self.orientation = orientationObserver.currentOrientationForCamera()
46-
47-
orientationObserver.onNewOrientation = { [weak self] orientation in
48-
self?.orientation = orientation
49-
}
50-
}
30+
var crop: CGRect = .zero
5131

5232

5333
/// sets a crop for all returning images in camera coordinates
@@ -63,43 +43,25 @@ class W3WCameraImageProcessor: NSObject, AVCaptureVideoDataOutputSampleBufferDel
6343

6444
/// called when a new image is aviaable from the camera
6545
public func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
66-
67-
// make sure the orientation is correct
68-
connection.videoOrientation = orientation
69-
70-
// crop the incoming image, and send to whomever is interested
71-
if let i = image(from: sampleBuffer, crop: crop) {
72-
onNewImage(i)
73-
}
74-
}
75-
76-
77-
// MARK: Util
78-
79-
/// crop an image and return it as a CGImage
80-
/// - Parameters:
81-
/// - buffer: image buffer from the camera
82-
/// - crop: region to crop to
83-
/// - Returns: CGImage of the crop
84-
private func image(from buffer: CMSampleBuffer, crop: CGRect?) -> CGImage? {
85-
var image: CGImage?
46+
guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return }
47+
let width = CVPixelBufferGetWidth(pixelBuffer)
48+
let height = CVPixelBufferGetHeight(pixelBuffer)
49+
50+
let cropRect = CGRect(
51+
x: crop.origin.x * CGFloat(width),
52+
y: crop.origin.y * CGFloat(height),
53+
width: crop.width * CGFloat(width),
54+
height: crop.height * CGFloat(height)
55+
)
8656

87-
if let imageBuffer = CMSampleBufferGetImageBuffer(buffer) {
88-
var ciimage = CIImage(cvPixelBuffer: imageBuffer)
89-
resolution = CGSize(width: ciimage.extent.size.width, height: ciimage.extent.size.height)
90-
if let c = crop?.intersection(CGRect(origin: CGPoint.zero, size: resolution!)) {
91-
ciimage = ciimage.cropped(to: c)
92-
}
93-
94-
if let cgImage = CIContext.init(options: nil).createCGImage(ciimage, from: ciimage.extent) {
95-
image = cgImage
96-
}
57+
let ciImage = CIImage(cvPixelBuffer: pixelBuffer)
58+
let cropped = ciImage.cropped(to: cropRect)
59+
60+
if let cgImage = CIContext().createCGImage(cropped, from: cropped.extent) {
61+
onNewImage(cgImage)
9762
}
98-
99-
return image
10063
}
10164

102-
10365
// this makes the OCR work even under the iOS simulator
10466
#if targetEnvironment(simulator)
10567
var fakeImages = W3WOcrFakeImages()

0 commit comments

Comments
 (0)