簡介
CIDetector
是Core Image
框架中提供的一個識別類怕品,包括對人臉野舶、形狀易迹、條碼、文本的識別平道,本文主要介紹人臉特征識別睹欲。
人臉識別功能不單單可以對人臉進(jìn)行獲取,還可以獲取眼睛和嘴等面部特征信息一屋。但是CIDetector
不包括面紋編碼提取窘疮,也就是說CIDetector
只能判斷是不是人臉,而不能判斷這張人臉是誰的冀墨,比如說面部打卡這種功能是實現(xiàn)不了的闸衫。
今天主要看CIDetector
對圖片當(dāng)中二維碼的識別
創(chuàng)建
// CIDetector(CIDetector可用于人臉識別)進(jìn)行圖片解析,從而使我們可以便捷的從相冊中獲取到二維碼
// 聲明一個 CIDetector诽嘉,并設(shè)定識別類型 CIDetectorTypeQRCode
// 創(chuàng)建圖形上下文
CIContext * context = [CIContext contextWithOptions:nil];
// 創(chuàng)建自定義參數(shù)字典
NSDictionary * param = [NSDictionary dictionaryWithObject:CIDetectorAccuracyHigh forKey:CIDetectorAccuracy];
// 創(chuàng)建識別器對象
CIDetector * detector = [CIDetector detectorOfType:CIDetectorTypeQRCode context:context options:param];
// 取得識別結(jié)果
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(@"相冊中讀取二維碼數(shù)據(jù)信息 - - %@", resultStr);
}
}
我們先來看看識別器的類型都有哪些蔚出,這里我們設(shè)置的是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