Skip to content

Commit

Permalink
feat: 添加ios人脸识别
Browse files Browse the repository at this point in the history
基于coreimage
  • Loading branch information
domliang committed Jun 10, 2020
1 parent 295c7a8 commit ece593c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.3))
connection.project.dir=../example/android
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home
Expand Down
2 changes: 1 addition & 1 deletion example/android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
connection.project.dir=app
eclipse.preferences.version=1
gradle.user.home=
java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.3))
connection.project.dir=..
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home
Expand Down
41 changes: 24 additions & 17 deletions ios/Classes/ImageFacePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,34 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
if ([@"hasFace" isEqualToString:call.method]) {

result(@(NO));
NSString *p = [call.arguments objectForKey:@"image"];
BOOL rst =[self checkFace: p];
result(@(rst));
} else {
result(FlutterMethodNotImplemented);
}
}

//-(Boolean)checkFace:(NSString*)p{
//
//// CIImage *myImage = [CIImage imageWithContentsOfURL:(nonnull NSURL *)]
////
//// CIContext *context = [CIContext context]; // 1
//// NSDictionary *opts = @{ CIDetectorAccuracy : CIDetectorAccuracyHigh }; // 2
//// CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeFace
//// context:context
//// options:opts]; // 3
////
//// opts = @{ CIDetectorImageOrientation :
//// [[myImage properties] valueForKey:kCGImagePropertyOrientation] }; // 4
//// NSArray *features = [detector featuresInImage:myImage options:opts]; // 5
//
//}
- (BOOL)checkFace:(NSString*)p{

NSURL * urlStr = [NSURL fileURLWithPath:p];

CIImage *myImage = [CIImage imageWithContentsOfURL:urlStr];

CIContext *context = [CIContext context]; // 1
NSDictionary *opts = @{ CIDetectorAccuracy : CIDetectorAccuracyHigh }; // 2
CIDetector *detector = [CIDetector detectorOfType:CIDetectorTypeFace
context:context
options:opts]; // 3

opts = @{ CIDetectorImageOrientation :
[[myImage properties] valueForKey:kCGImagePropertyOrientation] }; // 4
NSArray *features = [detector featuresInImage:myImage options:opts]; // 5
if (features.count >0) {
return YES;
} else {
return NO;
}
}

@end

0 comments on commit ece593c

Please sign in to comment.