Skip to content

Instantly share code, notes, and snippets.

@Koze
Created June 7, 2017 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Koze/706766a1627ff5e5ee3ab01bd4dd7141 to your computer and use it in GitHub Desktop.
Save Koze/706766a1627ff5e5ee3ab01bd4dd7141 to your computer and use it in GitHub Desktop.
Overlay Image from VNTextObservation
- (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