Last active
October 29, 2024 18:56
-
-
Save Koze/e59fa3098388265e578dee6b3ce89dd8 to your computer and use it in GitHub Desktop.
Text Detection with Vision Framework
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
- (void)detectWithImageURL:(NSURL *)URL | |
{ | |
VNImageRequestHandler *handler = [[VNImageRequestHandler alloc] initWithURL:URL options:@{}]; | |
VNDetectTextRectanglesRequest *request = [[VNDetectTextRectanglesRequest alloc] initWithCompletionHandler:^(VNRequest * _Nonnull request, NSError * _Nullable error) { | |
if (error) { | |
NSLog(@"%@", error); | |
} | |
else { | |
for (VNTextObservation *textObservation in request.results) { | |
// NSLog(@"%@", textObservation); | |
// NSLog(@"%@", textObservation.characterBoxes); | |
NSLog(@"%@", NSStringFromCGRect(textObservation.boundingBox)); | |
for (VNRectangleObservation *rectangleObservation in textObservation.characterBoxes) { | |
NSLog(@" |-%@", NSStringFromCGRect(rectangleObservation.boundingBox)); | |
} | |
} | |
} | |
}]; | |
request.reportCharacterBoxes = YES; | |
NSError *error; | |
[handler performRequests:@[request] error:&error]; | |
if (error) { | |
NSLog(@"%@", error); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment