Skip to content
Permalink
Browse files

1.1.0 (#5)

* feat: added additional cases to RecognitionReliability

* feat: Made AVManager protocol public
feat: created new convenience initializers
fix: Fixed issue that was causing cropped images to be wider than expected

AVManager is now public so that a custom delegate can be implemented if
CMSampleBuffers need to be routed to another AVCaptureVideoDataOutputSampleBufferDelegate
for processing.

The cropping logic was not considering aspect ratios less than 1 and was returning
cropped images to SwiftyTesseract that were wider than the regionOfInterest.

* chore: Updated documentation

* chore: edited sample project

* fix: removed default initializer value that was never used

* chore: updated Changelog.md and renamed code of conduct and contributing files
  • Loading branch information...
Steven0351 committed May 24, 2018
1 parent d239cce commit 621d1607e1697059aab18146cdb41bddd9cae2ab
Showing with 1,243 additions and 210 deletions.
  1. 0 ContributorCodeOfConduct.md → CODE_OF_CONDUCT.md
  2. 0 Contributions.md → CONTRIBUTING.md
  3. +5 −0 Changelog.md
  4. +49 −41 Example/Pods/Pods.xcodeproj/project.pbxproj
  5. +27 −51 Example/SwiftyTesseractRTE/Base.lproj/Main.storyboard
  6. +4 −0 Example/SwiftyTesseractRTE/Info.plist
  7. +65 −15 Example/SwiftyTesseractRTE/ViewController.swift
  8. +1 −1 Readme.md
  9. +24 −24 SwiftyTesseractRTE/Classes/ConcreteTypes/ImageProcessor.swift
  10. +4 −0 SwiftyTesseractRTE/Classes/ConcreteTypes/RecognitionReliability.swift
  11. +45 −15 SwiftyTesseractRTE/Classes/ConcreteTypes/SwiftyTesseractRTE.swift
  12. +12 −1 SwiftyTesseractRTE/Classes/Protocols/AVManager.swift
  13. +3 −2 SwiftyTesseractRTE/Classes/Protocols/AVSampleProcessor.swift
  14. +4 −1 docs/Classes.html
  15. +162 −16 docs/Classes/SwiftyTesseractRTE.html
  16. +4 −1 docs/Enums.html
  17. +66 −1 docs/Enums/RecognitionReliability.html
  18. +41 −3 docs/Protocols.html
  19. +204 −0 docs/Protocols/AVManager.html
  20. +7 −3 docs/Protocols/AVSampleProcessor.html
  21. +4 −1 docs/Protocols/SwiftyTesseractRTEDelegate.html
  22. +4 −1 docs/docsets/SwiftyTesseractRTE.docset/Contents/Resources/Documents/Classes.html
  23. +162 −16 docs/docsets/SwiftyTesseractRTE.docset/Contents/Resources/Documents/Classes/SwiftyTesseractRTE.html
  24. +4 −1 docs/docsets/SwiftyTesseractRTE.docset/Contents/Resources/Documents/Enums.html
  25. +66 −1 .../docsets/SwiftyTesseractRTE.docset/Contents/Resources/Documents/Enums/RecognitionReliability.html
  26. +41 −3 docs/docsets/SwiftyTesseractRTE.docset/Contents/Resources/Documents/Protocols.html
  27. +204 −0 docs/docsets/SwiftyTesseractRTE.docset/Contents/Resources/Documents/Protocols/AVManager.html
  28. +7 −3 docs/docsets/SwiftyTesseractRTE.docset/Contents/Resources/Documents/Protocols/AVSampleProcessor.html
  29. +4 −1 .../SwiftyTesseractRTE.docset/Contents/Resources/Documents/Protocols/SwiftyTesseractRTEDelegate.html
  30. +9 −3 docs/docsets/SwiftyTesseractRTE.docset/Contents/Resources/Documents/index.html
  31. +1 −1 docs/docsets/SwiftyTesseractRTE.docset/Contents/Resources/Documents/search.json
  32. BIN docs/docsets/SwiftyTesseractRTE.docset/Contents/Resources/docSet.dsidx
  33. BIN docs/docsets/SwiftyTesseractRTE.tgz
  34. +9 −3 docs/index.html
  35. +1 −1 docs/search.json
File renamed without changes.
File renamed without changes.
@@ -1,3 +1,8 @@
#### 1.1.0 - May 24, 2018
* `AVManager` protocol made public
* Added 2 new cases to `RecognitionReliability` to allow for returning results on 1 and 2 frames
* Fixed issue with internal `ImageProcessor` that was not correctly calculating the area to crop when the aspect ratio of `previewLayer` was less than 1

#### 1.0.4 - May 5, 2018
* Internal `ImageProcessor` struct was redrawing the captured image at a much lower size which was causing image degradation. Instead of redrawing the image at the scale of `regionOfInterest`, `regionOfInterest` is now scaled to the size of the image.

Large diffs are not rendered by default.

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="92S-qF-W7g">
<device id="retina5_5" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
@@ -23,10 +23,10 @@
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="QsP-EC-SIH">
<rect key="frame" x="0.0" y="28" width="414" height="442"/>
<rect key="frame" x="0.0" y="64" width="414" height="672"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="6pY-x2-Kns">
<rect key="frame" x="69" y="190.66666666666666" width="275" height="60"/>
<rect key="frame" x="69" y="156" width="275" height="60"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="width" constant="275" id="WDj-L7-VyV"/>
@@ -37,81 +37,57 @@
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="6pY-x2-Kns" firstAttribute="centerX" secondItem="QsP-EC-SIH" secondAttribute="centerX" id="33E-my-byi"/>
<constraint firstItem="6pY-x2-Kns" firstAttribute="centerY" secondItem="QsP-EC-SIH" secondAttribute="centerY" id="I73-zK-vVZ"/>
<constraint firstItem="6pY-x2-Kns" firstAttribute="centerY" secondItem="QsP-EC-SIH" secondAttribute="centerY" constant="-150" id="I73-zK-vVZ"/>
</constraints>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="View finder below can be resized. Tap and drag to resize to fit the text to be recognized in the box." textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="xUq-E0-SXT">
<rect key="frame" x="28" y="28" width="358" height="61"/>
<rect key="frame" x="28" y="72" width="358" height="61"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="oIB-Ti-Qn5">
<rect key="frame" x="28" y="478" width="358" height="250"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="F6V-ms-4I3">
<rect key="frame" x="0.0" y="0.0" width="358" height="48"/>
<state key="normal" image="flashlightOff"/>
<connections>
<action selector="flashLightButtonTapped:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="LbF-k0-t1H"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Df9-DJ-y6p">
<rect key="frame" x="0.0" y="56" width="358" height="30"/>
<state key="normal" title="Button"/>
<connections>
<action selector="recognitionButtonTapped:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="3Gb-W4-ZZ8"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Recognition Text:" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="bFY-sy-3qF">
<rect key="frame" x="0.0" y="94" width="358" height="20.333333333333329"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" userInteractionEnabled="NO" contentMode="scaleToFill" text="Let's do this!" textAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="6Wj-BC-sZL">
<rect key="frame" x="0.0" y="122.33333333333337" width="358" height="127.66666666666669"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
</subviews>
<constraints>
<constraint firstAttribute="height" constant="250" id="a3m-0k-X0f"/>
</constraints>
</stackView>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="QsP-EC-SIH" secondAttribute="trailing" id="1Bw-7c-t0I"/>
<constraint firstItem="oIB-Ti-Qn5" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" constant="8" id="9rG-2E-BrU"/>
<constraint firstItem="QsP-EC-SIH" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" id="KMq-M9-jdO"/>
<constraint firstAttribute="trailingMargin" secondItem="oIB-Ti-Qn5" secondAttribute="trailing" constant="8" id="Mrk-kq-6db"/>
<constraint firstItem="QsP-EC-SIH" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" constant="8" id="NT5-kY-VEB"/>
<constraint firstItem="QsP-EC-SIH" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" id="NT5-kY-VEB"/>
<constraint firstItem="xUq-E0-SXT" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leadingMargin" constant="8" id="Qp0-Kx-zHk"/>
<constraint firstItem="2fi-mo-0CV" firstAttribute="top" secondItem="oIB-Ti-Qn5" secondAttribute="bottom" constant="8" id="UZa-dd-D2R"/>
<constraint firstAttribute="trailingMargin" secondItem="xUq-E0-SXT" secondAttribute="trailing" constant="8" id="V15-CR-PRw"/>
<constraint firstItem="xUq-E0-SXT" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" constant="8" id="beG-NE-UJ6"/>
<constraint firstItem="oIB-Ti-Qn5" firstAttribute="top" secondItem="QsP-EC-SIH" secondAttribute="bottom" constant="8" id="umT-Bq-YxA"/>
<constraint firstItem="2fi-mo-0CV" firstAttribute="top" secondItem="QsP-EC-SIH" secondAttribute="bottom" id="ubM-Gs-TsR"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="Jsk-U4-VZ5"/>
<connections>
<outlet property="flashLightButton" destination="F6V-ms-4I3" id="iJk-mx-XsX"/>
<outlet property="informationLabel" destination="xUq-E0-SXT" id="5uS-IR-FCA"/>
<outlet property="previewView" destination="QsP-EC-SIH" id="6Qu-SJ-Wd2"/>
<outlet property="recognitionButton" destination="Df9-DJ-y6p" id="9z2-Ux-E35"/>
<outlet property="recognitionTextView" destination="6Wj-BC-sZL" id="Viy-eN-4xs"/>
<outlet property="regionOfInterest" destination="6pY-x2-Kns" id="lxx-Ma-0uS"/>
<outlet property="regionOfInterestHeight" destination="cNW-AJ-fGV" id="Y9U-89-gab"/>
<outlet property="regionOfInterestWidth" destination="WDj-L7-VyV" id="uhO-LS-yV2"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="136.80000000000001" y="133.5832083958021"/>
<point key="canvasLocation" x="1043.4782608695652" y="132.88043478260872"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="Gsk-aD-7Nm">
<objects>
<placeholder placeholderIdentifier="IBFirstResponder" id="sCD-cE-uai" userLabel="First Responder" sceneMemberID="firstResponder"/>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="92S-qF-W7g" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="MIO-oC-44V">
<rect key="frame" x="0.0" y="20" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="vXZ-lx-hvc" kind="relationship" relationship="rootViewController" id="zjW-ld-AS0"/>
</connections>
</navigationController>
</objects>
<point key="canvasLocation" x="136.23188405797103" y="132.88043478260872"/>
</scene>
</scenes>
<resources>
<image name="flashlightOff" width="36" height="48"/>
</resources>
</document>
@@ -2,6 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSCameraUsageDescription</key>
<string></string>
<key>CFBundleDevelopmentRegion</key>
@@ -26,22 +26,66 @@ class ViewController: UIViewController {

var engine: SwiftyTesseractRTE!
var excludeLayer: CAShapeLayer!
var flashlightButton: UIBarButtonItem!
var recognitionButton: UIButton!
var recognitionTitleLabel: UILabel!
var recognitionLabel: UILabel!

@IBOutlet weak var informationLabel: UILabel!
@IBOutlet weak var previewView: UIView!
@IBOutlet weak var regionOfInterest: UIView!
@IBOutlet weak var flashLightButton: UIButton!
@IBOutlet weak var recognitionButton: UIButton!
@IBOutlet weak var recognitionTextView: UITextView!
@IBOutlet weak var regionOfInterestWidth: NSLayoutConstraint!
@IBOutlet weak var regionOfInterestHeight: NSLayoutConstraint!

override func viewDidLoad() {
super.viewDidLoad()
let swiftyTesseract = SwiftyTesseract(language: .english)
engine = SwiftyTesseractRTE(swiftyTesseract: swiftyTesseract, desiredReliability: .verifiable)
engine.recognitionIsActive = false
engine.delegate = self

// MARK: - UI Setup
let navigationBar = navigationController?.navigationBar
let textAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]

if #available(iOS 11.0, *) {
navigationBar?.prefersLargeTitles = true
navigationBar?.largeTitleTextAttributes = textAttributes
}

navigationBar?.titleTextAttributes = textAttributes
navigationBar?.isTranslucent = false
navigationBar?.barTintColor = .black
navigationItem.title = "SwiftyTesseractRTE"

flashlightButton = UIBarButtonItem(title: "Flashlight On", style: .plain, target: self, action: #selector(flashLightButtonTapped(_:)))
navigationItem.rightBarButtonItem = flashlightButton

recognitionButton = UIButton()
recognitionButton.setTitleColor(view.tintColor, for: .normal)
recognitionButton.setTitle("Start Recognition", for: .normal)
recognitionButton.addTarget(self, action: #selector(recognitionButtonTapped(_:)), for: .touchUpInside)

recognitionTitleLabel = UILabel()
recognitionTitleLabel.text = "Recognition Text:"
recognitionTitleLabel.font = UIFont.systemFont(ofSize: 16, weight: .bold)
recognitionTitleLabel.textColor = .white

recognitionLabel = UILabel()
recognitionLabel.textAlignment = .center
recognitionLabel.numberOfLines = 20
recognitionLabel.textColor = .white
recognitionLabel.text = "Let's Do This!"

let stackView = UIStackView(arrangedSubviews: [recognitionButton, recognitionTitleLabel, recognitionLabel])
stackView.axis = .vertical
stackView.alignment = .center
stackView.distribution = .fill
stackView.spacing = 8.0
stackView.translatesAutoresizingMaskIntoConstraints = false

view.addSubview(stackView)
stackView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true
stackView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
stackView.topAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
stackView.bottomAnchor.constraint(lessThanOrEqualTo: view.bottomAnchor).isActive = true

let panGesture = UIPanGestureRecognizer(target: self, action: #selector(handlePan(_:)))

@@ -50,13 +94,18 @@ class ViewController: UIViewController {
regionOfInterest.layer.borderColor = UIColor.blue.cgColor
regionOfInterest.backgroundColor = .clear

recognitionButton.setTitle("Start Recognition", for: .normal)

excludeLayer = CAShapeLayer()
excludeLayer.fillRule = kCAFillRuleEvenOdd
excludeLayer.fillColor = UIColor.black.cgColor
excludeLayer.opacity = 0.7

// SwiftyTesseractRTE Setup
let swiftyTesseract = SwiftyTesseract(language: .english)
engine = SwiftyTesseractRTE(swiftyTesseract: swiftyTesseract, desiredReliability: .verifiable)
engine.recognitionIsActive = false
engine.delegate = self

engine.startPreview()
}

@@ -103,12 +152,11 @@ class ViewController: UIViewController {
informationLabel.isHidden = true
}


@IBAction func recognitionButtonTapped(_ sender: Any) {
@objc func recognitionButtonTapped(_ sender: Any) {
recognitionIsRunning.toggle()
}

@IBAction func flashLightButtonTapped(_ sender: Any) {
@objc func flashLightButtonTapped(_ sender: Any) {
guard let device = AVCaptureDevice.default(for: .video) else { return }
if device.hasTorch {
do {
@@ -119,8 +167,8 @@ class ViewController: UIViewController {
print("Error: \(e.localizedDescription)")
}
}
let flashlightImage = device.torchMode == .off ? UIImage(named: "flashlightOff") : UIImage(named: "flashlightOn")
flashLightButton.setImage(flashlightImage, for: .normal)
let flashlightButtonTitle = device.torchMode == .off ? "Flashlight On" : "Flashlight Off"
flashlightButton.title = flashlightButtonTitle
}
}

@@ -129,16 +177,18 @@ extension ViewController: SwiftyTesseractRTEDelegate {
func onRecognitionComplete(_ recognizedString: String) {
AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate))
DispatchQueue.main.async { [weak self] in
self?.recognitionTextView.text = recognizedString
self?.recognitionLabel.text = recognizedString
}
recognitionIsRunning = false
}

}

extension Bool {

mutating func toggle() {
self = !self
}

}

@@ -4,7 +4,7 @@
#### SwiftyTesseractRTE can only currently be used in portrait mode.

<p align="center">
<img alt="SwiftyTesseractRTE-example" src=https://lh3.googleusercontent.com/o-C41-Wb7uJ2kzKEMgZ3VYYfGEFlgrpo4q-XLXaJRbMiwGdwRPKSdY3pwOopXyT7xZhxUm0yF0CGCn_4p5j5Vg3abouQyaSzud10uGZ4WCSL2hlOU72csZEgS6cX7lclQxAAFPCJ=w2400 />
<img alt="SwiftyTesseractRTE-example" src=https://lh3.googleusercontent.com/21owOJe7Kll0JXp2hWr3CKCLvKlgpPcjpWaJpyXzyrsyBYFMY-Dl2wmOth_XWLNa7nCGis6fzuBxAJV0oR9OjagQZTZ2Kfgpl2Pm94SdBMiQEiOaA92i8yDeZYa9ojALX9YIGWgIGlfsF5PNTE02HsKz51i8ca54QWMkwCDeKj9FME63etqqhvrgxLOdwR9X5zwFUoqHumktqNLSOZYL6i6ar4qjNJ3SRWoTastaZGQcCltskrnYXuwDrIbYUcuP8_j9xAA7EmieZf13yMRSQ13qmZ7kT-pTQ578klIqo1cU_rnKyTFDOtuBjtH_6nf_5EpF3euFsC1UFB0pLA7nLcL70qfLvL2qk2jjnA0447xbvHsKR8JqCDbrbiEriD6LaVQhvuAQg0OWgqrDAFTU9ApQz5riq6EFTyVn_92IJC2cjISeZ9kftrHAGP2Kk6W2M7yDIKhy7-4YJq4zpsDKR50nSU0RKkilZX-bSq_MpDPGfa9ptwXR5SYDBVGd2Me3emY2NqqHhwlbXC-VO5keni8q87ISUEsoLJZ_6uQ8JE6AfnJ01VwSx3l9kl4cX2g1G3WzWZ5zWqEuw8G8nfKw_ZtjBnqDDN3cb_xKLHeHNE4WqIcGXCh9ZaZmmcizj1WUoXphRYBZQ3T_aBL9mOz_mEyQNDuvujo=w413-h734-no />
</p>

# About SwiftyTesseractRTE

0 comments on commit 621d160

Please sign in to comment.
You can’t perform that action at this time.