This commit is contained in:
Xuan Hu (Sean) 2017-05-26 17:01:54 +08:00 коммит произвёл GitHub
Родитель f6ecaf8615
Коммит e67a1ff0fb
12 изменённых файлов: 50 добавлений и 26 удалений

Просмотреть файл

@ -87,7 +87,7 @@
HUD.labelText = @"Adding faces";
[HUD show: YES];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithSubscriptionKey:ProjectOxfordFaceSubscriptionKey];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithEndpointAndSubscriptionKey:ProjectOxfordFaceEndpoint key:ProjectOxfordFaceSubscriptionKey];
NSData *data = UIImageJPEGRepresentation(self.image, 0.8);
[client addPersonFaceWithPersonGroupId:self.group.groupId personId:self.person.personId data:data userData:nil faceRectangle:face.face.faceRectangle completionBlock:^(MPOAddPersistedFaceResult *addPersistedFaceResult, NSError *error) {

Просмотреть файл

@ -33,6 +33,7 @@
#import <CoreData/CoreData.h>
static NSString *const ProjectOxfordFaceSubscriptionKey = @"Your Subscription Key";
static NSString *const ProjectOxfordFaceEndpoint = @"https://westus.api.cognitive.microsoft.com/face/v1.0/";
@interface MPOAppDelegate : UIResponder <UIApplicationDelegate>

Просмотреть файл

@ -105,13 +105,13 @@
- (void)detectAction: (id)sender {
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithSubscriptionKey:ProjectOxfordFaceSubscriptionKey];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithEndpointAndSubscriptionKey:ProjectOxfordFaceEndpoint key:ProjectOxfordFaceSubscriptionKey];
NSData *data = UIImageJPEGRepresentation(_selectedImage, 0.8);
MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.labelText = @"deteting faces";
HUD.labelText = @"detecting faces";
[HUD show: YES];
[client detectWithData:data returnFaceId:YES returnFaceLandmarks:YES returnFaceAttributes:@[@(MPOFaceAttributeTypeGender), @(MPOFaceAttributeTypeAge), @(MPOFaceAttributeTypeHair), @(MPOFaceAttributeTypeFacialHair), @(MPOFaceAttributeTypeMakeup), @(MPOFaceAttributeTypeEmotion), @(MPOFaceAttributeTypeOcclusion), @(MPOFaceAttributeTypeExposure), @(MPOFaceAttributeTypeHeadPose), @(MPOFaceAttributeTypeAccessories)] completionBlock:^(NSArray<MPOFace *> *collection, NSError *error) {

Просмотреть файл

@ -105,7 +105,7 @@
}
[_resultGroups removeAllObjects];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithSubscriptionKey:ProjectOxfordFaceSubscriptionKey];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithEndpointAndSubscriptionKey:ProjectOxfordFaceEndpoint key:ProjectOxfordFaceSubscriptionKey];
[client groupWithFaceIds:faceIds completionBlock:^(MPOGroupResult *groupResult, NSError *error) {
//add all of the normal group members if they exist
@ -266,7 +266,7 @@
HUD.labelText = @"detecting faces";
[HUD show: YES];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithSubscriptionKey:ProjectOxfordFaceSubscriptionKey];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithEndpointAndSubscriptionKey:ProjectOxfordFaceEndpoint key:ProjectOxfordFaceSubscriptionKey];
NSData *data = UIImageJPEGRepresentation(_selectedImage, 0.8);
[client detectWithData:data returnFaceId:YES returnFaceLandmarks:YES returnFaceAttributes:@[] completionBlock:^(NSArray<MPOFace *> *collection, NSError *error) {
[HUD removeFromSuperview];

Просмотреть файл

@ -94,7 +94,7 @@
[self.navigationController.view addSubview:HUD];
HUD.labelText = @"Identifying faces";
[HUD show: YES];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithSubscriptionKey:ProjectOxfordFaceSubscriptionKey];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithEndpointAndSubscriptionKey:ProjectOxfordFaceEndpoint key:ProjectOxfordFaceSubscriptionKey];
[client identifyWithPersonGroupId:group.groupId faceIds:faceIds maxNumberOfCandidates:group.people.count completionBlock:^(NSArray<MPOIdentifyResult *> *collection, NSError *error) {
[HUD removeFromSuperview];
if (error) {
@ -311,7 +311,7 @@
HUD.labelText = @"detecting faces";
[HUD show: YES];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithSubscriptionKey:ProjectOxfordFaceSubscriptionKey];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithEndpointAndSubscriptionKey:ProjectOxfordFaceEndpoint key:ProjectOxfordFaceSubscriptionKey];
NSData *data = UIImageJPEGRepresentation(image, 0.8);
[client detectWithData:data returnFaceId:YES returnFaceLandmarks:YES returnFaceAttributes:@[] completionBlock:^(NSArray<MPOFace *> *collection, NSError *error) {
[HUD removeFromSuperview];

Просмотреть файл

@ -127,7 +127,7 @@
_intension = INTENSION_SAVE_PERSON;
[self createPerson];
} else {
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithSubscriptionKey:ProjectOxfordFaceSubscriptionKey];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithEndpointAndSubscriptionKey:ProjectOxfordFaceEndpoint key:ProjectOxfordFaceSubscriptionKey];
MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.labelText = @"Updating person";
@ -240,7 +240,7 @@
}
- (void)createPerson {
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithSubscriptionKey:ProjectOxfordFaceSubscriptionKey];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithEndpointAndSubscriptionKey:ProjectOxfordFaceEndpoint key:ProjectOxfordFaceSubscriptionKey];
MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.labelText = @"creating person";
@ -285,7 +285,7 @@
}
} else if (actionSheet.tag == 1) {
if (buttonIndex == 0) {
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithSubscriptionKey:ProjectOxfordFaceSubscriptionKey];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithEndpointAndSubscriptionKey:ProjectOxfordFaceEndpoint key:ProjectOxfordFaceSubscriptionKey];
MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.labelText = @"Deleting this face";
@ -320,7 +320,7 @@
HUD.labelText = @"detecting faces";
[HUD show: YES];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithSubscriptionKey:ProjectOxfordFaceSubscriptionKey];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithEndpointAndSubscriptionKey:ProjectOxfordFaceEndpoint key:ProjectOxfordFaceSubscriptionKey];
NSData *data = UIImageJPEGRepresentation(selectedImage, 0.8);
[client detectWithData:data returnFaceId:YES returnFaceLandmarks:YES returnFaceAttributes:@[] completionBlock:^(NSArray<MPOFace *> *collection, NSError *error) {
[HUD removeFromSuperview];

Просмотреть файл

@ -122,7 +122,7 @@
if (!self.group) {
[self createNewGroup];
} else {
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithSubscriptionKey:ProjectOxfordFaceSubscriptionKey];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithEndpointAndSubscriptionKey:ProjectOxfordFaceEndpoint key:ProjectOxfordFaceSubscriptionKey];
MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.labelText = @"saving group";
@ -210,7 +210,7 @@
}
- (void)createNewGroup {
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithSubscriptionKey:ProjectOxfordFaceSubscriptionKey];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithEndpointAndSubscriptionKey:ProjectOxfordFaceEndpoint key:ProjectOxfordFaceSubscriptionKey];
MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.labelText = @"Creating group";
@ -240,7 +240,7 @@
}
- (void)trainGroup {
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithSubscriptionKey:ProjectOxfordFaceSubscriptionKey];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithEndpointAndSubscriptionKey:ProjectOxfordFaceEndpoint key:ProjectOxfordFaceSubscriptionKey];
MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.labelText = @"Training group";
@ -299,7 +299,7 @@
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
if (actionSheet.tag == 0) {
if (buttonIndex == 0) {
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithSubscriptionKey:ProjectOxfordFaceSubscriptionKey];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithEndpointAndSubscriptionKey:ProjectOxfordFaceEndpoint key:ProjectOxfordFaceSubscriptionKey];
MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.labelText = @"Deleting this person";

Просмотреть файл

@ -104,7 +104,7 @@
[faceIds addObject:obj.face.faceId];
}
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithSubscriptionKey:ProjectOxfordFaceSubscriptionKey];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithEndpointAndSubscriptionKey:ProjectOxfordFaceEndpoint key:ProjectOxfordFaceSubscriptionKey];
[client findSimilarWithFaceId:_baseFaces[_selectedTargetIndex].face.faceId faceIds:faceIds completionBlock:^(NSArray<MPOSimilarFace *> *collection, NSError *error) {
[HUD removeFromSuperview];
@ -298,7 +298,7 @@
HUD.labelText = @"Detecting faces";
[HUD show: YES];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithSubscriptionKey:ProjectOxfordFaceSubscriptionKey];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithEndpointAndSubscriptionKey:ProjectOxfordFaceEndpoint key:ProjectOxfordFaceSubscriptionKey];
NSData *data = UIImageJPEGRepresentation(_selectedImage, 0.8);
[client detectWithData:data returnFaceId:YES returnFaceLandmarks:YES returnFaceAttributes:@[] completionBlock:^(NSArray<MPOFace *> *collection, NSError *error) {
[HUD removeFromSuperview];

Просмотреть файл

@ -237,7 +237,7 @@
}
- (void)verify: (id)sender {
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithSubscriptionKey:ProjectOxfordFaceSubscriptionKey];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithEndpointAndSubscriptionKey:ProjectOxfordFaceEndpoint key:ProjectOxfordFaceSubscriptionKey];
MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
@ -313,10 +313,10 @@
MBProgressHUD *HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view];
[self.navigationController.view addSubview:HUD];
HUD.labelText = @"deteting faces";
HUD.labelText = @"detecting faces";
[HUD show: YES];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithSubscriptionKey:ProjectOxfordFaceSubscriptionKey];
MPOFaceServiceClient *client = [[MPOFaceServiceClient alloc] initWithEndpointAndSubscriptionKey:ProjectOxfordFaceEndpoint key:ProjectOxfordFaceSubscriptionKey];
NSData *data = UIImageJPEGRepresentation(_selectedImage, 0.8);
[client detectWithData:data returnFaceId:YES returnFaceLandmarks:YES returnFaceAttributes:@[] completionBlock:^(NSArray<MPOFace *> *collection, NSError *error) {
[HUD removeFromSuperview];

Просмотреть файл

@ -73,12 +73,20 @@ typedef void (^MPOFaceListMetadataArrayCompletionBlock)(NSArray<MPOFaceListMetad
@interface MPOFaceServiceClient : NSObject
/**
* Creates an instance of MPOFaceServiceClient
* Creates an instance of MPOFaceServiceClient with default endpoint
* @param key subscription key to use face api
* @return MPOFaceServiceClient
*/
- (id)initWithSubscriptionKey:(NSString *)key;
/**
* Creates an instance of MPOFaceServiceClient with specific endpoint and subscription key
* @param endpoint the endpoint to use the face api
* @param key the subscription key to use the face api
* @return MPOFaceServiceClient
*/
- (id)initWithEndpointAndSubscriptionKey:(NSString *)endpoint key:(NSString *)key;
#pragma mark Face Detection APIs

Просмотреть файл

@ -31,10 +31,13 @@
#import "MPOFaceServiceClient.h"
static NSString *const DefaultEndpoint = @"https://westus.api.cognitive.microsoft.com/face/v1.0/";
@interface MPOFaceServiceClient ()
//private properties
typedef void(^PORequestCompletionBlock)(NSURLResponse *response, id responseObject, NSError *error);
@property NSString* subscriptionKey;
@property NSString* endpoint;
@end
@ -45,11 +48,25 @@ typedef void(^PORequestCompletionBlock)(NSURLResponse *response, id responseObje
self = [super init];
if (self) {
self.subscriptionKey = key;
self.endpoint = DefaultEndpoint;
}
return self;
}
- (id)initWithEndpointAndSubscriptionKey:(NSString *)endpoint key:(NSString *)key {
self = [super init];
if (self) {
self.endpoint = endpoint;
self.subscriptionKey = key;
}
return self;
}
#pragma mark Face
/*
* =============================================================
@ -642,8 +659,6 @@ typedef void(^PORequestCompletionBlock)(NSURLResponse *response, id responseObje
- (NSURLSessionDataTask *)startTaskWithHttpMethod:(NSString *)httpMethod path:(NSString *)path parameters:(NSDictionary *)params urlParams:(NSDictionary *)urlParams bodyData:(NSData *)bodyData completion:(PORequestCompletionBlock)completion {
NSString *basePath = @"https://westus.api.cognitive.microsoft.com/face/v1.0/";
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
if (!bodyData) {
@ -680,7 +695,7 @@ typedef void(^PORequestCompletionBlock)(NSURLResponse *response, id responseObje
}
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@%@", basePath, path, queryString]]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@%@", self.endpoint, path, queryString]]];
request.HTTPMethod = httpMethod;

Просмотреть файл

@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "ProjectOxfordFace"
s.version = "1.3.0"
s.version = "1.3.1"
s.summary = "Microsoft Cognitive Services - Face API iOS SDK"
s.description = <<-DESC
@ -10,7 +10,7 @@ Pod::Spec.new do |s|
s.screenshots = "https://github.com/Microsoft/Cognitive-Face-iOS/raw/master/SampleScreenshots/SampleScreenshot1.jpg","https://github.com/Microsoft/Cognitive-Face-iOS/raw/master/SampleScreenshots/SampleScreenshot2.jpg","https://github.com/Microsoft/Cognitive-Face-iOS/raw/master/SampleScreenshots/SampleScreenshot3.jpg","https://github.com/Microsoft/Cognitive-Face-iOS/raw/master/SampleScreenshots/SampleScreenshot4.jpg","https://github.com/Microsoft/Cognitive-Face-iOS/raw/master/SampleScreenshots/SampleScreenshot5.jpg","https://github.com/Microsoft/Cognitive-Face-iOS/raw/master/SampleScreenshots/SampleScreenshot6.jpg","https://github.com/Microsoft/Cognitive-Face-iOS/raw/master/SampleScreenshots/SampleScreenshot7.jpg","https://github.com/Microsoft/Cognitive-Face-iOS/raw/master/SampleScreenshots/SampleScreenshot8.jpg"
s.license = 'MIT'
s.author = { "Microsoft Cognitive Services SDK" => "oxfordGithub@microsoft.com" }
s.source = { :git => "https://github.com/Microsoft/Cognitive-Face-iOS.git", :branch => "master", :tag => '1.3.0' }
s.source = { :git => "https://github.com/Microsoft/Cognitive-Face-iOS.git", :branch => "master", :tag => '1.3.1' }
s.platform = :ios, '8.0'
s.requires_arc = true