From ece593cf775e93ecf5e93668eedfb8c68865f300 Mon Sep 17 00:00:00 2001 From: DOMLIANG Date: Wed, 10 Jun 2020 19:32:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0ios=E4=BA=BA=E8=84=B8?= =?UTF-8?q?=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 基于coreimage --- .../org.eclipse.buildship.core.prefs | 2 +- .../org.eclipse.buildship.core.prefs | 2 +- .../org.eclipse.buildship.core.prefs | 2 +- ios/Classes/ImageFacePlugin.m | 41 +++++++++++-------- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/android/.settings/org.eclipse.buildship.core.prefs b/android/.settings/org.eclipse.buildship.core.prefs index d0af573..a4101bf 100644 --- a/android/.settings/org.eclipse.buildship.core.prefs +++ b/android/.settings/org.eclipse.buildship.core.prefs @@ -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 diff --git a/example/android/.settings/org.eclipse.buildship.core.prefs b/example/android/.settings/org.eclipse.buildship.core.prefs index 0cdd27c..409cac3 100644 --- a/example/android/.settings/org.eclipse.buildship.core.prefs +++ b/example/android/.settings/org.eclipse.buildship.core.prefs @@ -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 diff --git a/example/android/app/.settings/org.eclipse.buildship.core.prefs b/example/android/app/.settings/org.eclipse.buildship.core.prefs index f9325ad..a4101bf 100644 --- a/example/android/app/.settings/org.eclipse.buildship.core.prefs +++ b/example/android/app/.settings/org.eclipse.buildship.core.prefs @@ -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 diff --git a/ios/Classes/ImageFacePlugin.m b/ios/Classes/ImageFacePlugin.m index 9535de7..dbd3f45 100644 --- a/ios/Classes/ImageFacePlugin.m +++ b/ios/Classes/ImageFacePlugin.m @@ -11,27 +11,34 @@ + (void)registerWithRegistrar:(NSObject*)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