人臉識別技術(shù)概念
所謂人臉識別技術(shù)炫欺,即基于人的臉部特征,對輸入的人臉圖象或者視頻流進(jìn)行判斷揉抵,首先判斷其是否存在人臉亡容。如果存在人臉,則進(jìn)一步的給出每個(gè)臉的位置冤今、大小和各個(gè)主要面部器官的位置信息闺兢。并依據(jù)這些信息,進(jìn)一步提取每個(gè)人臉中所蘊(yùn)涵的身份特征戏罢,并將其與已知的人臉進(jìn)行對比屋谭,從而識別每個(gè)人臉的身份。
人臉識別技術(shù)的發(fā)展前景
在這個(gè)刷臉的時(shí)代,人臉識別技術(shù)怎能不火龟糕。人臉識別技術(shù)桐磁,是目前生物科技上在可行性,穩(wěn)定性和準(zhǔn)確性等專業(yè)技術(shù)指標(biāo)中數(shù)值最高的技術(shù)讲岁。也是目前各行各業(yè)安全保衛(wèi)中運(yùn)用最廣我擂,效果最好的一種技術(shù)。在未來的幾年內(nèi)催首,它必將超越指紋識別等生物技術(shù)扶踊,成為生物識別技術(shù)領(lǐng)域的霸主。
列舉人臉識別在手機(jī)APP上的一些應(yīng)用
1.美圖秀秀邪惡大測試:識別面部表情,給出分?jǐn)?shù)和評價(jià)
2.百度圖片識圖功能
3.百度魔圖APP推出了“PK大咖”功能郎任,用戶只需要選取一張自己的大頭照秧耗,就可以通過人臉識別技術(shù)跟明星進(jìn)行PK,找到與你面部形象最為相似的明星大咖
4.百度錢包APP拍照付只是說當(dāng)你想買一款商品舶治,卻不知道商品的具體信息分井,這時(shí)候就可以用到百度錢包的拍照付,拍一下就能搜索到商品霉猛,選擇購買
5.支付寶APP人臉識別登錄
6.iPhoto 在蘋果的iPhoto中尺锚,同樣提供了人臉識別功能,用戶可以將圖片中的人臉和人名相匹配惜浅,該功能通過臉部檢測辨別照片中的人物瘫辩,再通過臉部識別找到與之特征相符的拍攝對象,幫你找到想找的人,甚至是海量的照片庫也不費(fèi)吹灰之力
7.圖圖搜是先找到淘寶上的同款伐厌,然后拿到產(chǎn)品tag承绸,接著根據(jù)tag、主顏色等信息進(jìn)行二次查找挣轨。最基本的技術(shù)還是相同圖像查找军熏,當(dāng)然也包含了商品主體識別。
Face++ 人臉識別demo
主要實(shí)現(xiàn)的功能是:給出兩張面孔,判斷兩張面孔的相似度
封裝YYFaceViewController
.h文件
//
// YYFaceViewController.h
// Demo_Face++
//
// Created by yyMae on 15/12/25.
// Copyright (c) 2015年 yyMae. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface YYFaceViewController : UIViewController<UINavigationControllerDelegate,UIImagePickerControllerDelegate>
@end
.m文件
//
// YYFaceViewController.m
// Demo_Face++
//
// Created by yyMae on 15/12/25.
// Copyright (c) 2015年 yyMae. All rights reserved.
//
#import "YYFaceViewController.h"
#import "FaceppAPI.h"
#define kwidth self.view.frame.size.width
#define height self.view.frame.size.height
#define btnBorder 40
#define imgBorder 20
@interface YYFaceViewController ()
//顯示圖片的imageView
@property (nonatomic,strong) UIImageView *firstImgV;
@property (nonatomic,strong) UIImageView *secondImgV;
//觸發(fā)比較相似度的button
@property (nonatomic,strong) UIButton *recognizedBtn;
//五官的相似度
@property (nonatomic,strong) NSString *eye;
@property (nonatomic,strong) NSString *eyebrow;
@property (nonatomic,strong) NSString *mouth;
@property (nonatomic,strong) NSString *nose;
@property (nonatomic,strong) NSString *similarity;
@property (nonatomic,strong) UITextView *similarityView;
//通過此標(biāo)記判斷選擇圖片要顯示到哪一個(gè)相框上
@property (nonatomic,assign) NSInteger imageTag;
@end
@implementation YYFaceViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
[self drawView];
}
- (void)drawView{
//創(chuàng)建兩個(gè)按鈕,點(diǎn)擊事件為選擇照片
UIButton *firstBtn = [UIButton buttonWithType:UIButtonTypeSystem];
firstBtn.frame = CGRectMake(btnBorder, 100, (kwidth - btnBorder * 3)/2, 30);
[firstBtn setTitle:@"setFirstPhoto" forState:UIControlStateNormal];
[firstBtn addTarget:self action:@selector(selectFirstPhoto) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:firstBtn];
UIButton *secondBtn = [UIButton buttonWithType:UIButtonTypeSystem];
secondBtn.frame = CGRectMake(CGRectGetMaxX(firstBtn.frame) + btnBorder, 100, (kwidth - btnBorder * 3)/2, 30);
[secondBtn setTitle:@"setSecondPhoto" forState:UIControlStateNormal];
[secondBtn addTarget:self action:@selector(selectSecondPhoto) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:secondBtn];
//創(chuàng)建兩個(gè)相框,顯示圖片
UIImageView *firstImgV = [[UIImageView alloc]initWithFrame:CGRectMake(imgBorder, 140, (kwidth - imgBorder *3)/2, (kwidth - imgBorder *3)/2 *height / kwidth)];
firstImgV.backgroundColor = [UIColor yellowColor];
[self.view addSubview:firstImgV];
self.firstImgV = firstImgV;
UIImageView *secondImgV = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(firstImgV.frame) + imgBorder, 140, (kwidth - imgBorder *3)/2, (kwidth - imgBorder *3)/2 *height / kwidth)];
secondImgV.backgroundColor = [UIColor yellowColor];
[self.view addSubview:secondImgV];
self.secondImgV = secondImgV;
//相似度監(jiān)測按鈕
UIButton *recognizedBtn = [UIButton buttonWithType:UIButtonTypeSystem];
recognizedBtn.frame = CGRectMake(self.view.bounds.size.width / 2, CGRectGetMaxY(secondImgV.frame) + 20, (kwidth - btnBorder * 3)/2, 30);
recognizedBtn.center = CGPointMake(self.view.bounds.size.width / 2, CGRectGetMaxY(secondImgV.frame) + 20);
[recognizedBtn setTitle:@"相似度計(jì)算(%)" forState:UIControlStateNormal];
[recognizedBtn addTarget:self action:@selector(recognized) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:recognizedBtn];
recognizedBtn.enabled = NO;
self.recognizedBtn = recognizedBtn;
//添加輸入框顯示輸出信息
UITextView *similarityView = [[UITextView alloc]initWithFrame:CGRectMake((kwidth - 300) / 2, CGRectGetMaxY(recognizedBtn.frame) + 10, 300, 150)];
similarityView.backgroundColor = [UIColor yellowColor];
[self.view addSubview:similarityView];
self.similarityView = similarityView;
}
//設(shè)置第一張圖片
- (void)selectFirstPhoto{
self.imageTag = 999;
[self alertController];
}
//設(shè)置第二張圖片
- (void)selectSecondPhoto{
self.imageTag = 888;
[self alertController];
}
//相似度監(jiān)測
- (void)recognized{
//獲取到兩張面孔的face_id
NSString *firstFace_id;
NSData *firstImgVData = UIImageJPEGRepresentation(self.firstImgV.image, 0.6);
FaceppResult *firstResult = [[FaceppAPI detection] detectWithURL:nil orImageData:firstImgVData];
NSArray *array1 = firstResult.content[@"face"];
if (array1.count == 1) {
firstFace_id = [firstResult content][@"face"][0][@"face_id"];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"未檢測到五官" delegate:self cancelButtonTitle:@"重新選擇圖片" otherButtonTitles: nil];
[alert show];
return;
}
NSString *secondFace_id;
NSData *secondImgVData = UIImageJPEGRepresentation(self.secondImgV.image, 0.6);
FaceppResult *secondResult = [[FaceppAPI detection] detectWithURL:nil orImageData:secondImgVData];
NSArray *array2 = secondResult.content[@"face"];
if (array2.count == 1) {
secondFace_id = [secondResult content][@"face"][0][@"face_id"];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"未檢測到五官" delegate:self cancelButtonTitle:@"重新選擇圖片" otherButtonTitles: nil];
[alert show];
return;
}
//比較二者的相似度
FaceppResult *similarResult = [[FaceppAPI recognition] compareWithFaceId1:firstFace_id andId2:secondFace_id async:NO];
if ([similarResult success]) {
self.eye = [similarResult content][@"component_similarity"][@"eye"];
self.eyebrow = [similarResult content][@"component_similarity"][@"eyebrow"];
self.mouth = [similarResult content][@"component_similarity"][@"mouth"];
self.nose = [similarResult content][@"component_similarity"][@"nose"];
self.similarity = [similarResult content][@"similarity"];
NSString *content = [NSString stringWithFormat:@"眼睛:%@\n眉毛:%@\n嘴巴:%@\n鼻子:%@\n綜合:%@",self.eye,self.eyebrow,self.mouth,self.nose,self.similarity];
self.similarityView.text = content;
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"未檢測到五官" delegate:self cancelButtonTitle:@"error" otherButtonTitles: nil];
[alert show];
return;
}
}
- (void)alertController{
UIAlertController * alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
//添加Button
[alertController addAction: [UIAlertAction actionWithTitle: @"拍照" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//處理點(diǎn)擊拍照
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
// 跳轉(zhuǎn)到相機(jī)或相冊頁面
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.allowsEditing = YES;
[self presentViewController:imagePickerController animated:YES completion:^{}];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"打開相機(jī)失敗" delegate:self cancelButtonTitle:@"取消" otherButtonTitles: nil];
[alert show];
}
}]];
[alertController addAction: [UIAlertAction actionWithTitle: @"從相冊選取" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action){
//處理點(diǎn)擊從相冊選取
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
// 跳轉(zhuǎn)到相機(jī)或相冊頁面
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.allowsEditing = YES;
[self presentViewController:imagePickerController animated:YES completion:^{}];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"打開相機(jī)失敗" delegate:self cancelButtonTitle:@"取消" otherButtonTitles: nil];
[alert show];
}
}]];
[alertController addAction: [UIAlertAction actionWithTitle: @"取消" style: UIAlertActionStyleCancel handler:nil]];
[self presentViewController:alertController animated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
[picker dismissViewControllerAnimated:YES completion:nil];
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
if (self.imageTag == 999) {
self.firstImgV.image = image;
}
if (self.imageTag == 888) {
self.secondImgV.image = image;
}
if (self.firstImgV.image && self.secondImgV.image) {
self.recognizedBtn.enabled = YES;
}
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
}
@end
效果見下圖: