Created
June 7, 2017 02:47
-
-
Save Koze/706766a1627ff5e5ee3ab01bd4dd7141 to your computer and use it in GitHub Desktop.
Overlay Image from VNTextObservation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (UIImage *)overlayImageWithTextObservations:(NSArray<VNTextObservation *> *)results size:(CGSize)size | |
{ | |
UIGraphicsImageRenderer *renderer = [[UIGraphicsImageRenderer alloc] initWithSize:size]; | |
UIImage *overlayImage = [renderer imageWithActions:^(UIGraphicsImageRendererContext * _Nonnull rendererContext) { | |
CGAffineTransform t = CGAffineTransformIdentity; | |
t = CGAffineTransformScale(t, size.width, -size.height); | |
t = CGAffineTransformTranslate(t, 0, -1); | |
for (VNTextObservation *textObservation in results) { | |
[[UIColor redColor] setStroke]; | |
[[UIBezierPath bezierPathWithRect:CGRectApplyAffineTransform(textObservation.boundingBox, t)] stroke]; | |
for (VNRectangleObservation *rectangleObservation in textObservation.characterBoxes) { | |
[[UIColor blueColor] setStroke]; | |
[[UIBezierPath bezierPathWithRect:CGRectApplyAffineTransform(rectangleObservation.boundingBox, t)] stroke]; | |
} | |
} | |
}]; | |
return overlayImage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment