iOS机器学习-文字识别

文字识别,iOS12系统就已经加入了文字识别能力,但是对于中国的开发者来说用处很小,因为不支持汉语识别,iOS15系统解决了汉语识别问题,基本OC代码如下,

 VNRecognizeTextRequest *textRequest = [[VNRecognizeTextRequest alloc] initWithCompletionHandler:^(VNRequest * _Nonnull request, NSError * _Nullable error) {
                NSArray *observations = request.results;
                [self textRectangles:observations image:image complete:complete];
                NSLog(@"%@",observations);
                
            }];
            textRequest.recognitionLevel = VNRequestTextRecognitionLevelAccurate;
            textRequest.usesLanguageCorrection = NO;
            textRequest.recognitionLanguages = @[@"zh-Hans", @"en-US"];

            // 转换CIImage
            CIImage *convertImage = [[CIImage alloc]initWithImage:image];
            
            // 创建处理requestHandler
            VNImageRequestHandler *detectRequestHandler = [[VNImageRequestHandler alloc]initWithCIImage:convertImage options:@{}];
            // 发送识别请求
            [detectRequestHandler performRequests:@[textRequest] error:nil];


需要注意的有两点,低一点就是识别的等级,一个是精准,一个是快速,

第二点就是识别语言的先后顺序问题,因为识别是第一种语言失败后去识别第二种语言

你可能感兴趣的:(iOS机器学习-文字识别)