Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
romanmazeev committed Dec 1, 2023
1 parent b1847c3 commit ebcc9ee
Show file tree
Hide file tree
Showing 32 changed files with 552 additions and 509 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added .github/.DS_Store
Binary file not shown.
Binary file added .github/workflows/.DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,6 @@ fastlane/test_output
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/

# OS X Finder
.DS_Store
Binary file added Docs/.DS_Store
Binary file not shown.
Binary file added Example/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,13 +1,67 @@
{
"pins" : [
{
"identity" : "combine-schedulers",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/combine-schedulers",
"state" : {
"revision" : "9dc9cbe4bc45c65164fa653a563d8d8db61b09bb",
"version" : "1.0.0"
}
},
{
"identity" : "mrzparser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/romanmazeev/MRZParser.git",
"state" : {
"revision" : "2c1c4809379f081c01297f0ac92df2e94c6db54a",
"revision" : "d6d24fa2f9d1eac229bba8ffdf812e715690338d",
"version" : "1.1.3"
}
},
{
"identity" : "swift-clocks",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-clocks",
"state" : {
"revision" : "d1fd837326aa719bee979bdde1f53cd5797443eb",
"version" : "1.0.0"
}
},
{
"identity" : "swift-concurrency-extras",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-concurrency-extras.git",
"state" : {
"revision" : "bb5059bde9022d69ac516803f4f227d8ac967f71",
"version" : "1.1.0"
}
},
{
"identity" : "swift-dependencies",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-dependencies",
"state" : {
"revision" : "9783b58167f7618cb86011156e741cbc6f4cc864",
"version" : "1.1.2"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax",
"state" : {
"revision" : "6ad4ea24b01559dde0773e3d091f1b9e36175036",
"version" : "509.0.2"
}
},
{
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay.git",
"state" : {
"revision" : "23cbf2294e350076ea4dbd7d5d047c1e76b03631",
"version" : "1.0.2"
}
}
],
"version" : 2
Expand Down
Binary file added Example/MRZScannerExample/.DS_Store
Binary file not shown.
17 changes: 12 additions & 5 deletions Example/MRZScannerExample/ViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class ViewModel: ObservableObject {
}

// MARK: Scanning
@Published var boundingRects: ScanedBoundingRects?
@Published var boundingRects: ScannedBoundingRects?
@Published var mrzRect: CGRect?
@Published var mrzResult: MRZResult?

Expand All @@ -36,11 +36,18 @@ final class ViewModel: ObservableObject {
func startMRZScanning() async throws {
guard let cameraRect, let mrzRect else { return }

let correctedMRZRect = correctCoordinates(to: .leftTop, rect: mrzRect)
let roi = MRZScanner.convertRect(to: .normalizedRect, rect: correctedMRZRect, imageWidth: Int(cameraRect.width), imageHeight: Int(cameraRect.height))
let scanningStream = MRZScanner.scanLive(
imageStream: camera.imageStream,
configuration: .init(orientation: .up, regionOfInterest: roi, minimumTextHeight: 0.1, recognitionLevel: .fast)
configuration: .init(
orientation: .up,
regionOfInterest: VNNormalizedRectForImageRect(
correctCoordinates(to: .leftTop, rect: mrzRect),
Int(cameraRect.width),
Int(cameraRect.height)
),
minimumTextHeight: 0.1,
recognitionLevel: .fast
)
)

scanningTask = Task {
Expand All @@ -66,7 +73,7 @@ final class ViewModel: ObservableObject {
case leftTop
}

private func correctBoundingRects(to type: CorrectionType, rects: ScanedBoundingRects) -> ScanedBoundingRects {
private func correctBoundingRects(to type: CorrectionType, rects: ScannedBoundingRects) -> ScannedBoundingRects {
guard let mrzRect else { fatalError("Camera rect must be set") }

let convertedCoordinates = rects.convertedToImageRects(imageWidth: Int(mrzRect.width), imageHeight: Int(mrzRect.height))
Expand Down
56 changes: 55 additions & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
@@ -1,13 +1,67 @@
{
"pins" : [
{
"identity" : "combine-schedulers",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/combine-schedulers",
"state" : {
"revision" : "9dc9cbe4bc45c65164fa653a563d8d8db61b09bb",
"version" : "1.0.0"
}
},
{
"identity" : "mrzparser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/romanmazeev/MRZParser.git",
"state" : {
"revision" : "2c1c4809379f081c01297f0ac92df2e94c6db54a",
"revision" : "d6d24fa2f9d1eac229bba8ffdf812e715690338d",
"version" : "1.1.3"
}
},
{
"identity" : "swift-clocks",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-clocks",
"state" : {
"revision" : "d1fd837326aa719bee979bdde1f53cd5797443eb",
"version" : "1.0.0"
}
},
{
"identity" : "swift-concurrency-extras",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-concurrency-extras.git",
"state" : {
"revision" : "bb5059bde9022d69ac516803f4f227d8ac967f71",
"version" : "1.1.0"
}
},
{
"identity" : "swift-dependencies",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-dependencies",
"state" : {
"revision" : "9783b58167f7618cb86011156e741cbc6f4cc864",
"version" : "1.1.2"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax",
"state" : {
"revision" : "6ad4ea24b01559dde0773e3d091f1b9e36175036",
"version" : "509.0.2"
}
},
{
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay.git",
"state" : {
"revision" : "23cbf2294e350076ea4dbd7d5d047c1e76b03631",
"version" : "1.0.2"
}
}
],
"version" : 2
Expand Down
21 changes: 19 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,29 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/romanmazeev/MRZParser.git", .upToNextMajor(from: "1.1.3"))
.package(url: "https://github.com/romanmazeev/MRZParser.git", .upToNextMajor(from: "1.1.3")),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay.git", .upToNextMajor(from: "1.0.2")),
.package(url: "https://github.com/pointfreeco/swift-concurrency-extras.git", .upToNextMajor(from: "1.1.0")),
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.1.2")
],
targets: [
.target(
name: "MRZScanner",
dependencies: ["MRZParser"]
dependencies: [
"MRZParser",
.product(
name: "XCTestDynamicOverlay",
package: "xctest-dynamic-overlay"
),
.product(
name: "ConcurrencyExtras",
package: "swift-concurrency-extras"
),
.product(
name: "Dependencies",
package: "swift-dependencies"
)
]
),
.testTarget(
name: "MRZScannerTests",
Expand Down
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Library for scanning documents via [MRZ](https://en.wikipedia.org/wiki/Machine-r
### Swift Package Manager
```swift
dependencies: [
.package(url: "https://github.com/romanmazeev/MRZScanner.git", .upToNextMajor(from: "1.0.0"))
.package(url: "https://github.com/romanmazeev/MRZScanner.git", .upToNextMajor(from: "2.0.0"))
]
```
*The library has an SPM [dependency](https://github.com/romanmazeev/MRZParser) for MRZ code parsing.*
Expand All @@ -28,17 +28,12 @@ ScanningConfiguration(orientation: .up, regionOfInterest: roi, minimumTextHeight
2. After you need to start scanning
```swift
/// Live scanning
for try await scanningResult in MRZScanner.scanLive(imageStream: imageStream, configuration: configuration) {
for try await scanningResult in imageStream.scanForMRZCode(configuration: configuration) {
// Handle `scanningResult` here
}

/// Single scanning
let scanningResult = try await MRZScanner.scanSingle(image: image, configuration: configuration)
```

*Also, for the convenience of transforming coordinates into a normalized form and back, there is a static method `convertRect`*
```swift
MRZScanner.convertRect(to: .normalizedRect, rect: rect, imageWidth: imageWidth, imageHeight: imageHeight)
let scanningResult = try await image.scanForMRZCode(configuration: configuration)
```

## Example
Expand Down
Binary file added Sources/.DS_Store
Binary file not shown.
Binary file added Sources/MRZScanner/.DS_Store
Binary file not shown.
32 changes: 0 additions & 32 deletions Sources/MRZScanner/MRZFrequencyTracker.swift

This file was deleted.

96 changes: 0 additions & 96 deletions Sources/MRZScanner/MRZScanner.swift

This file was deleted.

Loading

0 comments on commit ebcc9ee

Please sign in to comment.