美文网首页
CIDetector特征识别(iOS识别图片中的二维码)

CIDetector特征识别(iOS识别图片中的二维码)

作者: QL_fish | 来源:发表于2017-12-01 15:51 被阅读426次

简介

CIDetectorCore Image框架中提供的一个识别类,包括对人脸、形状、条码、文本的识别,本文主要介绍人脸特征识别。

人脸识别功能不单单可以对人脸进行获取,还可以获取眼睛和嘴等面部特征信息。但是CIDetector不包括面纹编码提取,也就是说CIDetector只能判断是不是人脸,而不能判断这张人脸是谁的,比如说面部打卡这种功能是实现不了的。

今天主要看CIDetector对图片当中二维码的识别

创建

    // CIDetector(CIDetector可用于人脸识别)进行图片解析,从而使我们可以便捷的从相册中获取到二维码
    // 声明一个 CIDetector,并设定识别类型 CIDetectorTypeQRCode
    // 创建图形上下文
    CIContext * context = [CIContext contextWithOptions:nil];
    // 创建自定义参数字典
    NSDictionary * param = [NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy];
    // 创建识别器对象
    CIDetector * detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:context options:param];
    
    // 取得识别结果
    NSArray *features = [detector featuresInImage:[CIImage imageWithCGImage:image.CGImage]];
    
    if (features.count == 0) {
        
        NSLog(@"暂未识别出扫描的二维码");
    } else {
        
        for (int index = 0; index < [features count]; index ++) {
            
            CIQRCodeFeature *feature = [features objectAtIndex:index];
            NSString *resultStr = feature.messageString;
            NSLog(@"相册中读取二维码数据信息 - - %@", resultStr);
        }
    }

我们先来看看识别器的类型都有哪些,这里我们设置的是CIDetectorTypeFace,人脸识别探测器类型。

// 人脸识别探测器类型
CORE_IMAGE_EXPORT NSString* const CIDetectorTypeFace NS_AVAILABLE(10_7, 5_0);
// 矩形检测探测器类型
CORE_IMAGE_EXPORT NSString* const CIDetectorTypeRectangle NS_AVAILABLE(10_10, 8_0);
// 条码检测探测器类型
CORE_IMAGE_EXPORT NSString* const CIDetectorTypeQRCode NS_AVAILABLE(10_10, 8_0);
// 文本检测探测器类型
#if __OBJC2__
CORE_IMAGE_EXPORT NSString* const CIDetectorTypeText NS_AVAILABLE(10_11, 9_0);
#endif

相关文章

网友评论

      本文标题:CIDetector特征识别(iOS识别图片中的二维码)

      本文链接:https://www.haomeiwen.com/subject/gyrwbxtx.html