├── .gitignore
├── FaceppDemo
├── FaceppDemo.xcworkspace
│ └── contents.xcworkspacedata
├── FaceppDemo
│ ├── FaceppDemo.xcodeproj
│ │ ├── project.pbxproj
│ │ └── project.xcworkspace
│ │ │ └── contents.xcworkspacedata
│ ├── FaceppDemo
│ │ ├── AppDelegate.h
│ │ ├── AppDelegate.m
│ │ ├── Assets.xcassets
│ │ │ ├── AppIcon.appiconset
│ │ │ │ ├── Contents.json
│ │ │ │ ├── icon_29_2.png
│ │ │ │ ├── icon_29_3.png
│ │ │ │ ├── icon_40_2.png
│ │ │ │ ├── icon_40_3.png
│ │ │ │ ├── icon_60_2.png
│ │ │ │ └── icon_60_3.png
│ │ │ └── Contents.json
│ │ ├── Base.lproj
│ │ │ ├── LaunchScreen.storyboard
│ │ │ ├── Localizable.strings
│ │ │ └── Main.storyboard
│ │ ├── Info.plist
│ │ ├── en.lproj
│ │ │ ├── LaunchScreen.strings
│ │ │ ├── Localizable.strings
│ │ │ └── Main.strings
│ │ ├── main.m
│ │ └── zh-Hans.lproj
│ │ │ ├── LaunchScreen.strings
│ │ │ ├── Localizable.strings
│ │ │ └── Main.strings
│ ├── FaceppDemoTests
│ │ ├── FaceppDemoTests.m
│ │ ├── Help
│ │ │ ├── VideoBufferReader.h
│ │ │ └── VideoBufferReader.m
│ │ ├── Info.plist
│ │ ├── MGFaceppTest.m
│ │ ├── MGPictureTest.m
│ │ ├── MGVideoTestVC.h
│ │ ├── MGVideoTestVC.m
│ │ ├── resources
│ │ │ ├── test_male.jpg
│ │ │ └── test_one_face.png
│ │ └── videoTest.m
│ ├── MGDetectPicture
│ │ ├── MGDetectPictureVC.h
│ │ └── MGDetectPictureVC.m
│ ├── MGDetectVideo
│ │ ├── Cells
│ │ │ ├── BaseCell.h
│ │ │ ├── BaseCell.m
│ │ │ ├── BaseCell.xib
│ │ │ ├── BaseCollectionCell.h
│ │ │ ├── BaseCollectionCell.m
│ │ │ ├── MCSetCell.h
│ │ │ ├── MCSetCell.m
│ │ │ ├── MCSetCell.xib
│ │ │ ├── MGFaceCompareCell.h
│ │ │ ├── MGFaceCompareCell.m
│ │ │ ├── TextCell.h
│ │ │ ├── TextCell.m
│ │ │ └── TextCell.xib
│ │ ├── Models
│ │ │ ├── BaseModel.h
│ │ │ ├── BaseModel.m
│ │ │ ├── MCSetModel.h
│ │ │ ├── MCSetModel.m
│ │ │ ├── MGFaceCompareModel.h
│ │ │ ├── MGFaceCompareModel.m
│ │ │ ├── MGFaceModelArray.h
│ │ │ ├── MGFaceModelArray.m
│ │ │ ├── TextModel.h
│ │ │ └── TextModel.m
│ │ └── ViewControllers
│ │ │ ├── MGFaceListViewController.h
│ │ │ ├── MGFaceListViewController.m
│ │ │ ├── MGFaceListViewController.storyboard
│ │ │ ├── MGMarkSetViewController.h
│ │ │ ├── MGMarkSetViewController.m
│ │ │ ├── MGVideoViewController.h
│ │ │ └── MGVideoViewController.mm
│ ├── MGFaceppSDK
│ │ ├── MGAlgorithmInfo.h
│ │ ├── MGDetectRectInfo.h
│ │ ├── MGFaceInfo.h
│ │ ├── MGFacepp.h
│ │ ├── MGFaceppCommon.h
│ │ ├── MGFaceppConfig.h
│ │ ├── MGImageData.h
│ │ ├── libMGFacepp-0.5.2.a
│ │ └── megviifacepp_0_5_2_model
│ ├── MGHelp
│ │ ├── MGFileManager.h
│ │ ├── MGFileManager.m
│ │ └── MGHeader.h
│ ├── MGLicenseManagerHelper
│ │ ├── MGFaceLicenseHandle.h
│ │ ├── MGFaceLicenseHandle.m
│ │ └── MGNetAccount.h
│ ├── MainViewController.h
│ ├── MainViewController.m
│ ├── OpenGL
│ │ ├── GLUtilities
│ │ │ ├── GLESUtils.h
│ │ │ └── GLESUtils.m
│ │ ├── MGOpenGLView.h
│ │ ├── MGOpenGLView.m
│ │ └── Manager
│ │ │ ├── MGOpenGLConfig.h
│ │ │ ├── MGOpenGLRenderer.h
│ │ │ └── MGOpenGLRenderer.m
│ └── Resources
│ │ ├── Shaders
│ │ ├── Face3DFragment.glsl
│ │ ├── Face3DVertex.glsl
│ │ ├── FacePointColor.glsl
│ │ ├── FacePointSize.glsl
│ │ ├── VideoFrag.glsl
│ │ └── VideoVert.glsl
│ │ ├── appImages
│ │ ├── 1280_720.png
│ │ ├── 1280_720@3x.png
│ │ ├── 1920_1080.png
│ │ ├── 1920_1080@3x.png
│ │ ├── 3D-0.png
│ │ ├── 3D-1.png
│ │ ├── 640_480.png
│ │ ├── 640_480@3x.png
│ │ ├── 81-0.png
│ │ ├── 81-1.png
│ │ ├── 960_540.png
│ │ ├── 960_540@3x.png
│ │ ├── IMG_2393.JPG
│ │ ├── area-0.png
│ │ ├── area-1.png
│ │ ├── card_front.png
│ │ ├── compare
│ │ │ ├── faceCompare-0.png
│ │ │ ├── faceCompare-1.png
│ │ │ ├── regist.png
│ │ │ ├── selected.png
│ │ │ ├── unSelected.png
│ │ │ └── user.png
│ │ ├── debug-0.png
│ │ ├── debug-1.png
│ │ ├── faceLogo.png
│ │ ├── faceinfo-0.png
│ │ ├── faceinfo-1.png
│ │ ├── megviicloud logo.png
│ │ ├── pw.png
│ │ ├── record-0.png
│ │ ├── record-1.png
│ │ ├── screen-0.png
│ │ ├── screen-1.png
│ │ ├── shader-0.png
│ │ ├── shader-1.png
│ │ ├── side-0.png
│ │ ├── side-1.png
│ │ ├── textrec-0.png
│ │ └── textrec-1.png
│ │ └── detectImages
│ │ ├── 81_points_position.jpg
│ │ ├── background.png
│ │ ├── skin.png
│ │ └── standard_alpha.png
└── MGBaseKit
│ ├── MGAnimation.h
│ ├── MGAnimation.m
│ ├── MGAutoSessionPreset.h
│ ├── MGAutoSessionPreset.m
│ ├── MGBaseDefine.h
│ ├── MGBaseKit.h
│ ├── MGBaseKit.xcodeproj
│ ├── project.pbxproj
│ └── project.xcworkspace
│ │ └── contents.xcworkspacedata
│ ├── MGBaseKit
│ └── Info.plist
│ ├── MGImage.h
│ ├── MGImage.mm
│ ├── MGLogManager.h
│ ├── MGLogManager.mm
│ ├── MGMovieRecorder.h
│ ├── MGMovieRecorder.m
│ ├── MGVideoManager.h
│ ├── MGVideoManager.mm
│ └── MegviiLicMgr-iOS-SDK
│ ├── MGLicenseCommon.h
│ ├── MGLicenseManager.h
│ └── libMGLicMgrSDK-0.3.0.a
├── LICENSE
├── MGFacepp.xcworkspace
└── contents.xcworkspacedata
├── MGFacepp
├── MGFacepp.xcodeproj
│ ├── project.pbxproj
│ └── project.xcworkspace
│ │ └── contents.xcworkspacedata
├── MGFacepp
│ ├── MGAlgorithmInfo.h
│ ├── MGAlgorithmInfo.m
│ ├── MGAlgorithmInfo_Creat.h
│ ├── MGDetectRectInfo.h
│ ├── MGDetectRectInfo.m
│ ├── MGFaceInfo.h
│ ├── MGFaceInfo.m
│ ├── MGFaceInfo_Creat.h
│ ├── MGFacepp.h
│ ├── MGFacepp.m
│ ├── MGFaceppCommon.h
│ ├── MGFaceppConfig.h
│ ├── MGFaceppConfig.m
│ ├── MGImageData.h
│ └── MGImageData.m
└── MegviiFacepp_C_SDK
│ ├── MG_Common.h
│ ├── MG_Facepp.h
│ ├── libMegviiFacepp-0.5.2.a
│ └── megviifacepp_0_5_2_model
├── MGFaceppSDKTest
├── MGFaceppSDKTest.xcodeproj
│ ├── project.pbxproj
│ └── project.xcworkspace
│ │ └── contents.xcworkspacedata
├── MGFaceppSDKTestTests
│ ├── Info.plist
│ └── MGFaceppSDKTestTests.m
└── SDKTest
│ ├── 2.png
│ ├── 3.jpg
│ ├── 81_points_position.jpg
│ ├── AppDelegate.h
│ ├── AppDelegate.m
│ ├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
│ ├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
│ ├── Info.plist
│ ├── ViewController.h
│ ├── ViewController.mm
│ ├── main.m
│ └── standard_alpha.png
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | tignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
3 |
4 | #
5 | .DS_Store
6 |
7 | ## Build generated
8 | build/
9 | DerivedData/
10 |
11 | ## Various settings
12 | *.pbxuser
13 | !default.pbxuser
14 | *.mode1v3
15 | !default.mode1v3
16 | *.mode2v3
17 | !default.mode2v3
18 | *.perspectivev3
19 | !default.perspectivev3
20 | xcuserdata/
21 |
22 | ## Other
23 | *.moved-aside
24 | *.xcuserstate
25 |
26 | ## Obj-C/Swift specific
27 | *.hmap
28 | *.ipa
29 | *.dSYM.zip
30 | *.dSYM
31 |
32 | # CocoaPods
33 | #
34 | # We recommend against adding the Pods directory to your .gitignore. However
35 | # you should judge for yourself, the pros and cons are mentioned at:
36 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
37 | #
38 | # Pods/
39 |
40 | # Carthage
41 | #
42 | # Add this line if you want to avoid checking in source code from Carthage dependencies.
43 | # Carthage/Checkouts
44 |
45 | Carthage/Build
46 |
47 | # fastlane
48 | #
49 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
50 | # screenshots whenever they are needed.
51 | # For more information about the recommended setup visit:
52 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md
53 |
54 | fastlane/report.xml
55 | fastlane/Preview.html
56 | fastlane/screenshots
57 | fastlane/test_output
58 |
59 | # Code Injection
60 | #
61 | # After new code Injection tools there's a generated folder /iOSInjectionProject
62 | # https://github.com/johnno1962/injectionforxcode
63 |
64 | iOSInjectionProject/
65 |
66 | # model .a
67 |
68 | megviifacepp*model
69 | *.a
70 |
71 | # net account
72 |
73 | MGNetAccount.h
74 |
75 | # ignore folder
76 | *gitignore
77 |
78 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // MGSDKV2Test
4 | //
5 | // Created by 张英堂 on 16/9/5.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // MGSDKV2Test
4 | //
5 | // Created by 张英堂 on 16/9/5.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 |
11 | @interface AppDelegate ()
12 |
13 | @end
14 |
15 | @implementation AppDelegate
16 |
17 |
18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
19 | // Override point for customization after application launch.
20 | return YES;
21 | }
22 |
23 | - (void)applicationWillResignActive:(UIApplication *)application {
24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
26 | }
27 |
28 | - (void)applicationDidEnterBackground:(UIApplication *)application {
29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
31 | }
32 |
33 | - (void)applicationWillEnterForeground:(UIApplication *)application {
34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
35 | }
36 |
37 | - (void)applicationDidBecomeActive:(UIApplication *)application {
38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
39 | }
40 |
41 | - (void)applicationWillTerminate:(UIApplication *)application {
42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
43 | }
44 |
45 | @end
46 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "20x20",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "20x20",
11 | "scale" : "3x"
12 | },
13 | {
14 | "size" : "29x29",
15 | "idiom" : "iphone",
16 | "filename" : "icon_29_2.png",
17 | "scale" : "2x"
18 | },
19 | {
20 | "size" : "29x29",
21 | "idiom" : "iphone",
22 | "filename" : "icon_29_3.png",
23 | "scale" : "3x"
24 | },
25 | {
26 | "size" : "40x40",
27 | "idiom" : "iphone",
28 | "filename" : "icon_40_2.png",
29 | "scale" : "2x"
30 | },
31 | {
32 | "size" : "40x40",
33 | "idiom" : "iphone",
34 | "filename" : "icon_40_3.png",
35 | "scale" : "3x"
36 | },
37 | {
38 | "size" : "60x60",
39 | "idiom" : "iphone",
40 | "filename" : "icon_60_2.png",
41 | "scale" : "2x"
42 | },
43 | {
44 | "size" : "60x60",
45 | "idiom" : "iphone",
46 | "filename" : "icon_60_3.png",
47 | "scale" : "3x"
48 | },
49 | {
50 | "idiom" : "ios-marketing",
51 | "size" : "1024x1024",
52 | "scale" : "1x"
53 | }
54 | ],
55 | "info" : {
56 | "version" : 1,
57 | "author" : "xcode"
58 | }
59 | }
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo/Assets.xcassets/AppIcon.appiconset/icon_29_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/FaceppDemo/Assets.xcassets/AppIcon.appiconset/icon_29_2.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo/Assets.xcassets/AppIcon.appiconset/icon_29_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/FaceppDemo/Assets.xcassets/AppIcon.appiconset/icon_29_3.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo/Assets.xcassets/AppIcon.appiconset/icon_40_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/FaceppDemo/Assets.xcassets/AppIcon.appiconset/icon_40_2.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo/Assets.xcassets/AppIcon.appiconset/icon_40_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/FaceppDemo/Assets.xcassets/AppIcon.appiconset/icon_40_3.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo/Assets.xcassets/AppIcon.appiconset/icon_60_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/FaceppDemo/Assets.xcassets/AppIcon.appiconset/icon_60_2.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo/Assets.xcassets/AppIcon.appiconset/icon_60_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/FaceppDemo/Assets.xcassets/AppIcon.appiconset/icon_60_3.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo/Base.lproj/Localizable.strings:
--------------------------------------------------------------------------------
1 | /*
2 | InfoPlist.strings
3 | FaceppDemo
4 |
5 | Created by 张英堂 on 2017/4/13.
6 | Copyright © 2017年 megvii. All rights reserved.
7 | */
8 |
9 |
10 | icon_title1 = "录像";
11 | icon_title2 = "3D模型";
12 | icon_title3 = "调试信息";
13 | icon_title4 = "区域选择";
14 | icon_title5 = "人脸属性";
15 | icon_title6 = "前置摄像头";
16 | icon_title7 = "后置摄像头";
17 | icon_title8 = "最小人脸";
18 | icon_title9 = "显示帧率";
19 | icon_title10 = "检测间隔";
20 | icon_title11 = "关键点个数";
21 | icon_title12 = "相机分辨率";
22 | icon_title13 = "单脸跟踪";
23 | icon_title14 = "跟踪模式";
24 | icon_title17 = "检测人脸";
25 | icon_title18 = "返回";
26 | icon_title19 = "人脸识别演示";
27 |
28 | icon_title15 = "Fast";
29 | icon_title16 = "Robust";
30 | icon_title21 = "detect_rect";
31 | icon_title22 = "track_rect";
32 |
33 | icon_title_face_compare = "人脸比对";
34 |
35 |
36 | alert_title = "取消";
37 | alert_title2 = "请选择";
38 | alert_title_input_user_name = "输入用户名";
39 | alert_title_no_face = "未检测到人脸";
40 | alert_title_camera = "请在iPhone的“设置-隐私-相机”选项中,允许 Face++ 访问你的相机";
41 | alert_title_resolution = "前置摄像头不支持此分辨率";
42 |
43 | alert_action_ok = "确定";
44 |
45 | alert_message1 = "错误的视频配置,该摄像头不支持 1080P 分辨率";
46 | alert_message2 = "警告";
47 | alert_message3 = "完成";
48 | alert_message4 = "最小值为 1,最大值为 1000";
49 |
50 |
51 | debug_message1 = "是否需要联网授权";
52 | debug_message2 = "版本号";
53 | debug_message3 = "SDK支持功能";
54 | debug_message4 = "关键点";
55 | debug_message5 = "3D角度";
56 | debug_message6 = "质量";
57 | debug_message7 = "人脸数量";
58 |
59 |
60 | viewController_title_choose_face = "选择人脸";
61 |
62 | navigationBar_back = "返回";
63 |
64 | button_title_cancel_all = "全部取消";
65 | button_title_register = "注册";
66 |
67 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | MC Face++ Demo
9 | CFBundleExecutable
10 | $(EXECUTABLE_NAME)
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | 0.5.2
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | 1
25 | LSRequiresIPhoneOS
26 |
27 | NSAppTransportSecurity
28 |
29 | NSAllowsArbitraryLoads
30 |
31 |
32 | NSCameraUsageDescription
33 |
34 | NSPhotoLibraryUsageDescription
35 |
36 | UILaunchStoryboardName
37 | LaunchScreen
38 | UIMainStoryboardFile
39 | Main
40 | UIRequiredDeviceCapabilities
41 |
42 | armv7
43 |
44 | UIStatusBarStyle
45 | UIStatusBarStyleLightContent
46 | UISupportedInterfaceOrientations
47 |
48 | UIInterfaceOrientationPortrait
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo/en.lproj/LaunchScreen.strings:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo/en.lproj/Localizable.strings:
--------------------------------------------------------------------------------
1 | /*
2 | InfoPlist.strings
3 | FaceppDemo
4 |
5 | Created by 张英堂 on 2017/4/13.
6 | Copyright © 2017年 megvii. All rights reserved.
7 | */
8 |
9 | icon_title1 = "Record";
10 | icon_title2 = "3D Pose";
11 | icon_title3 = "Debug";
12 | icon_title4 = "ROI";
13 | icon_title5 = "Attributes";
14 | icon_title6 = "Front";
15 | icon_title7 = "Back";
16 | icon_title8 = "Min Face";
17 | icon_title9 = "FPS";
18 | icon_title10 = "Interval";
19 | icon_title11 = "Landmarks";
20 | icon_title12 = "Resolution";
21 | icon_title13 = "One Face Tracking";
22 | icon_title14 = "Tracking Mode";
23 | icon_title17 = "Detect Face";
24 | icon_title18 = "Back";
25 | icon_title19 = "Face++ Demo";
26 |
27 | icon_title15 = "Fast";
28 | icon_title16 = "Robust";
29 | icon_title21 = "detect_rect";
30 | icon_title22 = "track_rect";
31 |
32 | icon_title_face_compare = "Compare";
33 |
34 | alert_title = "cancel";
35 | alert_title2 = "select";
36 | alert_title_input_user_name = "Input userName";
37 | alert_title_no_face = "Did not find face";
38 | alert_title_camera = "Please allow WeChat to access your device's camera in \"Settings\"->\"privacy\"->\"Camera\".";
39 | alert_title_resolution = "Front-facing camera does not support this resolution";
40 |
41 | alert_action_ok = "ok";
42 |
43 | alert_message1 = "can not open 1080P!";
44 | alert_message2 = "warning";
45 | alert_message3 = "down";
46 | alert_message4 = "min 1,max 1000";
47 |
48 |
49 | debug_message1 = "Need Net License";
50 | debug_message2 = "Version";
51 | debug_message3 = "SDK Function";
52 | debug_message4 = "Landmarks";
53 | debug_message5 = "3D Pose";
54 | debug_message6 = "Confidence";
55 | debug_message7 = "Face Count";
56 |
57 |
58 | viewController_title_choose_face = "Choose Face";
59 |
60 | navigationBar_back = "Back";
61 |
62 | button_title_cancel_all = "cancelAll";
63 | button_title_register = "Register";
64 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo/en.lproj/Main.strings:
--------------------------------------------------------------------------------
1 |
2 | /* Class = "UILabel"; text = "face info"; ObjectID = "IYs-8K-NTt"; */
3 | "IYs-8K-NTt.text" = "face info";
4 |
5 | /* Class = "UILabel"; text = "message"; ObjectID = "LgV-yD-fyP"; */
6 | "LgV-yD-fyP.text" = "message";
7 |
8 | /* Class = "UIButton"; normalTitle = "开始检测"; ObjectID = "OAZ-4Q-Yl6"; */
9 | "OAZ-4Q-Yl6.normalTitle" = "Detect Face";
10 |
11 | /* Class = "UIButton"; normalTitle = "检测人脸"; ObjectID = "TMt-7D-evW"; */
12 | "TMt-7D-evW.normalTitle" = "Detect Face";
13 |
14 | /* Class = "UINavigationItem"; title = "实时人脸检测"; ObjectID = "puV-yq-SfP"; */
15 | "puV-yq-SfP.title" = "Detect Face";
16 |
17 | /* Class = "UIButton"; normalTitle = "单张图片测试"; ObjectID = "s0h-Nz-MPi"; */
18 | "s0h-Nz-MPi.normalTitle" = "Single Image Test";
19 |
20 | /* Class = "UIButton"; normalTitle = "实时视频检测"; ObjectID = "z0F-tg-AZW"; */
21 | "z0F-tg-AZW.normalTitle" = "Detect Face";
22 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // MGSDKV2Test
4 | //
5 | // Created by 张英堂 on 16/9/5.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo/zh-Hans.lproj/LaunchScreen.strings:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo/zh-Hans.lproj/Localizable.strings:
--------------------------------------------------------------------------------
1 | /*
2 | InfoPlist.strings
3 | FaceppDemo
4 |
5 | Created by 张英堂 on 2017/4/13.
6 | Copyright © 2017年 megvii. All rights reserved.
7 | */
8 |
9 |
10 | icon_title1 = "录像";
11 | icon_title2 = "3D模型";
12 | icon_title3 = "调试信息";
13 | icon_title4 = "区域选择";
14 | icon_title5 = "人脸属性";
15 | icon_title6 = "前置摄像头";
16 | icon_title7 = "后置摄像头";
17 | icon_title8 = "最小人脸";
18 | icon_title9 = "显示帧率";
19 | icon_title10 = "检测间隔";
20 | icon_title11 = "关键点个数";
21 | icon_title12 = "相机分辨率";
22 | icon_title13 = "单脸跟踪";
23 | icon_title14 = "跟踪模式";
24 | icon_title17 = "检测人脸";
25 | icon_title18 = "返回";
26 | icon_title19 = "人脸识别演示";
27 |
28 | icon_title15 = "Fast";
29 | icon_title16 = "Robust";
30 | icon_title21 = "detect_rect";
31 | icon_title22 = "track_rect";
32 |
33 | icon_title_face_compare = "人脸比对";
34 |
35 | alert_title = "取消";
36 | alert_title2 = "请选择";
37 | alert_title_input_user_name = "输入用户名";
38 | alert_title_no_face = "未检测到人脸";
39 | alert_title_camera = "请在iPhone的“设置-隐私-相机”选项中,允许 Face++ 访问你的相机";
40 | alert_title_resolution = "前置摄像头不支持此分辨率";
41 |
42 | alert_action_ok = "确定";
43 |
44 | alert_message1 = "错误的视频配置,该摄像头不支持 1080P 分辨率";
45 | alert_message2 = "警告";
46 | alert_message3 = "完成";
47 | alert_message4 = "最小值为 1,最大值为 1000";
48 |
49 |
50 | debug_message1 = "是否需要联网授权";
51 | debug_message2 = "版本号";
52 | debug_message3 = "SDK支持功能";
53 | debug_message4 = "关键点";
54 | debug_message5 = "3D角度";
55 | debug_message6 = "质量";
56 | debug_message7 = "人脸数量";
57 |
58 |
59 | viewController_title_choose_face = "选择人脸";
60 |
61 | navigationBar_back = "返回";
62 |
63 | button_title_cancel_all = "全部取消";
64 | button_title_register = "注册";
65 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemo/zh-Hans.lproj/Main.strings:
--------------------------------------------------------------------------------
1 |
2 | /* Class = "UINavigationItem"; title = "FACE ++"; ObjectID = "Ccd-Xh-4w0"; */
3 | "Ccd-Xh-4w0.title" = "FACE ++";
4 |
5 | /* Class = "UILabel"; text = "face info"; ObjectID = "IYs-8K-NTt"; */
6 | "IYs-8K-NTt.text" = "face info";
7 |
8 | /* Class = "UILabel"; text = "message"; ObjectID = "LgV-yD-fyP"; */
9 | "LgV-yD-fyP.text" = "message";
10 |
11 | /* Class = "UIButton"; normalTitle = "开始检测"; ObjectID = "OAZ-4Q-Yl6"; */
12 | "OAZ-4Q-Yl6.normalTitle" = "开始检测";
13 |
14 | /* Class = "UIButton"; normalTitle = "检测人脸"; ObjectID = "TMt-7D-evW"; */
15 | "TMt-7D-evW.normalTitle" = "检测人脸";
16 |
17 | /* Class = "UINavigationItem"; title = "实时人脸检测"; ObjectID = "puV-yq-SfP"; */
18 | "puV-yq-SfP.title" = "实时人脸检测";
19 |
20 | /* Class = "UIButton"; normalTitle = "单张图片测试"; ObjectID = "s0h-Nz-MPi"; */
21 | "s0h-Nz-MPi.normalTitle" = "单张图片测试";
22 |
23 | /* Class = "UIButton"; normalTitle = "实时视频检测"; ObjectID = "z0F-tg-AZW"; */
24 | "z0F-tg-AZW.normalTitle" = "实时视频检测";
25 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemoTests/FaceppDemoTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // FaceppDemoTests.m
3 | // FaceppDemoTests
4 | //
5 | // Created by Megvii on 2017/8/11.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface FaceppDemoTests : XCTestCase
12 |
13 | @end
14 |
15 | @implementation FaceppDemoTests
16 |
17 | - (void)setUp {
18 | [super setUp];
19 | // Put setup code here. This method is called before the invocation of each test method in the class.
20 | }
21 |
22 | - (void)tearDown {
23 | // Put teardown code here. This method is called after the invocation of each test method in the class.
24 | [super tearDown];
25 | }
26 |
27 | - (void)testExample {
28 | // This is an example of a functional test case.
29 | // Use XCTAssert and related functions to verify your tests produce the correct results.
30 | }
31 |
32 | - (void)testPerformanceExample {
33 | // This is an example of a performance test case.
34 | [self measureBlock:^{
35 | // Put the code you want to measure the time of here.
36 | }];
37 | }
38 |
39 | @end
40 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemoTests/Help/VideoBufferReader.h:
--------------------------------------------------------------------------------
1 | //
2 | // BufferReader.h
3 | // FaceDetectionProcessor
4 | //
5 | // Created by Vitaliy Malakhovskiy on 7/3/14.
6 | // Copyright (c) 2014 Vitaliy Malakhovskiy. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 | #import
12 |
13 | @class AVAsset;
14 | @protocol VideoBufferReaderDelegate;
15 |
16 | @interface VideoBufferReader : NSObject
17 |
18 | - (instancetype)initWithDelegate:(id )delegate;
19 |
20 | - (void)startReading:(NSString *)video;
21 |
22 | - (void)cancelReading;
23 |
24 | @end
25 |
26 |
27 |
28 | @protocol VideoBufferReaderDelegate
29 |
30 | - (void)bufferReader:(VideoBufferReader *)reader didFinishReadingAsset:(AVAsset *)asset;
31 | - (void)bufferReader:(VideoBufferReader *)reader didGetNextVideoSample:(CMSampleBufferRef)bufferRef;
32 | - (void)bufferReader:(VideoBufferReader *)reader didGetErrorRedingSample:(NSError *)error;
33 | - (void)bufferReaderDidCancelled;
34 |
35 | @end
36 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemoTests/Help/VideoBufferReader.m:
--------------------------------------------------------------------------------
1 | //
2 | // BufferReader.m
3 | // FaceDetectionProcessor
4 | //
5 | // Created by Vitaliy Malakhovskiy on 7/3/14.
6 | // Copyright (c) 2014 Vitaliy Malakhovskiy. All rights reserved.
7 | //
8 |
9 | #import "VideoBufferReader.h"
10 | #import
11 |
12 | @interface VideoBufferReader () {
13 | struct DelegateMethods {
14 | unsigned int didGetNextVideoSample : 1;
15 | unsigned int didGetErrorRedingSample : 1;
16 | unsigned int didFinishReadingSample : 1;
17 | } _delegateMethods;
18 |
19 | }
20 |
21 | @property (nonatomic, weak) id delegate;
22 | @property (nonatomic, strong) AVAssetReader *reader;
23 | @end
24 |
25 | @implementation VideoBufferReader
26 |
27 | - (instancetype)initWithDelegate:(id)delegate {
28 | if (self = [super init]) {
29 | _delegate = delegate;
30 | _delegateMethods.didGetNextVideoSample = [self.delegate respondsToSelector:@selector(bufferReader:didGetNextVideoSample:)];
31 | _delegateMethods.didGetErrorRedingSample = [self.delegate respondsToSelector:@selector(bufferReader:didGetErrorRedingSample:)];
32 | _delegateMethods.didFinishReadingSample = [self.delegate respondsToSelector:@selector(bufferReader:didFinishReadingAsset:)];
33 | }
34 | return self;
35 | }
36 |
37 | - (void)startReading:(NSString *)video {
38 |
39 | NSString *videoPath = [[NSBundle mainBundle] pathForResource:video ofType:@""];
40 | AVAsset *asset = [AVAsset assetWithURL:[NSURL fileURLWithPath:videoPath]];
41 | NSError *error = nil;
42 | _reader = [[AVAssetReader alloc] initWithAsset:asset error:&error];
43 |
44 |
45 | NSArray *videoTracks = [asset tracksWithMediaType:AVMediaTypeVideo];
46 | if (!videoTracks.count) {
47 | error = [NSError errorWithDomain:@"AVFoundation error" code:-1 userInfo:@{ NSLocalizedDescriptionKey : @"Can't read video track" }];
48 | return;
49 | }
50 |
51 | AVAssetTrack *videoTrack = [videoTracks objectAtIndex:0];
52 | NSDictionary *settings = @{(NSString *)kCVPixelBufferPixelFormatTypeKey : [NSNumber numberWithInt:kCVPixelFormatType_32BGRA] };
53 | AVAssetReaderTrackOutput *trackOutput = [[AVAssetReaderTrackOutput alloc] initWithTrack:videoTrack outputSettings:settings];
54 | if ([_reader canAddOutput:trackOutput]) {
55 | [_reader addOutput:trackOutput];
56 | }
57 |
58 |
59 | [_reader startReading];
60 |
61 | CMSampleBufferRef buffer = NULL;
62 | BOOL continueReading = YES;
63 | while (continueReading) {
64 | AVAssetReaderStatus status = [_reader status];
65 | switch (status) {
66 | case AVAssetReaderStatusUnknown: {
67 | } break;
68 | case AVAssetReaderStatusReading: {
69 | buffer = [trackOutput copyNextSampleBuffer];
70 |
71 | if (!buffer) {
72 | break;
73 | }
74 |
75 | if (_delegateMethods.didGetNextVideoSample) {
76 | [self.delegate bufferReader:self didGetNextVideoSample:buffer];
77 | }
78 | } break;
79 | case AVAssetReaderStatusCompleted: {
80 | if (_delegateMethods.didFinishReadingSample) {
81 | [self.delegate bufferReader:self didFinishReadingAsset:asset];
82 | [_reader cancelReading];
83 | }
84 | continueReading = NO;
85 | } break;
86 | case AVAssetReaderStatusFailed: {
87 | if (_delegateMethods.didFinishReadingSample) {
88 | [self.delegate bufferReader:self didFinishReadingAsset:asset];
89 | }
90 | [_reader cancelReading];
91 | continueReading = NO;
92 | } break;
93 | case AVAssetReaderStatusCancelled: {
94 | continueReading = NO;
95 | } break;
96 | }
97 | if (buffer) {
98 | CMSampleBufferInvalidate(buffer);
99 | CFRelease(buffer);
100 | buffer = NULL;
101 | }
102 | }
103 | }
104 |
105 | - (void)cancelReading {
106 | [_reader cancelReading];
107 | // _reader = nil;
108 | if ([_delegate respondsToSelector:@selector(bufferReaderDidCancelled)]) {
109 | dispatch_async(dispatch_get_main_queue(), ^{
110 | [_delegate bufferReaderDidCancelled];
111 | });
112 | }
113 | }
114 |
115 | NS_INLINE NSDictionary *CVPixelFormatOutputSettings() {
116 | return @{ (NSString *)kCVPixelBufferPixelFormatTypeKey : [NSNumber numberWithInt:kCVPixelFormatType_32BGRA] };
117 | }
118 |
119 | @end
120 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemoTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemoTests/MGFaceppTest.m:
--------------------------------------------------------------------------------
1 | //
2 | // MGFaceppTest.m
3 | // FaceppDemo
4 | //
5 | // Created by Megvii on 2017/8/30.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "MGFacepp.h"
11 |
12 | @interface MGFaceppTest : XCTestCase
13 | @property (nonatomic, strong) MGFacepp *facepp;
14 | @property (nonatomic, strong) MGAlgorithmInfo *faceppInfo;
15 | @end
16 |
17 | @implementation MGFaceppTest
18 |
19 | - (void)setUp {
20 | [super setUp];
21 |
22 | NSString *modelPath = [[NSBundle mainBundle] pathForResource:KMGFACEMODELNAME ofType:@""];
23 | NSData *modelData = [NSData dataWithContentsOfFile:modelPath];
24 |
25 | _facepp = [[MGFacepp alloc] initWithModel:modelData
26 | faceppSetting:^(MGFaceppConfig *config) {
27 | config.orientation = 0;
28 | config.detectionMode = MGFppDetectionModeNormal;
29 | }];
30 | XCTAssertNotNil(_facepp);
31 | }
32 |
33 | - (void)tearDown {
34 | // Put teardown code here. This method is called after the invocation of each test method in the class.
35 | [super tearDown];
36 | }
37 |
38 | - (void)testExample {
39 | // This is an example of a functional test case.
40 | // Use XCTAssert and related functions to verify your tests produce the correct results.
41 | }
42 |
43 |
44 | - (void)testUpdateFaceSetting {
45 | BOOL result = [_facepp updateFaceppSetting:^(MGFaceppConfig *config) {
46 | config.minFaceSize = 100;
47 | config.interval = 40;
48 | config.detectionMode = MGFppDetectionModeNormal;
49 | MGDetectROI roi = {0, 0, 0, 0};
50 | config.detectROI = roi;
51 | config.pixelFormatType = PixelFormatTypeRGBA;
52 | }];
53 | XCTAssertTrue(result);
54 | }
55 |
56 | - (void)testGetLandmark {
57 | MGImageData *imageData = [[MGImageData alloc] initWithImage:[UIImage imageNamed:@"test_one_face.png"]];
58 | MGFaceInfo *faceInfo = [self getFaceInfo:imageData];
59 | BOOL result = [_facepp GetGetLandmark:faceInfo isSmooth:NO pointsNumber:81];
60 | XCTAssertTrue(result);
61 | [imageData releaseImageData];
62 | }
63 |
64 | - (void)testGetAgeGenderStatus{
65 | if ([_faceppInfo.SDKAbility containsObject:MG_ABILITY_KEY_AGE_GENDER]) {
66 | MGImageData *imageData = [[MGImageData alloc] initWithImage:[UIImage imageNamed:@"test_one_face.png"]];
67 | MGFaceInfo *faceInfo = [self getFaceInfo:imageData];
68 | [imageData releaseImageData];
69 | BOOL result = [_facepp GetAttributeAgeGenderStatus:faceInfo];
70 | XCTAssertTrue(result);
71 | XCTAssert(faceInfo.age > 0);
72 | XCTAssert(faceInfo.gender == MGFemale);
73 |
74 | MGImageData *imageData1 = [[MGImageData alloc] initWithImage:[UIImage imageNamed:@"test_male.jpg"]];
75 | MGFaceInfo *maleFaceInfo = [self getFaceInfo:imageData1];
76 | [imageData1 releaseImageData];
77 | BOOL maleResult = [_facepp GetAttributeAgeGenderStatus:maleFaceInfo];
78 | XCTAssertTrue(maleResult);
79 | XCTAssert(maleFaceInfo.age > 0);
80 | XCTAssert(maleFaceInfo.gender == MGMale);
81 | }
82 | }
83 |
84 | - (void)testCompareFaces {
85 | if ([_faceppInfo.SDKAbility containsObject:MG_ABILITY_KEY_EXTRACT_FEATURE]) {
86 | MGImageData *imageData = [[MGImageData alloc] initWithImage:[UIImage imageNamed:@"test_one_face.png"]];
87 | MGFaceInfo *faceInfo = [self getFaceInfo:imageData];
88 | BOOL result0 = [_facepp GetFeatureData:faceInfo];
89 | XCTAssertTrue(result0);
90 | [imageData releaseImageData];
91 |
92 | // 同一个人
93 | MGImageData *imageData1 = [[MGImageData alloc] initWithImage:[UIImage imageNamed:@"test_one_face.png"]];
94 | MGFaceInfo *faceInfo1 = [self getFaceInfo:imageData1];
95 | BOOL result1 = [_facepp GetFeatureData:faceInfo1];
96 | XCTAssertTrue(result1);
97 | [imageData1 releaseImageData];
98 | float score1 = [_facepp faceCompareWithFaceInfo:faceInfo faceInf2:faceInfo1];
99 | XCTAssert(score1 > 0.9);
100 |
101 | // 不同人
102 | MGImageData *imageData2 = [[MGImageData alloc] initWithImage:[UIImage imageNamed:@"test_male.jpg"]];
103 | MGFaceInfo *faceInfo2 = [self getFaceInfo:imageData2];
104 | BOOL result2 = [_facepp GetFeatureData:faceInfo2];
105 | XCTAssertTrue(result2);
106 | [imageData2 releaseImageData];
107 | float score2 = [_facepp faceCompareWithFeatureData:faceInfo.featureData featureData2:faceInfo2.featureData];
108 | XCTAssert(score2 < 0.5);
109 | }
110 | }
111 |
112 | - (void)testGetVsersion {
113 | NSString *version = [MGFacepp getVersion];
114 | BOOL result = [version containsString:@"MegviiFacepp 0.5.0"];
115 | XCTAssertTrue(result);
116 | }
117 |
118 |
119 | - (MGFaceInfo *)getFaceInfo:(MGImageData *)imageData {
120 | [_facepp beginDetectionFrame];
121 | NSArray *faces = [_facepp detectWithImageData:imageData];
122 | [_facepp endDetectionFrame];
123 | XCTAssert(faces.count == 1);
124 | MGFaceInfo *faceInfo = faces[0];
125 | return faceInfo;
126 | }
127 |
128 | - (void)testPerformanceExample {
129 | // This is an example of a performance test case.
130 | [self measureBlock:^{
131 | // Put the code you want to measure the time of here.
132 | }];
133 | }
134 |
135 | @end
136 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemoTests/MGPictureTest.m:
--------------------------------------------------------------------------------
1 | //
2 | // MGPictureTest.m
3 | // FaceppDemo
4 | //
5 | // Created by Megvii on 2017/7/19.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "MGFacepp.h"
11 | #import "MGFaceInfo.h"
12 | #import "MGHeader.h"
13 |
14 | @interface MGPictureTest : XCTestCase
15 | @property (nonatomic, strong) MGFacepp *facepp;
16 | @end
17 |
18 | @implementation MGPictureTest
19 |
20 | - (void)setUp {
21 | [super setUp];
22 |
23 |
24 | NSString *modelPath = [[NSBundle mainBundle] pathForResource:KMGFACEMODELNAME ofType:@""];
25 | NSData *modelData = [NSData dataWithContentsOfFile:modelPath];
26 |
27 | _facepp = [[MGFacepp alloc] initWithModel:modelData
28 | faceppSetting:^(MGFaceppConfig *config) {
29 | config.orientation = 0;
30 | }];
31 | }
32 |
33 | - (void)tearDown {
34 | // Put teardown code here. This method is called after the invocation of each test method in the class.
35 | [super tearDown];
36 | }
37 |
38 | - (void)testExample {
39 | [self detectImage:@"background.png"];
40 | [self detectImage:@"81_points_position.jpg"];
41 | }
42 |
43 | - (void)detectImage:(NSString *)name {
44 | UIImage *image = [UIImage imageNamed:name];
45 | MGImageData *imageData = [[MGImageData alloc] initWithImage:image];
46 | [_facepp beginDetectionFrame];
47 |
48 | NSDate *t1 = [NSDate date];
49 | NSArray *faceArray = [_facepp detectWithImageData:imageData];
50 | NSDate *t2 = [NSDate date];
51 | NSTimeInterval interval = [t2 timeIntervalSinceDate:t1];
52 | NSLog(@"detect time = %f",interval * 1000);
53 |
54 | [_facepp endDetectionFrame];
55 | [imageData releaseImageData];
56 |
57 | if (faceArray.count > 0) {
58 | MGLog(@"人脸数量 %@ :%lu", name, (unsigned long)faceArray.count);
59 | MGFaceInfo *faceInfo = faceArray[0];
60 | [_facepp GetGetLandmark:faceInfo isSmooth:NO pointsNumber:81];
61 | } else {
62 | MGLog(@"%@ 未检测出人脸",name);
63 | XCTFail(@"未检测出人脸");
64 | }
65 | }
66 |
67 | - (void)testCompare {
68 | UIImage *image1 = [UIImage imageNamed:@"background.png"];
69 | UIImage *image2 = [UIImage imageNamed:@"81_points_position.jpg"];
70 | NSData *data1;
71 | NSData *data2;
72 |
73 | // image1
74 | MGImageData *imageData = [[MGImageData alloc] initWithImage:image1];
75 | [_facepp beginDetectionFrame];
76 |
77 | NSArray *face = [_facepp detectWithImageData:imageData];
78 | if (face.count > 0) {
79 | MGFaceInfo *faceInfo = face[0];
80 | BOOL success = [_facepp GetFeatureData:faceInfo];
81 | if (success) {
82 | data1 = faceInfo.featureData;
83 | } else {
84 | XCTFail(@"获取人脸特征失败");
85 | }
86 | } else {
87 | XCTFail(@"未检测出人脸");
88 | }
89 | [_facepp endDetectionFrame];
90 |
91 | // image2
92 | MGImageData *imageData2 = [[MGImageData alloc] initWithImage:image2];
93 | [_facepp beginDetectionFrame];
94 |
95 | NSArray *face2 = [_facepp detectWithImageData:imageData2];
96 | if (face.count > 0) {
97 | MGFaceInfo *faceInfo2 = face2[0];
98 | BOOL success = [_facepp GetFeatureData:faceInfo2];
99 | if (success) {
100 | data2 = faceInfo2.featureData;
101 | } else {
102 | XCTFail(@"获取人脸特征失败");
103 | }
104 | } else {
105 | NSLog(@"未检测到人脸");
106 | }
107 | [_facepp endDetectionFrame];
108 |
109 | CGFloat like = [_facepp faceCompareWithFeatureData:data1 featureData2:data2];
110 | NSLog(@"相似度:%.2f",like);
111 | }
112 |
113 | - (void)testPerformanceExample {
114 | // This is an example of a performance test case.
115 | [self measureBlock:^{
116 | // Put the code you want to measure the time of here.
117 | }];
118 | }
119 |
120 | @end
121 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemoTests/MGVideoTestVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGVideoTestVC.h
3 | // FaceppDemo
4 | //
5 | // Created by Megvii on 2017/7/20.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface MGVideoTestVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemoTests/MGVideoTestVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // MGVideoTestVC.m
3 | // FaceppDemo
4 | //
5 | // Created by Megvii on 2017/7/20.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import "MGVideoTestVC.h"
10 | #import "VideoBufferReader.h"
11 | #import "MGFacepp.h"
12 | #import "MGFaceModelArray.h"
13 |
14 | @interface MGVideoTestVC ()
15 | @property (nonatomic, strong) VideoBufferReader *videoReader;
16 | @property (nonatomic, strong) dispatch_queue_t detectQueue;
17 | @property (nonatomic, strong) dispatch_queue_t videoQueue;
18 | @property (nonatomic, strong) MGFacepp *facepp;
19 | @property (nonatomic, strong) NSDate *t1, *t2;
20 | @property (nonatomic, assign) int min_face_size;
21 | @end
22 |
23 | @implementation MGVideoTestVC
24 |
25 | - (void)viewDidLoad {
26 | [super viewDidLoad];
27 |
28 | _videoReader = [[VideoBufferReader alloc] initWithDelegate:self];
29 | _detectQueue = dispatch_queue_create("com.megvii.detect", DISPATCH_QUEUE_SERIAL);
30 | _videoQueue = dispatch_queue_create("com.megvii.video", DISPATCH_QUEUE_SERIAL);
31 |
32 | _min_face_size =170;
33 | [self start];
34 | }
35 |
36 | - (void)start {
37 | NSString *modelPath = [[NSBundle mainBundle] pathForResource:KMGFACEMODELNAME ofType:@""];
38 | NSData *modelData = [NSData dataWithContentsOfFile:modelPath];
39 |
40 | int width = 480;
41 | int height= 640;
42 |
43 | MGDetectROI detectROI = MGDetectROIMake(0, 0, 0, 0);
44 | CGFloat angeleW = width * 0.8;
45 | CGFloat angeleL = (width - angeleW) / 2;
46 | CGFloat angeleT = (height - angeleW) / 2;
47 | detectROI = MGDetectROIMake(angeleT, angeleL, angeleW+angeleT, angeleW+angeleL);
48 |
49 | _facepp = [[MGFacepp alloc] initWithModel:modelData
50 | faceppSetting:^(MGFaceppConfig *config) {
51 | config.orientation = 0;
52 | config.minFaceSize = 40;
53 | config.detectionMode = MGFppDetectionModeTrackingFast;
54 | }];
55 | [_facepp updateFaceppSetting:^(MGFaceppConfig *config) {
56 | NSLog(@"track min_face_size = %d",_min_face_size);
57 | config.minFaceSize = _min_face_size;
58 | }];
59 | dispatch_async(_videoQueue, ^{
60 | // [_videoReader startReading:@"1.m4v"];
61 | });
62 | }
63 |
64 | - (void)didReceiveMemoryWarning {
65 | [super didReceiveMemoryWarning];
66 | // Dispose of any resources that can be recreated.
67 | }
68 |
69 | /*
70 | #pragma mark - Navigation
71 |
72 | // In a storyboard-based application, you will often want to do a little preparation before navigation
73 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
74 | // Get the new view controller using [segue destinationViewController].
75 | // Pass the selected object to the new view controller.
76 | }
77 | */
78 |
79 | - (void)track:(CMSampleBufferRef)sampleBuffer {
80 | if (MGMarkWorking == _facepp.status) {
81 | return;
82 | }
83 |
84 | CMSampleBufferRef detectSampleBufferRef = NULL;
85 | CMSampleBufferCreateCopy(kCFAllocatorDefault, sampleBuffer, &detectSampleBufferRef);
86 |
87 | /* 进入检测人脸专用线程 */
88 | dispatch_sync(_detectQueue, ^{
89 | @autoreleasepool {
90 | MGImageData *imageData = [[MGImageData alloc] initWithSampleBuffer:detectSampleBufferRef];
91 |
92 | [_facepp beginDetectionFrame];
93 |
94 | if (!_t1) {
95 | _t1 = [NSDate date];
96 | }
97 |
98 | NSArray *tempArray = [_facepp detectWithImageData:imageData];
99 |
100 | if (tempArray.count > 0) {
101 | _t2 = [NSDate date];
102 | double timeUsed = [_t2 timeIntervalSinceDate:_t1] * 1000;
103 | NSLog(@"track time : %f",timeUsed);
104 | _t1 = nil;
105 |
106 | [_videoReader cancelReading];
107 | }
108 |
109 |
110 | // MGFaceModelArray *faceModelArray = [[MGFaceModelArray alloc] init];
111 | // faceModelArray.faceArray = [NSMutableArray arrayWithArray:tempArray];
112 | // faceModelArray.getFaceInfo = NO;
113 | //
114 | // for (int i = 0; i < faceModelArray.count; i ++) {
115 | // MGFaceInfo *faceInfo = faceModelArray.faceArray[i];
116 | // [_facepp GetGetLandmark:faceInfo isSmooth:YES pointsNumber:81];
117 | // }
118 |
119 |
120 | [_facepp endDetectionFrame];
121 |
122 | [imageData releaseImageData];
123 | }
124 | });
125 |
126 | if (detectSampleBufferRef) {
127 | CFRelease(detectSampleBufferRef);
128 | }
129 | }
130 |
131 |
132 |
133 | #pragma mark - VideoBufferReaderDelegate
134 |
135 | - (void)bufferReader:(VideoBufferReader *)reader didFinishReadingAsset:(AVAsset *)asset{
136 | NSLog(@"didFinishReadingAsset %@", asset);
137 | _t2 = nil;
138 | _t1 = nil;
139 | NSLog(@"track time : 未检出");
140 | [self reTest];
141 | }
142 |
143 | - (void)bufferReader:(VideoBufferReader *)reader didGetNextVideoSample:(CMSampleBufferRef)bufferRef {
144 | @synchronized(self) {
145 | [self track:bufferRef];
146 | }
147 | }
148 |
149 | - (void)bufferReader:(VideoBufferReader *)reader didGetErrorRedingSample:(NSError *)error{
150 | NSLog(@"decoding error %@", error);
151 | }
152 |
153 | - (void)bufferReaderDidCancelled {
154 | [self reTest];
155 | }
156 |
157 | - (void)reTest {
158 | if (_min_face_size > 40) {
159 | _min_face_size --;
160 | [self start];
161 | }
162 | }
163 |
164 | @end
165 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemoTests/resources/test_male.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/FaceppDemoTests/resources/test_male.jpg
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemoTests/resources/test_one_face.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/FaceppDemoTests/resources/test_one_face.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/FaceppDemoTests/videoTest.m:
--------------------------------------------------------------------------------
1 | //
2 | // videoTest.m
3 | // FaceppDemo
4 | //
5 | // Created by Megvii on 2017/7/20.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "VideoBufferReader.h"
11 | #import "MGFacepp.h"
12 | #import "MGFaceModelArray.h"
13 |
14 | @interface videoTest : XCTestCase
15 |
16 | @property (nonatomic, strong) VideoBufferReader *videoReader;
17 | @property (nonatomic, strong) dispatch_queue_t detectQueue;
18 | @property (nonatomic, strong) MGFacepp *facepp;
19 | @property (nonatomic, strong) NSDate *t1, *t2;
20 |
21 | @end
22 |
23 | @implementation videoTest
24 |
25 | - (void)setUp {
26 | [super setUp];
27 |
28 | _videoReader = [[VideoBufferReader alloc] initWithDelegate:self];
29 | _detectQueue = dispatch_queue_create("com.megvii.detect", DISPATCH_QUEUE_SERIAL);
30 | int width = 480;
31 | int height= 640;
32 |
33 | NSString *modelPath = [[NSBundle mainBundle] pathForResource:KMGFACEMODELNAME ofType:@""];
34 | NSData *modelData = [NSData dataWithContentsOfFile:modelPath];
35 |
36 | MGDetectROI detectROI = MGDetectROIMake(0, 0, 0, 0);
37 | CGFloat angeleW = width * 0.8;
38 | CGFloat angeleL = (width - angeleW) / 2;
39 | CGFloat angeleT = (height - angeleW) / 2;
40 | detectROI = MGDetectROIMake(angeleT, angeleL, angeleW+angeleT, angeleW+angeleL);
41 |
42 | _facepp = [[MGFacepp alloc] initWithModel:modelData
43 | faceppSetting:^(MGFaceppConfig *config) {
44 | config.orientation = 0;
45 | config.detectROI = detectROI;
46 | config.minFaceSize = 150;
47 | config.detectionMode = MGFppDetectionModeTrackingFast;
48 | }];
49 | }
50 |
51 | - (void)start {
52 | dispatch_async(dispatch_get_global_queue(0, 0), ^{
53 | [_videoReader startReading:@"1.m4v"];
54 | });
55 | }
56 |
57 | - (void)tearDown {
58 | // Put teardown code here. This method is called after the invocation of each test method in the class.
59 | [super tearDown];
60 | }
61 |
62 | - (void)testExample {
63 | [self start];
64 | }
65 |
66 | - (void)testPerformanceExample {
67 | // This is an example of a performance test case.
68 | [self measureBlock:^{
69 | // Put the code you want to measure the time of here.
70 | }];
71 | }
72 |
73 | - (void)track:(CMSampleBufferRef)sampleBuffer {
74 | if (MGMarkWorking == _facepp.status) {
75 | NSLog(@"1");
76 | return;
77 | }
78 |
79 | CMSampleBufferRef detectSampleBufferRef = NULL;
80 | CMSampleBufferCreateCopy(kCFAllocatorDefault, sampleBuffer, &detectSampleBufferRef);
81 |
82 | /* 进入检测人脸专用线程 */
83 | dispatch_sync(_detectQueue, ^{
84 | @autoreleasepool {
85 | MGImageData *imageData = [[MGImageData alloc] initWithSampleBuffer:detectSampleBufferRef];
86 |
87 | [_facepp beginDetectionFrame];
88 |
89 | if (!_t1) {
90 | _t1 = [NSDate date];
91 | }
92 |
93 | NSArray *tempArray = [_facepp detectWithImageData:imageData];
94 |
95 | if (tempArray.count > 0) {
96 | _t2 = [NSDate date];
97 | double timeUsed = [_t2 timeIntervalSinceDate:_t1] * 1000;
98 | NSLog(@"track time : %f",timeUsed);
99 | _t1 = nil;
100 | }
101 |
102 |
103 | MGFaceModelArray *faceModelArray = [[MGFaceModelArray alloc] init];
104 | faceModelArray.faceArray = [NSMutableArray arrayWithArray:tempArray];
105 | faceModelArray.getFaceInfo = NO;
106 |
107 | for (int i = 0; i < faceModelArray.count; i ++) {
108 | MGFaceInfo *faceInfo = faceModelArray.faceArray[i];
109 | [_facepp GetGetLandmark:faceInfo isSmooth:YES pointsNumber:81];
110 | }
111 |
112 |
113 | [_facepp endDetectionFrame];
114 |
115 | [imageData releaseImageData];
116 | }
117 | });
118 |
119 | if (detectSampleBufferRef) {
120 | // CFRelease(detectSampleBufferRef);
121 | }
122 | }
123 |
124 |
125 |
126 | #pragma mark - VideoBufferReaderDelegate
127 |
128 | - (void)bufferReader:(VideoBufferReader *)reader didFinishReadingAsset:(AVAsset *)asset{
129 | NSLog(@"didFinishReadingAsset %@", asset);
130 | }
131 |
132 | - (void)bufferReader:(VideoBufferReader *)reader didGetNextVideoSample:(CMSampleBufferRef)bufferRef {
133 | @synchronized(self) {
134 | [self track:bufferRef];
135 | }
136 | }
137 |
138 | - (void)bufferReader:(VideoBufferReader *)reader didGetErrorRedingSample:(NSError *)error{
139 | NSLog(@"decoding error %@", error);
140 | }
141 |
142 | @end
143 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectPicture/MGDetectPictureVC.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGDetectPictureVC.h
3 | // FaceppDemo
4 | //
5 | // Created by 张英堂 on 2016/11/8.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface MGDetectPictureVC : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectPicture/MGDetectPictureVC.m:
--------------------------------------------------------------------------------
1 | //
2 | // MGDetectPictureVC.m
3 | // FaceppDemo
4 | //
5 | // Created by 张英堂 on 2016/11/8.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import "MGDetectPictureVC.h"
10 | #import "MGFacepp.h"
11 | #import "MGFaceInfo.h"
12 |
13 | @interface MGDetectPictureVC ()
14 | @property (weak, nonatomic) IBOutlet UIImageView *detectImage;
15 | @property (weak, nonatomic) IBOutlet UILabel *messageView;
16 |
17 | @property (nonatomic, strong) MGFacepp *markManager;
18 |
19 | @end
20 |
21 | @implementation MGDetectPictureVC
22 |
23 | - (void)viewDidLoad {
24 | [super viewDidLoad];
25 | // Do any additional setup after loading the view.
26 |
27 | NSString *modelPath = [[NSBundle mainBundle] pathForResource:KMGFACEMODELNAME ofType:@""];
28 | NSData *modelData = [NSData dataWithContentsOfFile:modelPath];
29 |
30 | MGFacepp *markManager = [[MGFacepp alloc] initWithModel:modelData
31 | faceppSetting:^(MGFaceppConfig *config) {
32 | config.orientation = 0;
33 | }];
34 | self.markManager = markManager;
35 | }
36 |
37 | - (void)didReceiveMemoryWarning {
38 | [super didReceiveMemoryWarning];
39 | // Dispose of any resources that can be recreated.
40 | }
41 |
42 | - (IBAction)startDetect:(id)sender {
43 | NSString *imageName = @"background.png";
44 | UIImage *image = [UIImage imageNamed:imageName];
45 | self.detectImage.image = image;
46 |
47 | MGImageData *imageData = [[MGImageData alloc] initWithImage:image];
48 |
49 | [self.markManager beginDetectionFrame];
50 |
51 | NSArray *faceArray = [self.markManager detectWithImageData:imageData];
52 |
53 | if (faceArray.count > 0) {
54 | MGFaceInfo *faceInfo = faceArray[0];
55 | [self.markManager GetGetLandmark:faceInfo isSmooth:YES pointsNumber:81];
56 | [self.markManager GetAttribute3D:faceInfo];
57 |
58 | NSLog(@"%lu - %@", (unsigned long)faceInfo.points.count ,faceInfo.points);
59 |
60 | }else{
61 | NSLog(@"%@ no face", imageName);
62 | }
63 | [self.markManager endDetectionFrame];
64 |
65 | NSString *tempString = @"";
66 | if (faceArray.count > 0) {
67 | MGFaceInfo *info1 = faceArray[0];
68 |
69 | tempString = [NSString stringWithFormat:@"age:%.2f \npitch:%.2f \nyaw:%.2f \nroll:%.2f", info1.age, info1.pitch, info1.yaw, info1.roll];
70 |
71 | NSLog(@"%@", NSStringFromCGRect(info1.rect));
72 | }
73 |
74 | NSString *faceLog = [NSString stringWithFormat:@"%@:%zi\n%@",NSLocalizedString(@"debug_message7", nil) ,faceArray.count, tempString];
75 | self.messageView.text = faceLog;
76 |
77 | NSLog(@"%@", faceArray);
78 | }
79 |
80 |
81 | @end
82 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Cells/BaseCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // BaseCell.h
3 | // KoalaPhoto
4 | //
5 | // Created by 张英堂 on 14/12/22.
6 | // Copyright (c) 2014年 visionhacker. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @class BaseModel;
12 |
13 | @interface BaseCell : UITableViewCell
14 |
15 |
16 | @property (nonatomic, strong) BaseModel *dataModel;
17 |
18 | + (CGFloat)cellHigth;
19 |
20 | @end
21 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Cells/BaseCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // BaseCell.m
3 | // KoalaPhoto
4 | //
5 | // Created by 张英堂 on 14/12/22.
6 | // Copyright (c) 2014年 visionhacker. All rights reserved.
7 | //
8 |
9 | #import "BaseCell.h"
10 |
11 | @implementation BaseCell
12 |
13 |
14 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
15 | [super setSelected:selected animated:animated];
16 |
17 | // Configure the view for the selected state
18 | }
19 |
20 |
21 |
22 | + (CGFloat)cellHigth{
23 | return 44.0f;
24 | }
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Cells/BaseCell.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Cells/BaseCollectionCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // BaseCollectionCell.h
3 | // MGSDKV2Test
4 | //
5 | // Created by 张英堂 on 2016/10/17.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface BaseCollectionCell : UICollectionViewCell
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Cells/BaseCollectionCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // BaseCollectionCell.m
3 | // MGSDKV2Test
4 | //
5 | // Created by 张英堂 on 2016/10/17.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import "BaseCollectionCell.h"
10 |
11 | @implementation BaseCollectionCell
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Cells/MCSetCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // MCSetCell.h
3 | // MGSDKV2Test
4 | //
5 | // Created by 张英堂 on 2016/10/17.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "BaseCollectionCell.h"
11 |
12 | @class MCSetModel;
13 |
14 | @interface MCSetCell : BaseCollectionCell
15 |
16 | @property (nonatomic, strong) MCSetModel *dataModel;
17 |
18 |
19 | - (void)refurbish;
20 |
21 |
22 | @end
23 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Cells/MCSetCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // MCSetCell.m
3 | // MGSDKV2Test
4 | //
5 | // Created by 张英堂 on 2016/10/17.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import "MCSetCell.h"
10 | #import "MCSetModel.h"
11 | #import "MGHeader.h"
12 |
13 | @interface MCSetCell ()
14 | {
15 | CAShapeLayer *_lineShape;
16 | }
17 | @property (weak, nonatomic) IBOutlet UIImageView *imageView;
18 | @property (weak, nonatomic) IBOutlet UILabel *titleView;
19 | @property (weak, nonatomic) IBOutlet UILabel *textView;
20 |
21 | @end
22 |
23 |
24 | @implementation MCSetCell
25 |
26 | - (void)awakeFromNib {
27 | [super awakeFromNib];
28 | // Initialization code
29 | self.textView.adjustsFontSizeToFitWidth = YES;
30 |
31 | }
32 |
33 | -(void)setDataModel:(MCSetModel *)dataModel{
34 | if (_dataModel != dataModel) {
35 | _dataModel = dataModel;
36 | }
37 |
38 | [self freshenView:_dataModel];
39 | }
40 |
41 | - (void)refurbish{
42 |
43 | [self freshenView:self.dataModel];
44 | }
45 |
46 | - (void)freshenView:(MCSetModel *)dataModel{
47 | if (dataModel != nil) {
48 | self.titleView.text = dataModel.title;
49 |
50 | switch (dataModel.type) {
51 | case LogoTypeImage:
52 | {
53 | if (dataModel.status == SelectStatusBool) {
54 | [self.imageView setHidden:NO];
55 | [self.textView setHidden:YES];
56 |
57 | NSString *tempImageName = [NSString stringWithFormat:@"%@-%zi",dataModel.imageName, dataModel.boolValue];
58 | UIImage *tempImage = [UIImage imageNamed:tempImageName];
59 | [self.imageView setImage:tempImage];
60 | }else if(dataModel.status == SelectStatusSting){
61 | [self.imageView setHidden:YES];
62 | [self.textView setHidden:NO];
63 |
64 | self.textView.text = dataModel.stringValue;
65 | }
66 | }
67 | break;
68 | case LogoTypeText:
69 | {
70 | [self.imageView setHidden:YES];
71 | [self.textView setHidden:NO];
72 |
73 | NSString *showString;
74 | if (dataModel.status == SelectStatusInt) {
75 | showString = [NSString stringWithFormat:@"%zi", dataModel.intValue];
76 | }else if (dataModel.status == SelectStatusFloat){
77 | showString = [NSString stringWithFormat:@"%.2f", dataModel.floatValue];
78 | }else if(dataModel.status == SelectStatusSting){
79 | showString = dataModel.stringValue;
80 | }
81 | self.textView.text = showString;
82 | }
83 | break;
84 | case LogoTypeSelect:
85 | {
86 | if (dataModel.status == SelectStatusSize) {
87 | [self.imageView setHidden:NO];
88 | [self.textView setHidden:YES];
89 |
90 | NSString *tempImageName = [NSString stringWithFormat:@"%.0f_%.0f",dataModel.sizeValue.height, dataModel.sizeValue.width];
91 | UIImage *tempImage = [UIImage imageNamed:tempImageName];
92 | [self.imageView setImage:tempImage];
93 |
94 | }else if(dataModel.status == SelectStatusSting){
95 | [self.imageView setHidden:YES];
96 | [self.textView setHidden:NO];
97 |
98 | self.textView.text = dataModel.stringValue;
99 | }
100 |
101 | }
102 | break;
103 | default:
104 | {
105 | [self.imageView setHidden:YES];
106 | [self.textView setHidden:YES];
107 | }
108 | break;
109 | }
110 |
111 | if (dataModel.type != LogoTypeSpace) {
112 | [self drawLine];
113 | }
114 | }
115 | }
116 |
117 | - (void)drawLine{
118 | if (_lineShape == nil) {
119 | CGMutablePathRef linepath = nil;
120 |
121 | linepath = CGPathCreateMutable();
122 | _lineShape = [CAShapeLayer layer];
123 |
124 | _lineShape.lineWidth = 2.0f;
125 | _lineShape.lineCap = kCALineCapRound;
126 | _lineShape.strokeColor = MGColorWithRGB(224, 224, 224, 1).CGColor;
127 |
128 | CGPathMoveToPoint(linepath, NULL, CGRectGetMinX(self.bounds), CGRectGetMaxY(self.bounds));
129 | CGPathAddLineToPoint(linepath, NULL, CGRectGetMaxX(self.bounds), CGRectGetMaxY(self.bounds));
130 |
131 | _lineShape.path = linepath;
132 | CGPathRelease(linepath);
133 | }
134 |
135 | [self.layer addSublayer:_lineShape];
136 | }
137 |
138 | - (void)clearLine{
139 | if (_lineShape != nil) {
140 | [_lineShape removeFromSuperlayer];
141 | }
142 | }
143 |
144 | @end
145 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Cells/MGFaceCompareCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGFaceCompareCell.h
3 | // FaceppDemo
4 | //
5 | // Created by Li Bo on 2017/5/19.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "MGFaceCompareModel.h"
11 |
12 | @protocol MGFaceCompareCellDelegate
13 |
14 | - (void)nameDidEdit:(MGFaceCompareModel *)model;
15 |
16 | - (void)modelDidSelected:(MGFaceCompareModel *)model;
17 |
18 | @end
19 |
20 | @interface MGFaceCompareCell : UITableViewCell
21 |
22 | @property (nonatomic, weak) id delegate;
23 |
24 | @property (nonatomic, strong) MGFaceCompareModel *model;
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Cells/MGFaceCompareCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // MGFaceCompareCell.m
3 | // FaceppDemo
4 | //
5 | // Created by Li Bo on 2017/5/19.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import "MGFaceCompareCell.h"
10 |
11 | @interface MGFaceCompareCell ()
12 | @property (weak, nonatomic) IBOutlet UIImageView *icon;
13 | @property (weak, nonatomic) IBOutlet UIButton *selectBtn;
14 | @property (weak, nonatomic) IBOutlet UILabel *nameLabel;
15 |
16 | @property (nonatomic, strong) UITapGestureRecognizer *nameTap;
17 | @end
18 |
19 | @implementation MGFaceCompareCell
20 |
21 | - (void)awakeFromNib {
22 | [super awakeFromNib];
23 | self.selectionStyle = UITableViewCellSelectionStyleNone;
24 | _icon.contentMode = UIViewContentModeScaleAspectFit;
25 | [self addNameAction];
26 | }
27 |
28 | - (void)setModel:(MGFaceCompareModel *)model{
29 | _selectBtn.selected = model.selected;
30 | if (_selectBtn.selected) {
31 | [_selectBtn setBackgroundImage:[UIImage imageNamed:@"selected"] forState:UIControlStateNormal];
32 | } else {
33 | [_selectBtn setBackgroundImage:[UIImage imageNamed:@"unSelected"] forState:UIControlStateNormal];
34 | }
35 | _icon.image = model.image;
36 | _nameLabel.text = model.name;
37 | _model = model;
38 | }
39 |
40 | - (void)nameAction{
41 | if ([_delegate respondsToSelector:@selector(nameDidEdit:)]) {
42 | [_delegate nameDidEdit:_model];
43 | }
44 | }
45 |
46 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
47 | [super setSelected:selected animated:animated];
48 |
49 | // Configure the view for the selected state
50 | }
51 |
52 |
53 | - (IBAction)selectBtnAction:(UIButton *)sender {
54 | sender.selected = !sender.selected;
55 | _model.selected = sender.selected;
56 | if (sender.selected) {
57 | [sender setBackgroundImage:[UIImage imageNamed:@"selected"] forState:UIControlStateNormal];
58 | } else {
59 | [sender setBackgroundImage:[UIImage imageNamed:@"unSelected"] forState:UIControlStateNormal];
60 | }
61 | if ([_delegate respondsToSelector:@selector(modelDidSelected:)]) {
62 | [_delegate modelDidSelected:_model];
63 | }
64 | }
65 |
66 | - (void)addNameAction{
67 | _nameTap = [[UITapGestureRecognizer alloc] initWithTarget:self
68 | action:@selector(nameAction)];
69 | _nameLabel.userInteractionEnabled = YES;
70 | [_nameLabel addGestureRecognizer:_nameTap];
71 | }
72 |
73 | @end
74 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Cells/TextCell.h:
--------------------------------------------------------------------------------
1 | //
2 | // TextCell.h
3 | // MGSDKV2Test
4 | //
5 | // Created by 张英堂 on 2016/10/21.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "TextModel.h"
11 | #import "BaseCell.h"
12 |
13 | @interface TextCell : BaseCell
14 |
15 | @property (nonatomic, strong) TextModel *model;
16 |
17 |
18 | //- (CGFloat)CellHight;
19 |
20 |
21 |
22 | @end
23 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Cells/TextCell.m:
--------------------------------------------------------------------------------
1 | //
2 | // TextCell.m
3 | // MGSDKV2Test
4 | //
5 | // Created by 张英堂 on 2016/10/21.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import "TextCell.h"
10 |
11 | @interface TextCell ()
12 | @property (weak, nonatomic) IBOutlet UILabel *titleView;
13 | @property (weak, nonatomic) IBOutlet UILabel *textView;
14 |
15 | @end
16 |
17 | @implementation TextCell
18 |
19 | - (void)awakeFromNib {
20 | [super awakeFromNib];
21 | // Initialization code
22 | [self.textView setAdjustsFontSizeToFitWidth:YES];
23 | [self.titleView setAdjustsFontSizeToFitWidth:YES];
24 | }
25 |
26 | - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
27 | [super setSelected:selected animated:animated];
28 |
29 | // Configure the view for the selected state
30 | }
31 |
32 |
33 | -(void)setDataModel:(BaseModel *)dataModel{
34 | [super setDataModel:dataModel];
35 | self.model = (TextModel *)dataModel;
36 | }
37 |
38 | -(void)setModel:(TextModel *)model{
39 | if (_model != model) {
40 | _model = model;
41 | }
42 |
43 | if (_model) {
44 | self.titleView.text = model.title;
45 | self.textView.text = model.text;
46 | }
47 | }
48 |
49 |
50 | @end
51 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Cells/TextCell.xib:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
33 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Models/BaseModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // BaseModel.h
3 | // KoalaPhoto
4 | //
5 | // Created by 张英堂 on 14/12/22.
6 | // Copyright (c) 2014年 visionhacker. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 |
13 | @interface BaseModel : NSObject
14 |
15 |
16 |
17 | @end
18 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Models/BaseModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // BaseModel.m
3 | // KoalaPhoto
4 | //
5 | // Created by 张英堂 on 14/12/22.
6 | // Copyright (c) 2014年 visionhacker. All rights reserved.
7 | //
8 |
9 | #import "BaseModel.h"
10 |
11 | @implementation BaseModel
12 |
13 |
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Models/MCSetModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // MCSetModel.h
3 | // MGSDKV2Test
4 | //
5 | // Created by 张英堂 on 2016/10/17.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import "BaseModel.h"
10 |
11 | typedef NS_ENUM(NSInteger, LogoType) {
12 | LogoTypeImage = 1,
13 | LogoTypeText,
14 | LogoTypeSelect,
15 | LogoTypeSpace
16 | };
17 | typedef NS_ENUM(NSInteger, SelectStatus) {
18 | SelectStatusBool = 1,
19 | SelectStatusInt,
20 | SelectStatusFloat,
21 | SelectStatusSize,
22 | SelectStatusSting
23 | };
24 |
25 | @interface MCSetModel : BaseModel
26 |
27 | @property (nonatomic, copy) NSString *title;
28 | @property (nonatomic, copy) NSString *imageName;
29 |
30 | @property (nonatomic, assign) BOOL boolValue;
31 | @property (nonatomic, assign) NSInteger intValue;
32 | @property (nonatomic, assign) CGFloat floatValue;
33 | @property (nonatomic, assign) CGSize sizeValue;
34 | @property (copy, nonatomic) NSString *stringValue;
35 |
36 | @property (copy, nonatomic) NSString *videoPreset;
37 |
38 | @property (nonatomic, assign) BOOL changeTitle;
39 |
40 | @property (nonatomic, assign) LogoType type;
41 | @property (nonatomic, assign) SelectStatus status;
42 |
43 |
44 | - (void)setOpen;
45 |
46 |
47 | + (instancetype)modelWithTitle:(NSString *)title
48 | type:(LogoType)type
49 | status:(SelectStatus)status;
50 |
51 | @end
52 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Models/MCSetModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // MCSetModel.m
3 | // MGSDKV2Test
4 | //
5 | // Created by 张英堂 on 2016/10/17.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import "MCSetModel.h"
10 |
11 | @implementation MCSetModel
12 |
13 |
14 | + (instancetype)modelWithTitle:(NSString *)title
15 | type:(LogoType)type
16 | status:(SelectStatus)status{
17 | MCSetModel *model = [[MCSetModel alloc] init];
18 | model.title = title;
19 | model.type = type;
20 | model.status = status;
21 |
22 | return model;
23 | }
24 |
25 | - (void)setOpen{
26 | if (self.status == SelectStatusBool) {
27 | if (self.boolValue != YES) {
28 | self.boolValue = YES;
29 | }
30 | }
31 |
32 | }
33 |
34 | @end
35 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Models/MGFaceCompareModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGFaceCompareModel.h
3 | // FaceppDemo
4 | //
5 | // Created by Li Bo on 2017/5/19.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 | #import "MGImageData.h"
12 | #import "MGFaceInfo.h"
13 |
14 | @interface MGFaceCompareModel : NSObject
15 |
16 | - (instancetype)initWithImage:(UIImage *)image faceInfo:(MGFaceInfo *)faceInfo;
17 |
18 | @property (nonatomic, copy) NSString *name;
19 | @property (nonatomic, strong) NSData *feature;
20 | @property (nonatomic, strong) UIImage *image;
21 | @property (nonatomic, assign) BOOL selected;
22 |
23 | @property (nonatomic, assign) NSInteger trackID;
24 |
25 | - (void)getName;
26 |
27 | @end
28 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Models/MGFaceCompareModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // MGFaceCompareModel.m
3 | // FaceppDemo
4 | //
5 | // Created by Li Bo on 2017/5/19.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import "MGFaceCompareModel.h"
10 | #import
11 |
12 | static NSString *faceCount = @"MGFaceCompareModelFaceCount";
13 |
14 | @implementation MGFaceCompareModel
15 |
16 | - (instancetype)initWithImage:(UIImage *)image faceInfo:(MGFaceInfo *)faceInfo{
17 | if (self = [super init]) {
18 | _feature = faceInfo.featureData;
19 |
20 | // 将检测出的人脸框放大
21 | float x = faceInfo.rect.origin.x;
22 | float y = faceInfo.rect.origin.y;
23 | float width = faceInfo.rect.size.width;
24 | float height = faceInfo.rect.size.height;
25 | CGRect rect = CGRectMake(x-width/2, y-height/5 , width*1.8, height*1.4);
26 |
27 | _image = [MGImage croppedImage:image rect:rect];
28 | _image = [UIImage imageWithCGImage:[_image CGImage]
29 | scale:[_image scale]
30 | orientation:UIImageOrientationLeftMirrored];
31 | _trackID = faceInfo.trackID;
32 | }
33 | return self;
34 | }
35 |
36 | - (void)getName{
37 | if (![[NSUserDefaults standardUserDefaults] integerForKey:faceCount]) {
38 | [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:faceCount];
39 | }
40 | NSInteger count = [[NSUserDefaults standardUserDefaults] integerForKey:faceCount];
41 | count ++;
42 | _name = [NSString stringWithFormat:@"user_%ld",count];
43 | [[NSUserDefaults standardUserDefaults] setInteger:count forKey:faceCount];
44 | }
45 |
46 |
47 | - (void)encodeWithCoder:(NSCoder *)aCoder{
48 | [aCoder encodeObject:self.name forKey:@"name"];
49 | [aCoder encodeObject:self.feature forKey:@"feature"];
50 | [aCoder encodeObject:self.image forKey:@"image"];
51 | [aCoder encodeObject:[NSNumber numberWithBool:self.selected] forKey:@"selected"];
52 | }
53 |
54 |
55 | - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder{
56 | self = [super init];
57 | if (self) {
58 | self.name = [aDecoder decodeObjectForKey:@"name"];
59 | self.feature = [aDecoder decodeObjectForKey:@"feature"];
60 | self.image = [aDecoder decodeObjectForKey:@"image"];
61 | self.selected = [aDecoder decodeObjectForKey:@"selected"];
62 | }
63 | return self;
64 | }
65 |
66 |
67 |
68 |
69 | @end
70 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Models/MGFaceModelArray.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGFaceModelArray.h
3 | // LandMask
4 | //
5 | // Created by 张英堂 on 16/8/17.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 | #import
12 |
13 | #import "MGFaceInfo.h"
14 |
15 |
16 | @interface MGFaceModelArray : NSObject
17 |
18 | @property (nonatomic, strong) NSMutableArray * faceArray;
19 |
20 | @property (nonatomic, assign) NSUInteger count;
21 | @property (nonatomic, assign) CGFloat timeUsed;
22 | @property (nonatomic, assign) CGFloat AttributeTimeUsed;
23 |
24 | @property (nonatomic, assign) CGRect detectRect;
25 |
26 | @property (nonatomic, assign) NSInteger pointsCount;
27 |
28 |
29 | @property (nonatomic, assign) BOOL getFaceInfo;
30 | @property (nonatomic, assign) BOOL get3DInfo;
31 |
32 |
33 | - (void)addModel:(MGFaceInfo *)model;
34 |
35 | - (MGFaceInfo *)modelWithIndex:(NSUInteger)index;
36 |
37 |
38 | - (NSString *)getDebugString;
39 |
40 | @end
41 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Models/MGFaceModelArray.m:
--------------------------------------------------------------------------------
1 | //
2 | // MGFaceModelArray.m
3 | // LandMask
4 | //
5 | // Created by 张英堂 on 16/8/17.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import "MGFaceModelArray.h"
10 |
11 | @implementation MGFaceModelArray
12 |
13 | - (instancetype)init
14 | {
15 | self = [super init];
16 | if (self) {
17 | self.timeUsed = 0;
18 | self.detectRect = CGRectZero;
19 | }
20 | return self;
21 | }
22 |
23 | - (void)addModel:(MGFaceInfo *)model{
24 | [self.faceArray addObject:model];
25 | }
26 |
27 | - (MGFaceInfo *)modelWithIndex:(NSUInteger)index{
28 | MGFaceInfo *model = [self.faceArray objectAtIndex:index];
29 |
30 | return model;
31 | }
32 |
33 | -(NSMutableArray *)faceArray{
34 | if (!_faceArray) {
35 | _faceArray = [NSMutableArray arrayWithCapacity:5];
36 | }
37 | return _faceArray;
38 | }
39 |
40 | -(NSUInteger)count{
41 | return self.faceArray.count;
42 | }
43 |
44 | - (NSString *)getDebugString{
45 |
46 | NSMutableString *tempString = [NSMutableString string];
47 | [tempString appendFormat:@"%@:%.2f ms", NSLocalizedString(@"debug_message4", nil) ,self.timeUsed];
48 | [tempString appendFormat:@"\n%@:%.2f ms", NSLocalizedString(@"debug_message5", nil) ,self.AttributeTimeUsed];
49 |
50 | NSMutableString *conficeString = [NSMutableString string];
51 |
52 | if (self.count >= 1 ) {
53 | MGFaceInfo *model = [self modelWithIndex:0];
54 | [conficeString appendFormat:@"\n%@:%.2f", NSLocalizedString(@"debug_message6", nil), model.confidence];
55 |
56 | if (self.self.getFaceInfo) {
57 | [conficeString appendFormat:@"\n嘴巴:%zi", model.mouseStatus];
58 | [conficeString appendFormat:@"\n年龄:%.2f", model.age];
59 | [conficeString appendFormat:@"\n性别:%@", model.gender == 0 ? @"女":@"男"];
60 | }
61 | }
62 |
63 | [tempString appendString:conficeString];
64 |
65 | return tempString;
66 | }
67 |
68 | @end
69 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Models/TextModel.h:
--------------------------------------------------------------------------------
1 | //
2 | // TextModel.h
3 | // MGSDKV2Test
4 | //
5 | // Created by 张英堂 on 2016/10/21.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import "BaseModel.h"
10 |
11 | @interface TextModel : BaseModel
12 |
13 | @property (nonatomic, copy) NSString *title;
14 | @property (nonatomic, copy) NSString *text;
15 |
16 |
17 | + (instancetype)modelWith:(NSString *)title text:(NSString *)text;
18 | @end
19 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/Models/TextModel.m:
--------------------------------------------------------------------------------
1 | //
2 | // TextModel.m
3 | // MGSDKV2Test
4 | //
5 | // Created by 张英堂 on 2016/10/21.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import "TextModel.h"
10 |
11 | @implementation TextModel
12 |
13 | + (instancetype)modelWith:(NSString *)title text:(NSString *)text{
14 | TextModel *model = [[TextModel alloc] init];
15 | model.title = title;
16 | model.text = text;
17 |
18 |
19 | return model;
20 | }
21 |
22 | @end
23 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/ViewControllers/MGFaceListViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGFaceListViewController.h
3 | // FaceppDemo
4 | //
5 | // Created by Li Bo on 2017/5/19.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "MGFaceCompareModel.h"
11 |
12 | @interface MGFaceListViewController : UIViewController
13 |
14 | + (instancetype)storyboardInstance;
15 |
16 | @property (nonatomic, strong) NSArray *models;
17 |
18 | @end
19 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/ViewControllers/MGFaceListViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // MGFaceListViewController.m
3 | // FaceppDemo
4 | //
5 | // Created by Li Bo on 2017/5/19.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import "MGFaceListViewController.h"
10 | #import "MGFaceCompareCell.h"
11 | #import "MGFileManager.h"
12 |
13 | @interface MGFaceListViewController ()
14 | @property (weak, nonatomic) IBOutlet UITableView *tableView;
15 | @property (weak, nonatomic) IBOutlet UIView *bottomView;
16 | @property (weak, nonatomic) IBOutlet UIButton *cancelBtn;
17 | @property (weak, nonatomic) IBOutlet UIButton *okBtn;
18 |
19 | @end
20 |
21 | @implementation MGFaceListViewController
22 |
23 | + (instancetype)storyboardInstance{
24 | UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MGFaceListViewController" bundle:nil];
25 | return [sb instantiateViewControllerWithIdentifier:@"MGFaceListViewController"];
26 | }
27 |
28 | - (void)viewDidLoad {
29 | [super viewDidLoad];
30 | self.title = NSLocalizedString(@"viewController_title_choose_face", nil);
31 | _bottomView.backgroundColor = [UIColor colorWithRed:41/255. green:135/255. blue:192/255. alpha:1];
32 | _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
33 |
34 | [_cancelBtn setTitle:NSLocalizedString(@"button_title_cancel_all", nil) forState:UIControlStateNormal];
35 | [_cancelBtn setTitle:NSLocalizedString(@"button_title_cancel_all", nil) forState:UIControlStateHighlighted];
36 | [_okBtn setTitle:NSLocalizedString(@"alert_action_ok", nil) forState:UIControlStateNormal];
37 | [_okBtn setTitle:NSLocalizedString(@"alert_action_ok", nil) forState:UIControlStateHighlighted];
38 | }
39 |
40 | - (void)didReceiveMemoryWarning {
41 | [super didReceiveMemoryWarning];
42 | // Dispose of any resources that can be recreated.
43 | }
44 |
45 | #pragma mark - UITableViewDelegate -
46 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
47 | return 110;
48 | }
49 |
50 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
51 | [tableView deselectRowAtIndexPath:indexPath animated:YES];
52 | }
53 |
54 | #pragma mark - UITableViewDataSource -
55 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
56 | return _models.count;
57 | }
58 |
59 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
60 | MGFaceCompareCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
61 | cell.model = _models[indexPath.row];
62 | cell.delegate = self;
63 | return cell;
64 | }
65 |
66 |
67 | #pragma amrk - MGFaceCompareCellDelegate -
68 |
69 | - (void)nameDidEdit:(MGFaceCompareModel *)model{
70 | UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"alert_title_input_user_name", nil) message:nil preferredStyle:UIAlertControllerStyleAlert];
71 | [alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
72 |
73 | }];
74 | UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"alert_action_ok", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
75 | UITextField *name = alert.textFields.firstObject;
76 | NSString *str = name.text;
77 | if (str.length > 0) {
78 | model.name = str;
79 | [self.tableView reloadData];
80 | }
81 | }];
82 | UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"alert_title", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
83 |
84 | }];
85 | [alert addAction:okAction];
86 | [alert addAction:cancelAction];
87 | [self presentViewController:alert animated:YES completion:nil];
88 |
89 | }
90 |
91 | - (void)modelDidSelected:(MGFaceCompareModel *)model{
92 | NSLog(@"");
93 | }
94 |
95 | /*
96 | #pragma mark - Navigation
97 |
98 | // In a storyboard-based application, you will often want to do a little preparation before navigation
99 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
100 | // Get the new view controller using [segue destinationViewController].
101 | // Pass the selected object to the new view controller.
102 | }
103 | */
104 |
105 | - (IBAction)cancelBtnAction:(UIButton *)sender {
106 | for (MGFaceCompareModel *model in _models) {
107 | model.selected = NO;
108 | }
109 | [self.tableView reloadData];
110 | }
111 |
112 | - (IBAction)okBtnAction:(UIButton *)sender {
113 | NSMutableArray *arr = [NSMutableArray array];
114 | for (MGFaceCompareModel *model in _models) {
115 | if (model.selected == YES) {
116 | [arr addObject:model];
117 | }
118 | }
119 | [MGFileManager saveModels:arr];
120 | [self.navigationController popViewControllerAnimated:YES];
121 | }
122 |
123 | @end
124 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/ViewControllers/MGMarkSetViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGMarkSetViewController.h
3 | // LandMask
4 | //
5 | // Created by 张英堂 on 16/8/17.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface MGMarkSetViewController : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGDetectVideo/ViewControllers/MGVideoViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGVideoViewController.h
3 | // Test
4 | //
5 | // Created by 张英堂 on 16/4/20.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 | #import "MGFacepp.h"
12 |
13 | /**
14 | * 视频流检测---OpenGLES 版本
15 | */
16 | @interface MGVideoViewController : UIViewController
17 |
18 | @property (nonatomic, strong) MGFacepp *markManager;
19 |
20 | @property (nonatomic, strong) MGVideoManager *videoManager;
21 |
22 | @property (nonatomic, assign) CGRect detectRect;
23 | @property (nonatomic, assign) CGSize videoSize;
24 |
25 | @property (nonatomic, assign) BOOL debug;
26 | @property (nonatomic, assign) BOOL show3D;
27 | @property (nonatomic, assign) BOOL faceInfo;
28 | @property (nonatomic, assign) BOOL faceCompare;
29 |
30 | @property (nonatomic, assign) MGFppDetectionMode detectMode;
31 |
32 |
33 | @property (nonatomic, assign) int pointsNum;
34 |
35 | @end
36 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGFaceppSDK/MGAlgorithmInfo.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGAlgorithmInfo.h
3 | // MGFacepp
4 | //
5 | // Created by 张英堂 on 2017/1/10.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | #define MG_ABILITY_KEY_POSE3D @"pose3D"
13 | #define MG_ABILITY_KEY_EYE_STATUS @"eyeStatus"
14 | #define MG_ABILITY_KEY_MOUTH_SATUS @"mouthStatus"
15 | #define MG_ABILITY_KEY_MINORITY @"minority"
16 | #define MG_ABILITY_KEY_BLURNESS @"blurness"
17 | #define MG_ABILITY_KEY_AGE_GENDER @"ageGender"
18 | #define MG_ABILITY_KEY_EXTRACT_FEATURE @"extractFeature"
19 | #define MG_ABILITY_KEY_TRACK_FAST @"trackFast"
20 | #define MG_ABILITY_KEY_TRACK_ROBUST @"trackRobust"
21 | #define MG_ABILITY_KEY_DETECT @"detect"
22 | #define MG_ABILITY_KEY_DETECT_RECT @"detectRect"
23 | #define MG_ABILITY_KEY_IDCARD_QUALITY @"IDCardQuality"
24 | #define MG_ABILITY_KEY_TRACK @"track"
25 | #define MG_ABILITY_KEY_TRACK_RECT @"track_rect"
26 |
27 |
28 | @interface MGAlgorithmInfo : NSObject
29 |
30 |
31 | /**
32 | SDK 版本号
33 | */
34 | @property (nonatomic, copy, readonly) NSString *version;
35 |
36 | /**
37 | SDK 过期时间
38 | */
39 | @property (nonatomic, strong, readonly) NSDate *expireDate;
40 |
41 |
42 | /**
43 | 是否需要联网授权
44 | */
45 | @property (nonatomic, assign, readonly) BOOL needNetLicense;
46 |
47 |
48 | /**
49 | SDK 功能列表
50 | */
51 | @property (nonatomic, strong, readonly) NSArray *SDKAbility;
52 |
53 |
54 | /**
55 | SDK 限制的bundleId
56 | */
57 | @property (nonatomic, strong, readonly) NSString *bundleId;
58 |
59 |
60 | @end
61 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGFaceppSDK/MGDetectRectInfo.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGDetectRect.h
3 | // MGFacepp
4 | //
5 | // Created by Megvii on 2017/10/18.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | typedef NS_ENUM(NSInteger, MGOrientation) {
13 | MGOrientationLeft,
14 | MGOrientationUp,
15 | MGOrientationRight,
16 | MGOrientationDown,
17 | };
18 |
19 | @interface MGDetectRectInfo : NSObject
20 |
21 | @property (nonatomic, assign) float confidence;
22 |
23 | @property (nonatomic, assign) float angle;
24 |
25 | @property (nonatomic, assign) MGOrientation orient;
26 |
27 | @property (nonatomic, assign) CGRect rect;
28 |
29 | @end
30 |
31 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGFaceppSDK/MGFaceInfo.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGFaceModel.h
3 | // LandMask
4 | //
5 | // Created by 张英堂 on 16/7/11.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 | #import "MGFaceppCommon.h"
12 |
13 | typedef NS_ENUM(NSInteger, MGGender) {
14 | MGFemale = 0,
15 | MGMale = 1,
16 | };
17 |
18 | @interface MGFaceInfo : NSObject
19 |
20 | /** tracking ID */
21 | @property (nonatomic, assign) NSInteger trackID;
22 |
23 | /** 在该张图片中人脸序号 */
24 | @property (nonatomic, assign) int index;
25 |
26 | /** 人脸的rect */
27 | @property (nonatomic, assign) CGRect rect;
28 |
29 | /** 人脸点坐标 (NSValue -> CGPoints)*/
30 | @property (nonatomic, strong) NSArray *points;
31 |
32 | /** 该张人脸质量 */
33 | @property (nonatomic, assign) CGFloat confidence;
34 |
35 |
36 | #pragma mark 以下属性需要SDK版本支持 请使用 [MGAlgorithmInfo SDKAbility] 属性,获取SDK支持功能
37 |
38 | #pragma mark 需要主动调用 MGFacepp 相关方法获取
39 | //3D info
40 | @property (nonatomic, assign) float pitch;
41 | @property (nonatomic, assign) float yaw;
42 | @property (nonatomic, assign) float roll;
43 |
44 | /** 年龄 */
45 | @property (nonatomic, assign) float age;
46 | /** 性别 */
47 | @property (nonatomic, assign) MGGender gender;
48 | /** blurness */
49 | @property (nonatomic, assign) float blurness;
50 | /** minority */
51 | @property (nonatomic, assign) float minority;
52 |
53 | /** 眼状态 */
54 | @property (nonatomic, assign) MGEyeStatus leftEyesStatus;
55 | @property (nonatomic, assign) MGEyeStatus rightEyesStatus;
56 |
57 | /** 嘴状态 */
58 | @property (nonatomic, assign) MGMouthStatus mouseStatus;
59 |
60 |
61 | #pragma mark -
62 |
63 | /**
64 | 人脸的 feature
65 | */
66 | @property (nonatomic, strong, readonly) NSData *featureData;
67 |
68 |
69 |
70 | @end
71 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGFaceppSDK/MGFacepp.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGFacepp.h
3 | // LandMask
4 | //
5 | // Created by 张英堂 on 16/9/5.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | #import "MGFaceppConfig.h"
13 | #import "MGImageData.h"
14 | #import "MGFaceppCommon.h"
15 | #import "MGAlgorithmInfo.h"
16 | #import "MGFaceInfo.h"
17 | #import "MGDetectRectInfo.h"
18 |
19 | @interface MGFacepp : NSObject
20 |
21 | - (MGFaceppConfig *)getFaceppConfig;
22 |
23 | - (instancetype)init DEPRECATED_ATTRIBUTE;
24 |
25 | /**
26 | * 初始化方法 必须使用该方法初始化,否则会导致初始化失败。
27 | *
28 | * @param modelData model data
29 | * @param config 设置的callback
30 | * @return 实例化
31 | */
32 | - (instancetype)initWithModel:(NSData *)modelData
33 | faceppSetting:(void(^)(MGFaceppConfig *config))config;
34 |
35 | /**
36 | 初始化方法
37 |
38 | @param modelData model data
39 | @param maxFaceCount 一张图像中识别的最大人脸数,设置为1即为单脸跟踪
40 | @param config 设置的callback
41 | @return handle
42 | */
43 | - (instancetype)initWithModel:(NSData *)modelData maxFaceCount:(NSInteger)maxFaceCount faceppSetting:(void(^)(MGFaceppConfig *config))config;
44 |
45 | /**
46 | * @param config 更新设置参数
47 | */
48 | - (BOOL)updateFaceppSetting:(void(^)(MGFaceppConfig *config))config;
49 |
50 |
51 | /**
52 | * 获取检测器目前状态
53 | */
54 | @property (nonatomic, assign, readonly) MGFaceppStatus status;
55 |
56 |
57 | #pragma mark - 检测人脸信息
58 | /**
59 | * 检测人脸信息
60 | *
61 | * @param imagedata 检测的图片
62 | * @return 检测结果(如果为 nil 时候,检测器异常,检测失败,请检测代码以及设置)
63 | */
64 | - (NSArray *)detectWithImageData:(MGImageData *)imagedata;
65 |
66 | /**
67 | * 检测人脸框
68 | *
69 | * @param imagedata 检测的图片
70 | * @return 检测结果(如果为 nil 时候,检测器异常,检测失败,请检测代码以及设置)
71 | */
72 | - (NSInteger)getFaceNumberWithImageData:(MGImageData *)imagedata;
73 |
74 |
75 | /**
76 | * 人脸关键点平滑
77 | *
78 | * @param faceInfo faceinfo model
79 | * @param isSmooth 是否关键点平滑,防止人脸抖动
80 | * @param nr 关键点个数
81 | */
82 | - (BOOL)GetGetLandmark:(MGFaceInfo *)faceInfo isSmooth:(BOOL)isSmooth pointsNumber:(int)nr;
83 |
84 | /**
85 | * 获取人脸框
86 | *
87 | *
88 | * @param index faceinfo model
89 | * @param isSmooth 是否关键点平滑,防止人脸抖动
90 | */
91 | - (MGDetectRectInfo *)GetRectAtIndex:(int)index isSmooth:(BOOL)isSmooth;
92 |
93 | /**
94 | * 获取人脸 3D信息
95 | * @param faceInfo faceInfo
96 | * @return 是否获取成功
97 | */
98 | - (BOOL)GetAttribute3D:(MGFaceInfo *)faceInfo;
99 |
100 | /**
101 | * 获取 眼状态
102 | * @param faceInfo faceInfo
103 | * @return 是否获取成功
104 | */
105 | - (BOOL)GetAttributeEyeStatus:(MGFaceInfo *)faceInfo;
106 |
107 | /**
108 | * 获取 嘴状态
109 | * @param faceInfo faceInfo
110 | * @return 是否获取成功
111 | */
112 | - (BOOL)GetAttributeMouseStatus:(MGFaceInfo *)faceInfo;
113 |
114 | /**
115 | * 获取 年龄
116 | * @param faceInfo faceInfo
117 | * @return 是否获取成功
118 | */
119 | - (BOOL)GetAttributeAgeGenderStatus:(MGFaceInfo *)faceInfo;
120 |
121 | /**
122 | 获取 Blurness 状态
123 |
124 | @param faceInfo faceInfo
125 | @return 是否获取成功
126 | */
127 | - (BOOL)GetBlurnessStatus:(MGFaceInfo *)faceInfo;
128 |
129 | /**
130 | 获取 Minorit 状态
131 |
132 | @param faceInfo faceInfo
133 | @return 是否获取成功
134 | */
135 | - (BOOL)GetMinorityStatus:(MGFaceInfo *)faceInfo;
136 |
137 | /**
138 | 获取人脸的 Feature 数据
139 |
140 | @param faceInfo faceinfo
141 | @return 是否获取成功
142 | */
143 | - (BOOL)GetFeatureData:(MGFaceInfo *)faceInfo;
144 |
145 | /**
146 | 比较两个人脸相似度, 必须改 MGFaceInfo 获取过 Feature 数据才有效
147 | 如果成功返回人脸相似度, 如果比对失败,返回 -1.0
148 |
149 | @param faceInfo MGFaceInfo 1
150 | @param faceInf2 MGFaceInfo 2
151 | @return 比对相似度
152 | */
153 | - (float)faceCompareWithFaceInfo:(MGFaceInfo *)faceInfo faceInf2:(MGFaceInfo *)faceInf2;
154 |
155 | /**
156 | 比较两个人脸相似度
157 | 如果成功返回人脸相似度, 如果比对失败,返回 -1.0
158 |
159 | @param featureData featureData 1
160 | @param featureData2 featureData 2
161 | @return 相似度
162 | */
163 | - (float)faceCompareWithFeatureData:(NSData *)featureData featureData2:(NSData *)featureData2;
164 |
165 |
166 | /** 开启检测新的一帧,在每次调用 detectWithImageData: 之前调用。 */
167 | - (void)beginDetectionFrame;
168 |
169 | /** 停止当前改帧的检测,在获取人脸详细信息后,需要主动调用该方法结束当前帧,以便进入下一帧 */
170 | - (void)endDetectionFrame;
171 |
172 |
173 | /**
174 | 释放算法资源
175 | 算法在计算时需要占用一些内存资源,必须在所有算法的句柄(handle)被释放后再调用
176 |
177 | @return 成功则返回 YES
178 | */
179 | - (BOOL)shutDown;
180 |
181 | #pragma mark - 类方法,获取 SDK 相关信息
182 |
183 |
184 | /**
185 | 获取版本号
186 |
187 | @return 版本号
188 | */
189 | + (NSString *)getSDKVersion;
190 |
191 |
192 | /**
193 | 获取 SDK jenkins 号
194 |
195 | @return SDK jenkins 号
196 | */
197 | + (NSString *)getJenkinsNumber;
198 |
199 |
200 | /**
201 | 清除track缓存
202 |
203 | @return 成功则返回 YES
204 | */
205 | - (BOOL)resetTrack;
206 |
207 |
208 | /**
209 | 获取 SDK 相关信息
210 |
211 | @param modelData model data
212 | @return sdk 相关信息
213 | */
214 | + (MGAlgorithmInfo *)getSDKAlgorithmInfoWithModel:(NSData *)modelData;;
215 |
216 |
217 |
218 |
219 | @end
220 |
221 |
222 |
223 |
224 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGFaceppSDK/MGFaceppCommon.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGFaceppConfig.h
3 | // MGLandMark
4 | //
5 | // Created by 张英堂 on 16/9/5.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #ifndef MGFaceppConfig_h
10 | #define MGFaceppConfig_h
11 |
12 | #import
13 |
14 | #define KMGFACEMODELNAME @"megviifacepp_0_5_2_model"
15 | #define KMGFACEMODELTYPE @""
16 |
17 |
18 | /** 设置检测视频帧的类型 */
19 | typedef NS_ENUM(NSInteger, MGPixelFormatType) {
20 | PixelFormatTypeGRAY = 0,
21 | PixelFormatTypeBGR,
22 | PixelFormatTypeNV21,
23 | PixelFormatTypeRGBA,
24 | PixelFormatTypeRGB
25 | };
26 |
27 | /** face SDK 功能类型 */
28 | typedef NS_ENUM(NSInteger, MGFaceAbility) {
29 | MGFaceAbilityTrack = 0,
30 | MGFaceAbilityDetect = 1,
31 | MGFaceAbilityPose3d = 2,
32 | MGFaceAbilityEyeStatus = 3,
33 | MGFaceAbilityMouseStatus = 4,
34 | MGFaceAbilityMinority = 5,
35 | MGFaceAbilityBlurness = 6,
36 | MGFaceAbilityAgeGender = 7,
37 | MGFaceAbilityExtractFeature = 8,
38 | };
39 |
40 |
41 | /** 人脸检测框 */
42 | typedef struct {
43 | int left;
44 | int top;
45 | int right;
46 | int bottom;
47 | }MGDetectROI;
48 |
49 | CG_INLINE MGDetectROI MGDetectROIMake(int left, int top, int right,int bottom){
50 | MGDetectROI d;
51 | d.left = left;
52 | d.top = top;
53 | d.right = right;
54 | d.bottom = bottom;
55 | return d;
56 | }
57 |
58 | typedef NS_ENUM(NSUInteger ,MGFaceppStatus) {
59 | MGMarkPrepareWork = 1, //初始化已结束, 准备工作
60 | MGMarkWorking, //正在检测中
61 | MGMarkWaiting, //上一帧已经结束,等待下一帧输入
62 | MGMarkStopped //检测器停止检测,等待释放
63 | };
64 |
65 | typedef NS_ENUM(NSUInteger ,MGFppDetectionMode) {
66 | MGFppDetectionModeDetect = 0,
67 | MGFppDetectionModeTracking = 1, // 此模式已经废弃,请使用 robust 模式
68 | MGFppDetectionModeTrackingFast = 3,
69 | MGFppDetectionModeTrackingRobust = 4,
70 | MGFppDetectionModeDetectRect = 5,
71 | MGFppDetectionModeTrackingRect = 6,
72 | };
73 |
74 |
75 | typedef NS_ENUM(NSUInteger ,MGEyeStatus) {
76 | MGEyeStatusNoGlassesOpen = 0,
77 | MGEyeStatusNoGlassesClose = 1,
78 | MGEyeStatusNormalGlassesOpen = 2, //普通眼镜
79 | MGEyeStatusNormalGlassesClose = 3,
80 | MGEyeStatuoDarkGlasses = 4, //太阳镜
81 | MGEyeStatusOtherOcclusion = 5,
82 | MGEyeStatusCount = 6
83 | };
84 |
85 | typedef NS_ENUM(NSUInteger ,MGMouthStatus) {
86 | MGMouthStatusOpen = 0,
87 | MGMouthStatusClose = 1,
88 | MGMouthStatusMaskOrRespopator = 2, //
89 | MGMouthStatusOtherOcclusion = 3,
90 | MGMouthStatusCount = 4, //
91 | };
92 |
93 |
94 |
95 |
96 |
97 | #endif /* MGFaceppConfig_h */
98 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGFaceppSDK/MGFaceppConfig.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGFaceppConfig.h
3 | // MGFacepp
4 | //
5 | // Created by 张英堂 on 2016/12/27.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | #import "MGFaceppCommon.h"
13 |
14 | #pragma mark - 设置检测参数
15 |
16 | @interface MGFaceppConfig : NSObject
17 |
18 | /** 人脸大小 默认 100 */
19 | @property (nonatomic, assign) int minFaceSize;
20 |
21 | /** 重新全局检测间隔 40 */
22 | @property (nonatomic, assign) int interval;
23 |
24 | /** 旋转角度 defalut 0, [0,90,180,270,360] */
25 | @property (nonatomic, assign) int orientation;
26 |
27 |
28 | /** 设置Detection类型 默认:MGFppDetectionModeNormal */
29 | @property (nonatomic, assign) MGFppDetectionMode detectionMode;
30 |
31 | /** 设置检测区域(为视频流原图的区域),默认全图检测 */
32 | @property (nonatomic, assign) MGDetectROI detectROI;
33 |
34 | /** 设置视频流格式,默认 PixelFormatTypeRGBA */
35 | @property (nonatomic, assign) MGPixelFormatType pixelFormatType;
36 |
37 |
38 | @property (nonatomic, assign) float faceConfidenceFilter;
39 |
40 |
41 |
42 | @end
43 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGFaceppSDK/MGImageData.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGImageData.h
3 | // MGFacepp
4 | //
5 | // Created by 张英堂 on 2016/12/27.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @interface MGImageData : NSObject
13 |
14 | /** 请不要使用该方法初始化 */
15 | - (instancetype)init DEPRECATED_ATTRIBUTE;
16 |
17 | /**
18 | 初始化方法,二选一
19 |
20 | @param sampleBuffer 视频流帧
21 | @return 实例化对象
22 | */
23 | - (instancetype)initWithSampleBuffer:(CMSampleBufferRef)sampleBuffer;
24 |
25 | /**
26 | 初始化方法,二选一
27 |
28 |
29 | @param image UIImage 对象
30 | @return 实例化对象
31 | */
32 | - (instancetype)initWithImage:(UIImage *)image;
33 |
34 |
35 | /**
36 | 图片宽度
37 | */
38 | @property (nonatomic, assign) CGFloat width;
39 |
40 | /**
41 | 图片高度
42 | */
43 | @property (nonatomic, assign) CGFloat height;
44 |
45 |
46 | /**
47 | 是否为图片
48 | */
49 | @property (nonatomic, assign, readonly) BOOL isUIImage;
50 |
51 |
52 | /**
53 | 获取内存地址
54 |
55 | @return 内存地址
56 | */
57 | - (const char*)getData;
58 |
59 |
60 | /**
61 | 释放内存
62 | */
63 | - (void)releaseImageData;
64 |
65 | @end
66 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGFaceppSDK/libMGFacepp-0.5.2.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/MGFaceppSDK/libMGFacepp-0.5.2.a
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGFaceppSDK/megviifacepp_0_5_2_model:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/MGFaceppSDK/megviifacepp_0_5_2_model
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGHelp/MGFileManager.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGFileManager.h
3 | // FaceppDemo
4 | //
5 | // Created by Li Bo on 2017/5/22.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface MGFileManager : NSObject
12 |
13 | + (void)saveModels:(NSArray *)models;
14 |
15 | + (NSArray *)getModels;
16 |
17 | @end
18 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGHelp/MGFileManager.m:
--------------------------------------------------------------------------------
1 | //
2 | // MGFileManager.m
3 | // FaceppDemo
4 | //
5 | // Created by Li Bo on 2017/5/22.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import "MGFileManager.h"
10 |
11 | static NSString *fileName = @"fileName";
12 |
13 | @implementation MGFileManager
14 |
15 | + (NSString *)filePath:(NSString *)fileName{
16 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
17 | NSString *document = [paths lastObject];
18 | return [NSString stringWithFormat:@"%@/%@",document,fileName];
19 | }
20 |
21 | + (void)saveModels:(NSArray *)models{
22 | NSFileManager *fileManager = [NSFileManager defaultManager];
23 | [fileManager createFileAtPath:[MGFileManager filePath:fileName] contents:nil attributes:nil];
24 | NSData *data = [NSKeyedArchiver archivedDataWithRootObject:models];
25 | [data writeToFile:[MGFileManager filePath:fileName] atomically:NO];
26 | }
27 |
28 | + (NSArray *)getModels{
29 | NSFileManager *fileManager = [NSFileManager defaultManager];
30 | NSData *data = [fileManager contentsAtPath:[MGFileManager filePath:fileName]];
31 | return (NSArray *)[NSKeyedUnarchiver unarchiveObjectWithData:data];
32 | }
33 |
34 | @end
35 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGHelp/MGHeader.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGMacro.h
3 | //
4 |
5 | #ifndef text_MGMacro_h
6 | #define text_MGMacro_h
7 |
8 |
9 | #define MEGVII_EGG_MODEL @"MegviiEGG_0_1_0_model"
10 |
11 | #define WIN_WIDTH [UIScreen mainScreen].bounds.size.width
12 | #define WIN_HEIGHT [UIScreen mainScreen].bounds.size.height
13 |
14 | #define MGColorWithRGB(R, G, B, A) [UIColor colorWithRed:R/255.0f green:G/255.0f blue:B/255.0f alpha:A]
15 |
16 |
17 | #if DEBUG
18 | #define MGLog(FORMAT, ...) fprintf(stderr,"%s:%d \t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
19 | #else
20 | #define NSLog(FORMAT, ...) nil
21 | #endif
22 |
23 | #define MGLocalString(key) NSLocalizedStringFromTable(key, @"MGFaceDetection", nil)
24 |
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGLicenseManagerHelper/MGFaceLicenseHandle.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGLicenseHandle.h
3 | // MGSDKV2Test
4 | //
5 | // Created by 张英堂 on 16/9/7.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 | #import
12 | #import "MGNetAccount.h"
13 |
14 |
15 |
16 | @interface MGFaceLicenseHandle : NSObject
17 |
18 |
19 | /**
20 | * 获取当前SDK是否授权--- 子类需要重写该方法,通过该类获取的 是否授权无法全部包括使用的SDK
21 | *
22 | * @return 是否授权
23 | */
24 | + (BOOL)getLicense;
25 |
26 | + (NSDate *)getLicenseDate;
27 |
28 | /**
29 | * 只有当授权时间少于 1天的时候,才会进行授权操作
30 | *
31 | * @param finish
32 | */
33 | + (void)licenseForNetwokrFinish:(void(^)(bool License, NSDate *sdkDate))finish;
34 |
35 |
36 | /**
37 | 获取 face SDK 是否需要联网授权
38 |
39 | @return 是否为联网授权版本
40 | */
41 | + (BOOL)getNeedNetLicense;
42 |
43 |
44 |
45 |
46 | @end
47 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGLicenseManagerHelper/MGFaceLicenseHandle.m:
--------------------------------------------------------------------------------
1 | //
2 | // MGLicenseHandle.m
3 | // MGSDKV2Test
4 | //
5 | // Created by 张英堂 on 16/9/7.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import "MGFaceLicenseHandle.h"
10 | #import "MGFacepp.h"
11 | #import "MGNetAccount.h"
12 |
13 |
14 | @implementation MGFaceLicenseHandle
15 |
16 |
17 | + (BOOL)getLicense{
18 | NSDate *sdkDate = [self getLicenseDate];
19 | return [self compareSDKDate:sdkDate];
20 | }
21 |
22 |
23 | + (void)licenseForNetwokrFinish:(void(^)(bool License, NSDate *sdkDate))finish {
24 |
25 |
26 |
27 | // 检查 apk
28 | if ([MG_LICENSE_KEY isEqualToString:@""] || [MG_LICENSE_SECRET isEqualToString:@""]) {
29 | UIAlertController *controller = [UIAlertController alertControllerWithTitle:@"API Key 或 secret 不能为空"
30 | message:@"请到官网申请 ‘https://www.faceplusplus.com.cn’"
31 | preferredStyle:UIAlertControllerStyleAlert];
32 | UIAlertAction *action = [UIAlertAction actionWithTitle:@"好"
33 | style:UIAlertActionStyleCancel
34 | handler:nil];
35 | [controller addAction:action];
36 | UIViewController *rootViewController = [UIApplication sharedApplication].keyWindow.rootViewController;
37 | UIViewController *currentVC = [MGFaceLicenseHandle getCurrentVCFrom:rootViewController];
38 | [currentVC presentViewController:controller animated:YES completion:nil];
39 |
40 | if (finish) {
41 | finish(NO, nil);
42 | }
43 | return;
44 | }
45 |
46 | NSDate *licenSDKDate = [self getLicenseDate];
47 |
48 | if ([self compareSDKDate:licenSDKDate] == NO) {
49 | if (finish) {
50 | finish(YES, [self getLicenseDate]);
51 | }
52 | return;
53 | }
54 |
55 | NSString *version = [MGFacepp getSDKVersion];
56 | NSString *uuid = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
57 |
58 | [MGLicenseManager takeLicenseFromNetwokrUUID:uuid
59 | version:version
60 | sdkType:MGSDKTypeLandmark
61 | apiKey:MG_LICENSE_KEY
62 | apiSecret:MG_LICENSE_SECRET
63 | apiDuration:MGAPIDurationDay
64 | URLString:MGLicenseURL_CN
65 | finish:^(bool License, NSError *error) {
66 | if (error) {
67 | MG_LICENSE_LOG(@"Auth error = %@", error);
68 | }
69 |
70 | if (License) {
71 | NSDate *nowSDKDate = [self getLicenseDate];
72 |
73 | if (finish) {
74 | finish(License, nowSDKDate);
75 | }
76 | } else {
77 | if (finish) {
78 | finish(License, licenSDKDate);
79 | }
80 | }
81 | }];
82 |
83 | }
84 |
85 | + (NSDate *)getLicenseDate {
86 | NSString *modelPath = [[NSBundle mainBundle] pathForResource:KMGFACEMODELNAME ofType:@""];
87 | NSData *modelData = [NSData dataWithContentsOfFile:modelPath];
88 | MGAlgorithmInfo *sdkInfo = [MGFacepp getSDKAlgorithmInfoWithModel:modelData];
89 | if (sdkInfo.needNetLicense) {
90 | NSString *version = [MGFacepp getSDKVersion];
91 | NSDate *date = [MGLicenseManager getExpiretime:version];
92 | NSLog(@"过期时间 : %@",date);
93 | return date;
94 | } else {
95 | return sdkInfo.expireDate;
96 | }
97 | }
98 |
99 | + (BOOL)compareSDKDate:(NSDate *)sdkDate{
100 |
101 | NSDate *nowDate = [NSDate date];
102 | double result = [sdkDate timeIntervalSinceDate:nowDate];
103 |
104 |
105 | if (result >= 1*1*60*60.0) {
106 | return NO;
107 | }
108 | return YES;
109 | }
110 |
111 | + (BOOL)getNeedNetLicense{
112 |
113 | NSString *modelPath = [[NSBundle mainBundle] pathForResource:KMGFACEMODELNAME ofType:@""];
114 | NSData *modelData = [NSData dataWithContentsOfFile:modelPath];
115 |
116 | MGAlgorithmInfo *sdkInfo = [MGFacepp getSDKAlgorithmInfoWithModel:modelData];
117 | NSLog(@"\n************\nSDK 功能列表: %@\n是否需要联网授权: %d\n版本号:%@\n过期时间:%@ \n************", sdkInfo.SDKAbility, sdkInfo.needNetLicense, sdkInfo.version, sdkInfo.expireDate);
118 |
119 | return sdkInfo.needNetLicense;
120 | }
121 |
122 | + (UIViewController *)getCurrentVCFrom:(UIViewController *)rootVC
123 | {
124 | UIViewController *currentVC;
125 |
126 | if ([rootVC presentedViewController]) {
127 | // 视图是被presented出来的
128 | rootVC = [rootVC presentedViewController];
129 | }
130 |
131 | if ([rootVC isKindOfClass:[UITabBarController class]]) {
132 | // 根视图为UITabBarController
133 | currentVC = [self getCurrentVCFrom:[(UITabBarController *)rootVC selectedViewController]];
134 | } else if ([rootVC isKindOfClass:[UINavigationController class]]){
135 | // 根视图为UINavigationController
136 | currentVC = [self getCurrentVCFrom:[(UINavigationController *)rootVC visibleViewController]];
137 | } else {
138 | // 根视图为非导航类
139 | currentVC = rootVC;
140 | }
141 |
142 | return currentVC;
143 | }
144 |
145 |
146 | @end
147 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MGLicenseManagerHelper/MGNetAccount.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGNetAccount_example.h
3 | // FaceppDemo
4 | //
5 | // Created by 张英堂 on 2017/1/12.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #ifndef MGNetAccount_example_h
10 | #define MGNetAccount_example_h
11 |
12 |
13 |
14 | // 访问 https://www.faceplusplus.com.cn, 登录后在控制台生成对应的 key 和 secret 填写到下面的字符串中
15 |
16 | #define MG_LICENSE_KEY @"" // api_key
17 | #define MG_LICENSE_SECRET @"" // api_secret
18 |
19 |
20 | #endif /* MGNetAccount_example_h */
21 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MainViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // MainViewController.h
3 | // FaceppDemo
4 | //
5 | // Created by 张英堂 on 2017/1/11.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface MainViewController : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/MainViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // MainViewController.m
3 | // FaceppDemo
4 | //
5 | // Created by 张英堂 on 2017/1/11.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import "MainViewController.h"
10 | #import "MGFaceLicenseHandle.h"
11 | #import "MGFacepp.h"
12 |
13 | @interface MainViewController ()
14 | @property (weak, nonatomic) IBOutlet UILabel *messageView;
15 | @property (weak, nonatomic) IBOutlet UIButton *videoBtn;
16 |
17 | @end
18 |
19 | @implementation MainViewController
20 |
21 | - (void)viewDidLoad {
22 | [super viewDidLoad];
23 |
24 | /** 进行联网授权版本判断,联网授权就需要进行网络授权 */
25 | BOOL needLicense = [MGFaceLicenseHandle getNeedNetLicense];
26 |
27 | if (needLicense) {
28 | self.videoBtn.userInteractionEnabled = NO;
29 | [MGFaceLicenseHandle licenseForNetwokrFinish:^(bool License, NSDate *sdkDate) {
30 | if (!License) {
31 | NSLog(@"联网授权失败 !!!");
32 | } else {
33 | NSLog(@"联网授权成功");
34 | self.videoBtn.userInteractionEnabled = YES;
35 | }
36 | }];
37 | } else {
38 | NSLog(@"SDK 为非联网授权版本!");
39 | }
40 |
41 |
42 | NSString *modelPath = [[NSBundle mainBundle] pathForResource:KMGFACEMODELNAME ofType:@""];
43 | NSData *modelData = [NSData dataWithContentsOfFile:modelPath];
44 | MGAlgorithmInfo *sdkInfo = [MGFacepp getSDKAlgorithmInfoWithModel:modelData];
45 |
46 | NSMutableString *tempString = [NSMutableString stringWithString:@""];
47 | [tempString appendFormat:@"\n%@: %@",NSLocalizedString(@"debug_message1", nil), sdkInfo.needNetLicense?@"YES":@"NO"];
48 | [tempString appendFormat:@"\n%@: %@",NSLocalizedString(@"debug_message2", nil),sdkInfo.version];
49 | [tempString appendFormat:@"\n%@: {\n", NSLocalizedString(@"debug_message3", nil)];
50 | for (int i = 0; i < sdkInfo.SDKAbility.count; i++) {
51 | [tempString appendFormat:@" %@", sdkInfo.SDKAbility[i]];
52 | [tempString appendString:@",\n"];
53 | }
54 | [tempString appendString:@"}"];
55 | [self.messageView setText:tempString];
56 |
57 | UIBarButtonItem *backItem = [[UIBarButtonItem alloc]initWithTitle:NSLocalizedString(@"navigationBar_back", nil) style:UIBarButtonItemStylePlain target:nil action:nil];
58 | self.navigationItem.backBarButtonItem = backItem;
59 | }
60 |
61 |
62 |
63 |
64 | @end
65 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/OpenGL/GLUtilities/GLESUtils.h:
--------------------------------------------------------------------------------
1 | //
2 | // GLESUtils.h
3 | // Tutorial02
4 | //
5 | // Created by kesalin on 12-11-25.
6 | // Copyright (c) 2012年 Created by kesalin@gmail.com on. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 | #import
12 |
13 |
14 | @interface GLESUtils : NSObject
15 |
16 |
17 | +(GLuint)loadShader:(GLenum)type withString:(NSString *)shaderString;
18 | +(GLuint)loadShader:(GLenum)type withFilepath:(NSString *)shaderFilepath;
19 |
20 |
21 | +(GLuint)loadProgram:(NSString *)vertexShaderFilepath withFragmentShaderFilepath:(NSString *)fragmentShaderFilepath;
22 |
23 | + (const GLchar *)readFile:(NSString *)name;
24 |
25 |
26 |
27 | GLint glueCompileShader(GLenum target, GLsizei count, const GLchar **sources, GLuint *shader);
28 | GLint glueLinkProgram(GLuint program);
29 | GLint glueValidateProgram(GLuint program);
30 | GLint glueGetUniformLocation(GLuint program, const GLchar *name);
31 |
32 | GLint glueCreateProgram(const GLchar *vertSource, const GLchar *fragSource,
33 | GLsizei attribNameCt, const GLchar **attribNames,
34 | const GLint *attribLocations,
35 | GLsizei uniformNameCt, const GLchar **uniformNames,
36 | GLint *uniformLocations,
37 | GLuint *program);
38 |
39 |
40 |
41 | @end
42 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/OpenGL/MGOpenGLView.h:
--------------------------------------------------------------------------------
1 | /*
2 | File: OpenGLPixelBufferView.h
3 | Abstract: The OpenGL ES view
4 | Version: 2.1
5 |
6 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
7 | Inc. ("Apple") in consideration of your agreement to the following
8 | terms, and your use, installation, modification or redistribution of
9 | this Apple software constitutes acceptance of these terms. If you do
10 | not agree with these terms, please do not use, install, modify or
11 | redistribute this Apple software.
12 |
13 | In consideration of your agreement to abide by the following terms, and
14 | subject to these terms, Apple grants you a personal, non-exclusive
15 | license, under Apple's copyrights in this original Apple software (the
16 | "Apple Software"), to use, reproduce, modify and redistribute the Apple
17 | Software, with or without modifications, in source and/or binary forms;
18 | provided that if you redistribute the Apple Software in its entirety and
19 | without modifications, you must retain this notice and the following
20 | text and disclaimers in all such redistributions of the Apple Software.
21 | Neither the name, trademarks, service marks or logos of Apple Inc. may
22 | be used to endorse or promote products derived from the Apple Software
23 | without specific prior written permission from Apple. Except as
24 | expressly stated in this notice, no other rights or licenses, express or
25 | implied, are granted by Apple herein, including but not limited to any
26 | patent rights that may be infringed by your derivative works or by other
27 | works in which the Apple Software may be incorporated.
28 |
29 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE
30 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
31 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
32 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
33 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
34 |
35 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
36 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
39 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
40 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
41 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
42 | POSSIBILITY OF SUCH DAMAGE.
43 |
44 | Copyright (C) 2014 Apple Inc. All Rights Reserved.
45 |
46 | */
47 |
48 | #import
49 | #import "MGOpenGLConfig.h"
50 |
51 |
52 | @interface MGOpenGLView : UIView
53 |
54 | - (void)displayPixelBuffer:(CVPixelBufferRef )pixelBuffer;
55 |
56 | - (void)flushPixelBufferCache;
57 | - (void)reset;
58 |
59 |
60 |
61 | @end
62 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/OpenGL/Manager/MGOpenGLConfig.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGOpenGLConfig.h
3 | // LandMask
4 | //
5 | // Created by 张英堂 on 16/8/17.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #ifndef MGOpenGLConfig_h
10 | #define MGOpenGLConfig_h
11 |
12 | #import
13 | #import
14 | #import
15 | #import
16 |
17 |
18 | enum {
19 | ATTRIB_VERTEX,
20 | ATTRIB_TEXTUREPOSITON,
21 | NUM_ATTRIBUTES
22 | };
23 |
24 | typedef struct {
25 | float Position[3];
26 | float TexCoord[2];
27 | } Vertex;
28 |
29 | static const GLfloat squareVertices[] = {
30 | -1.0f, -1.0f, // bottom left
31 | 1.0f, -1.0f, // bottom right
32 | -1.0f, 1.0f, // top left
33 | 1.0f, 1.0f, // top right
34 | };
35 | static const float textureVertices[] = {
36 | 0.0f, 0.0f, // bottom left
37 | 1.0f, 0.0f, // bottom right
38 | 0.0f, 1.0f, // top left
39 | 1.0f, 1.0f, // top right
40 | };
41 |
42 |
43 | #endif /* MGOpenGLConfig_h */
44 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/OpenGL/Manager/MGOpenGLRenderer.h:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | File: RosyWriterOpenGLRenderer.h
4 | Abstract: The RosyWriter OpenGL effect renderer
5 | Version: 2.1
6 |
7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
8 | Inc. ("Apple") in consideration of your agreement to the following
9 | terms, and your use, installation, modification or redistribution of
10 | this Apple software constitutes acceptance of these terms. If you do
11 | not agree with these terms, please do not use, install, modify or
12 | redistribute this Apple software.
13 |
14 | In consideration of your agreement to abide by the following terms, and
15 | subject to these terms, Apple grants you a personal, non-exclusive
16 | license, under Apple's copyrights in this original Apple software (the
17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple
18 | Software, with or without modifications, in source and/or binary forms;
19 | provided that if you redistribute the Apple Software in its entirety and
20 | without modifications, you must retain this notice and the following
21 | text and disclaimers in all such redistributions of the Apple Software.
22 | Neither the name, trademarks, service marks or logos of Apple Inc. may
23 | be used to endorse or promote products derived from the Apple Software
24 | without specific prior written permission from Apple. Except as
25 | expressly stated in this notice, no other rights or licenses, express or
26 | implied, are granted by Apple herein, including but not limited to any
27 | patent rights that may be infringed by your derivative works or by other
28 | works in which the Apple Software may be incorporated.
29 |
30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE
31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
35 |
36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
43 | POSSIBILITY OF SUCH DAMAGE.
44 |
45 | Copyright (C) 2014 Apple Inc. All Rights Reserved.
46 |
47 | */
48 |
49 | #import
50 | #import
51 | #import "MGOpenGLConfig.h"
52 |
53 | @class MGFaceModelArray;
54 |
55 |
56 |
57 | @interface MGOpenGLRenderer : NSObject
58 |
59 | /* Format/Processing Requirements */
60 | @property(nonatomic, readonly) BOOL operatesInPlace; // When YES the input pixel buffer is written to by the renderer instead of writing the result to a new pixel buffer.
61 | @property(nonatomic, readonly) FourCharCode inputPixelFormat; // One of 420f, 420v, or BGRA
62 |
63 | /* Resource Lifecycle */
64 | // Prepare and destroy expensive resources inside these callbacks.
65 | // The outputRetainedBufferCountHint tells out of place renderers how many of their output buffers will be held onto by the downstream pipeline at one time.
66 | // This can be used by the renderer to size and preallocate their pools.
67 | - (void)prepareForInputWithFormatDescription:(CMFormatDescriptionRef)inputFormatDescription
68 | outputRetainedBufferCountHint:(size_t)outputRetainedBufferCountHint;
69 |
70 | - (void)reset;
71 |
72 | /* Rendering */
73 | // Renderers which operate in place should return the input pixel buffer with a +1 retain count.
74 | // Renderers which operate out of place should create a pixel buffer to return from a pool they own.
75 | // When rendering to a pixel buffer with the GPU it is not necessary to block until rendering has completed before returning.
76 | // It is sufficient to call glFlush() to ensure that the commands have been flushed to the GPU.
77 | //- (CVPixelBufferRef )copyRenderedPixelBuffer:(CMSampleBufferRef)sampleBufferRef faceModelArray:(MGFaceModelArray *)modelArray drawLandmark:(BOOL)drawLandmark;
78 |
79 | @property(nonatomic, assign) BOOL show3DView;
80 |
81 | // This property must be implemented if operatesInPlace is NO and the output pixel buffers have a different format description than the input.
82 | // If implemented a non-NULL value must be returned once the renderer has been prepared (can be NULL after being reset).
83 | @property(nonatomic, readonly) CMFormatDescriptionRef __attribute__((NSObject)) outputFormatDescription;
84 |
85 | - (void)setUpOutSampleBuffer:(CGSize)outSize devicePosition:(AVCaptureDevicePosition)devicePosition;
86 |
87 |
88 | - (CVPixelBufferRef )drawPixelBuffer:(CMSampleBufferRef)sampleBufferRef custumDrawing:(void (^)(void))draw;
89 |
90 | - (void)drawFaceLandMark:(MGFaceModelArray *)faces;
91 |
92 | - (void)drawRect:(CGRect)rect;
93 |
94 | - (void)drawFaceWithRect:(CGRect)rect;
95 |
96 | @end
97 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/Shaders/Face3DFragment.glsl:
--------------------------------------------------------------------------------
1 | precision mediump float;
2 |
3 | uniform highp float color_selector;
4 |
5 | void main()
6 | {
7 | if (color_selector == 1.0) {
8 | gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
9 | } else if (color_selector == 2.0) {
10 | gl_FragColor = vec4(0.0, 1.0, 0.0, 1.0);
11 | } else if (color_selector == 3.0) {
12 | gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);
13 | } else
14 | gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
15 | }
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/Shaders/Face3DVertex.glsl:
--------------------------------------------------------------------------------
1 | uniform mat4 projection;
2 | uniform mat4 modelView;
3 | attribute vec4 vPosition;
4 |
5 | void main(void)
6 | {
7 | gl_Position = vPosition;
8 | }
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/Shaders/FacePointColor.glsl:
--------------------------------------------------------------------------------
1 | precision mediump float;
2 |
3 | void main()
4 | {
5 | gl_FragColor = vec4(0.2, 0.709803922, 0.898039216, 1.0);
6 | }
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/Shaders/FacePointSize.glsl:
--------------------------------------------------------------------------------
1 | attribute vec4 vPosition;
2 |
3 | uniform float sizeScale;
4 |
5 | void main(void)
6 | {
7 | gl_Position = vPosition;
8 | gl_PointSize = 5.0 * sizeScale;
9 | }
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/Shaders/VideoFrag.glsl:
--------------------------------------------------------------------------------
1 |
2 | precision mediump float;
3 |
4 | varying mediump vec2 coordinate;
5 | uniform sampler2D videoframe;
6 |
7 | void main()
8 | {
9 | vec4 color = texture2D(videoframe, coordinate);
10 | gl_FragColor.bgra = vec4(color.b, color.g, color.r, color.a);
11 | }
12 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/Shaders/VideoVert.glsl:
--------------------------------------------------------------------------------
1 |
2 | attribute vec4 position;
3 | attribute mediump vec4 texturecoordinate;
4 | varying mediump vec2 coordinate;
5 |
6 | void main()
7 | {
8 | gl_Position = position;
9 | coordinate = texturecoordinate.xy;
10 | }
11 |
12 |
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/1280_720.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/1280_720.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/1280_720@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/1280_720@3x.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/1920_1080.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/1920_1080.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/1920_1080@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/1920_1080@3x.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/3D-0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/3D-0.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/3D-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/3D-1.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/640_480.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/640_480.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/640_480@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/640_480@3x.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/81-0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/81-0.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/81-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/81-1.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/960_540.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/960_540.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/960_540@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/960_540@3x.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/IMG_2393.JPG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/IMG_2393.JPG
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/area-0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/area-0.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/area-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/area-1.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/card_front.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/card_front.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/compare/faceCompare-0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/compare/faceCompare-0.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/compare/faceCompare-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/compare/faceCompare-1.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/compare/regist.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/compare/regist.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/compare/selected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/compare/selected.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/compare/unSelected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/compare/unSelected.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/compare/user.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/compare/user.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/debug-0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/debug-0.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/debug-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/debug-1.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/faceLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/faceLogo.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/faceinfo-0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/faceinfo-0.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/faceinfo-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/faceinfo-1.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/megviicloud logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/megviicloud logo.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/pw.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/pw.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/record-0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/record-0.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/record-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/record-1.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/screen-0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/screen-0.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/screen-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/screen-1.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/shader-0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/shader-0.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/shader-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/shader-1.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/side-0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/side-0.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/side-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/side-1.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/textrec-0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/textrec-0.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/appImages/textrec-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/appImages/textrec-1.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/detectImages/81_points_position.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/detectImages/81_points_position.jpg
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/detectImages/background.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/detectImages/background.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/detectImages/skin.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/detectImages/skin.png
--------------------------------------------------------------------------------
/FaceppDemo/FaceppDemo/Resources/detectImages/standard_alpha.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/FaceppDemo/Resources/detectImages/standard_alpha.png
--------------------------------------------------------------------------------
/FaceppDemo/MGBaseKit/MGAnimation.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGAnimation.h
3 | // MGBankCard
4 | //
5 | // Created by 张英堂 on 15/12/11.
6 | // Copyright © 2015年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @interface MGAnimation : NSObject
13 |
14 | /**
15 | * 一闪一闪的动画
16 | *
17 | * @return 动画
18 | */
19 | + (CABasicAnimation *)animationWithOpacity;
20 |
21 |
22 | @end
23 |
--------------------------------------------------------------------------------
/FaceppDemo/MGBaseKit/MGAnimation.m:
--------------------------------------------------------------------------------
1 | //
2 | // MGAnimation.m
3 | // MGBankCard
4 | //
5 | // Created by 张英堂 on 15/12/11.
6 | // Copyright © 2015年 megvii. All rights reserved.
7 | //
8 |
9 | #import "MGAnimation.h"
10 |
11 | #define KOpacityKey @"opacity"
12 |
13 | @implementation MGAnimation
14 |
15 | + (CABasicAnimation *)animationWithOpacity{
16 | CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:KOpacityKey];
17 | animation.fromValue = [NSNumber numberWithFloat:1.0f];
18 | animation.toValue = [NSNumber numberWithFloat:0.01f];
19 | animation.autoreverses = NO;
20 | animation.duration = 0.5f;
21 | animation.repeatCount = MAXFLOAT;
22 | animation.removedOnCompletion = NO;
23 | animation.fillMode = kCAFillModeForwards;
24 |
25 | return animation;
26 | }
27 |
28 | @end
29 |
--------------------------------------------------------------------------------
/FaceppDemo/MGBaseKit/MGAutoSessionPreset.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGAutoSessionPreset.h
3 | // MGBaseKit
4 | //
5 | // Created by 张英堂 on 16/8/2.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface MGAutoSessionPreset : NSObject
12 |
13 | /**
14 | * 获取与屏幕尺寸比例相同的视频流
15 | *
16 | * @return SessionPreset
17 | */
18 | + (NSString *)autoSessionPreset;
19 |
20 |
21 | + (CGSize)autoSessionPresetSize;
22 |
23 |
24 | @end
25 |
--------------------------------------------------------------------------------
/FaceppDemo/MGBaseKit/MGAutoSessionPreset.m:
--------------------------------------------------------------------------------
1 | //
2 | // MGAutoSessionPreset.m
3 | // MGBaseKit
4 | //
5 | // Created by 张英堂 on 16/8/2.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import "MGAutoSessionPreset.h"
10 | #import "MGBaseDefine.h"
11 | #import
12 |
13 |
14 |
15 | @implementation MGAutoSessionPreset
16 |
17 |
18 | + (NSString *)autoSessionPreset{
19 |
20 | NSString *tempSessionPreset;
21 |
22 | if (MG_WIN_WIDTH == 320 && MG_WIN_HEIGHT == 480) {
23 | tempSessionPreset = AVCaptureSessionPreset640x480;
24 | }else{
25 | tempSessionPreset = AVCaptureSessionPresetiFrame1280x720;
26 | }
27 |
28 | return tempSessionPreset;
29 | }
30 |
31 | + (CGSize)autoSessionPresetSize{
32 | CGSize returnSize;
33 |
34 | if (MG_WIN_WIDTH == 320 && MG_WIN_HEIGHT == 480) {
35 | returnSize = CGSizeMake(640, 480);
36 | }else{
37 | returnSize = CGSizeMake(1280, 720);
38 | }
39 |
40 | return returnSize;
41 | }
42 |
43 |
44 |
45 |
46 | @end
47 |
--------------------------------------------------------------------------------
/FaceppDemo/MGBaseKit/MGBaseDefine.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGBaseDefine.h
3 | // MGBaseAPI
4 | //
5 | // Created by 张英堂 on 15/12/21.
6 | // Copyright © 2015年 megvii. All rights reserved.
7 | //
8 |
9 | #ifndef MGBaseDefine_h
10 | #define MGBaseDefine_h
11 |
12 | #import
13 | #import
14 |
15 |
16 | /* 屏幕宽度 (区别于viewcontroller.view.fream)*/
17 | #define MG_WIN_WIDTH [UIScreen mainScreen].bounds.size.width
18 |
19 | /* 屏幕高度 (区别于viewcontroller.view.fream)*/
20 | #define MG_WIN_HEIGHT [UIScreen mainScreen].bounds.size.height
21 |
22 | /* 手机系统版本 */
23 | #define MG_IOS_SysVersion [[UIDevice currentDevice] systemVersion].floatValue
24 |
25 | /* rgb颜色转换(16进制->10进制)*/
26 | #define MGColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
27 |
28 | /* rgba颜色 */
29 | #define MGColorWithRGB(R, G, B, A) [UIColor colorWithRed:R/255.0f green:G/255.0f blue:B/255.0f alpha:A]
30 |
31 |
32 | #ifdef DEBUG
33 | #define MGLog(...) NSLog(__VA_ARGS__)
34 | #else
35 | #define MGLog(...)
36 | #endif
37 |
38 | typedef void(^VoidBlock)();
39 | typedef void(^VoidErrorBlock)(NSError *error);
40 | typedef void(^videoOutputBlock)(AVCaptureOutput *captureOutput,
41 | CMSampleBufferRef sampleBuffer,
42 | AVCaptureConnection *connection);
43 |
44 |
45 |
46 |
47 | #endif /* MGBaseDefine_h */
48 |
--------------------------------------------------------------------------------
/FaceppDemo/MGBaseKit/MGBaseKit.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGBaseAPI.h
3 | // MGBaseAPI
4 | //
5 | // Created by 张英堂 on 15/12/24.
6 | // Copyright © 2015年 megvii. All rights reserved.
7 | //
8 |
9 | #ifndef MGBaseAPI_h
10 | #define MGBaseAPI_h
11 |
12 |
13 | #import
14 | #import
15 | #import
16 |
17 | #import
18 | #import
19 |
20 | #import
21 | #import
22 |
23 |
24 | #import
25 | #import
26 |
27 |
28 | #endif /* MGBaseAPI_h */
29 |
--------------------------------------------------------------------------------
/FaceppDemo/MGBaseKit/MGBaseKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/FaceppDemo/MGBaseKit/MGBaseKit/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 2.5.2
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | $(CURRENT_PROJECT_VERSION)
23 | NSPrincipalClass
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/FaceppDemo/MGBaseKit/MGImage.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGImage.h
3 | // MGBankCard
4 | //
5 | // Created by 张英堂 on 15/12/11.
6 | // Copyright © 2015年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 | #import
12 | #import
13 |
14 | @interface MGImage : NSObject
15 |
16 | /**
17 | * 裁剪图片
18 | *
19 | * @param image 原始图片
20 | * @param bounds 裁剪的区域
21 | *
22 | * @return 裁剪后的图片
23 | */
24 | + (UIImage*)croppedImage:(UIImage *)image
25 | rect:(CGRect)bounds;
26 |
27 | /**
28 | * 修正图片方向
29 | *
30 | * @param image 原始图片
31 | *
32 | * @return 修正完成的图片
33 | */
34 | + (UIImage*)fixOrientationWithImage:(UIImage *)image;
35 |
36 |
37 | //+ (UIImage*)fixOrientationWithImageOrientation:(UIImage *)image
38 | // orientation:(UIImageOrientation) orientation;
39 |
40 | /**
41 | * 把sampleBuffer转化为图片
42 | *
43 | * @param sampleBuffer sampleBuffer
44 | * @param orientation 图片的方向
45 | *
46 | * @return 转化完成的图片
47 | */
48 | + (UIImage*)imageFromSampleBuffer:(CMSampleBufferRef)sampleBuffer
49 | orientation:(UIImageOrientation) orientation;
50 |
51 |
52 | //+ (UIImage*)fixOrientationFromSampleBuffer:(CMSampleBufferRef)sampleBuffer
53 | // orientation:(UIImageOrientation)orientation;
54 |
55 |
56 |
57 | /*视频角度转化为数值*/
58 | + (CGFloat)angleOffsetFromPortraitOrientationToOrientation:(AVCaptureVideoOrientation)orientation;
59 |
60 |
61 |
62 | @end
63 |
64 |
65 |
--------------------------------------------------------------------------------
/FaceppDemo/MGBaseKit/MGLogManager.h:
--------------------------------------------------------------------------------
1 | //
2 | // YTLogManager.h
3 | // BankCardTest
4 | //
5 | // Created by 张英堂 on 15/12/9.
6 | // Copyright © 2015年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 |
12 |
13 | @interface MGLogManager : NSObject
14 |
15 | /**
16 | * 单例
17 | *
18 | * @return 返回实例化对象
19 | */
20 | + (instancetype)sharedInstance;
21 |
22 |
23 |
24 | /**
25 | * 添加一条Log (子线程中进行文件读写处理)
26 | *
27 | * @param logString log内容
28 | * @param fileName 要写入的文件名
29 | */
30 | - (void)addLog:(NSString *)logString fileName:(NSString *)fileName;
31 |
32 |
33 | @end
34 |
--------------------------------------------------------------------------------
/FaceppDemo/MGBaseKit/MGLogManager.mm:
--------------------------------------------------------------------------------
1 | //
2 | // YTLogManager.m
3 | // BankCardTest
4 | //
5 | // Created by 张英堂 on 15/12/9.
6 | // Copyright © 2015年 megvii. All rights reserved.
7 | //
8 |
9 | #import "MGLogManager.h"
10 | #import "MGBaseDefine.h"
11 |
12 | static NSString *const YTLogfolderName = @"com.megvii.log";
13 |
14 | @interface MGLogManager ()
15 |
16 | @property (nonatomic, strong) NSString *logBasePath;
17 | @property (nonatomic, strong) NSFileManager *fileManager;
18 |
19 | @end
20 |
21 |
22 | @implementation MGLogManager
23 |
24 | +(instancetype)sharedInstance{
25 | static MGLogManager *logManager;
26 | static dispatch_once_t onceToken;
27 | dispatch_once(&onceToken, ^{
28 | logManager = [[MGLogManager alloc] init];
29 | });
30 | return logManager;
31 | }
32 |
33 | - (instancetype)init{
34 | self = [super init];
35 | if (self) {
36 | // NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
37 | // NSString *path = [paths objectAtIndex:0];
38 | self.logBasePath = [NSTemporaryDirectory() stringByAppendingPathComponent:YTLogfolderName];
39 | self.fileManager = [NSFileManager defaultManager];
40 |
41 | BOOL isDir = NO;
42 | BOOL existed = [self.fileManager fileExistsAtPath:self.logBasePath isDirectory:&isDir];
43 | if ( !(isDir == YES && existed == YES) )
44 | {
45 | [self.fileManager createDirectoryAtPath:self.logBasePath
46 | withIntermediateDirectories:YES
47 | attributes:nil
48 | error:nil];
49 | }
50 |
51 | }
52 | return self;
53 | }
54 |
55 | - (void)addLog:(NSString *)logString fileName:(NSString *)fileName{
56 |
57 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
58 | NSString *path = [self.logBasePath stringByAppendingPathComponent:fileName];
59 |
60 | NSFileHandle *outFile = [NSFileHandle fileHandleForWritingAtPath:path];
61 | if(outFile == nil)
62 | {
63 | MGLog(@"****目标文件不存在,重新创建\n");
64 | NSError *error;
65 | [logString writeToFile:path atomically:YES encoding:NSUTF8StringEncoding error:&error];
66 | if (error) {
67 | MGLog(@"%@: 写入失败%@", NSStringFromClass([self class]), error);
68 | }else {
69 | MGLog(@"%@: 写入成功", NSStringFromClass([self class]));
70 | }
71 | }else{
72 | [outFile seekToEndOfFile];
73 |
74 | NSData *writeBuffer = [logString dataUsingEncoding:NSUTF8StringEncoding];
75 | [outFile writeData:writeBuffer];
76 |
77 | [outFile closeFile];
78 | }
79 | });
80 | }
81 |
82 | @end
83 |
--------------------------------------------------------------------------------
/FaceppDemo/MGBaseKit/MGMovieRecorder.h:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | File: MovieRecorder.h
4 | Abstract: Real-time movie recorder which is totally non-blocking
5 | Version: 2.1
6 |
7 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple
8 | Inc. ("Apple") in consideration of your agreement to the following
9 | terms, and your use, installation, modification or redistribution of
10 | this Apple software constitutes acceptance of these terms. If you do
11 | not agree with these terms, please do not use, install, modify or
12 | redistribute this Apple software.
13 |
14 | In consideration of your agreement to abide by the following terms, and
15 | subject to these terms, Apple grants you a personal, non-exclusive
16 | license, under Apple's copyrights in this original Apple software (the
17 | "Apple Software"), to use, reproduce, modify and redistribute the Apple
18 | Software, with or without modifications, in source and/or binary forms;
19 | provided that if you redistribute the Apple Software in its entirety and
20 | without modifications, you must retain this notice and the following
21 | text and disclaimers in all such redistributions of the Apple Software.
22 | Neither the name, trademarks, service marks or logos of Apple Inc. may
23 | be used to endorse or promote products derived from the Apple Software
24 | without specific prior written permission from Apple. Except as
25 | expressly stated in this notice, no other rights or licenses, express or
26 | implied, are granted by Apple herein, including but not limited to any
27 | patent rights that may be infringed by your derivative works or by other
28 | works in which the Apple Software may be incorporated.
29 |
30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE
31 | MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
32 | THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
33 | FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
34 | OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
35 |
36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
37 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39 | INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
40 | MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
41 | AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
42 | STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
43 | POSSIBILITY OF SUCH DAMAGE.
44 |
45 | Copyright (C) 2014 Apple Inc. All Rights Reserved.
46 |
47 | */
48 |
49 |
50 | #import
51 | #import
52 | #import
53 |
54 |
55 | typedef NS_ENUM( NSInteger, MovieRecorderStatus ) {
56 | MovieRecorderStatusIdle = 0,
57 | MovieRecorderStatusPreparingToRecord,
58 | MovieRecorderStatusRecording,
59 | MovieRecorderStatusFinishingRecordingPart1, // waiting for inflight buffers to be appended
60 | MovieRecorderStatusFinishingRecordingPart2, // calling finish writing on the asset writer
61 | MovieRecorderStatusFinished, // terminal state
62 | MovieRecorderStatusFailed // terminal state
63 | }; // internal state machine
64 |
65 |
66 | @protocol MovieRecorderDelegate;
67 |
68 | @interface MGMovieRecorder : NSObject
69 |
70 | /**
71 | * 录像器 当前状态
72 | */
73 | @property (nonatomic, assign, readonly) MovieRecorderStatus status;
74 |
75 | /**
76 | * log 开关,默认开启
77 | */
78 | @property (nonatomic, assign) BOOL recorderLog;
79 |
80 | + (instancetype)movieRecorderWithSaveURL:(NSURL *)URL;
81 |
82 | - (instancetype)initWithURL:(NSURL *)URL;
83 |
84 | - (void)setDelegate:(id)delegate
85 | callbackQueue:(dispatch_queue_t)delegateCallbackQueue; // delegate is weak referenced
86 |
87 |
88 | // Only one audio and video track each are allowed.
89 | - (void)addVideoTrackWithSourceFormatDescription:(CMFormatDescriptionRef)formatDescription
90 | transform:(CGAffineTransform)transform
91 | settings:(NSDictionary *)videoSettings; // see AVVideoSettings.h for settings keys/values
92 |
93 |
94 | - (void)addAudioTrackWithSourceFormatDescription:(CMFormatDescriptionRef)formatDescription
95 | settings:(NSDictionary *)audioSettings; // see AVAudioSettings.h for settings keys/values
96 |
97 |
98 | - (void)prepareToRecord; // Asynchronous, might take several hundred milliseconds. When finished the delegate's recorderDidFinishPreparing: or recorder:didFailWithError: method will be called.
99 | - (void)finishRecording; // Asynchronous, might take several hundred milliseconds. When finished the delegate's recorderDidFinishRecording: or recorder:didFailWithError: method will be called.
100 |
101 | - (void)appendVideoSampleBuffer:(CMSampleBufferRef)sampleBuffer;
102 |
103 | - (void)appendVideoPixelBuffer:(CVPixelBufferRef)pixelBuffer
104 | withPresentationTime:(CMTime)presentationTime;
105 |
106 | - (void)appendAudioSampleBuffer:(CMSampleBufferRef)sampleBuffer;
107 |
108 |
109 | @end
110 |
111 |
112 |
113 | @protocol MovieRecorderDelegate
114 |
115 | @required
116 | - (void)movieRecorderDidFinishPreparing:(MGMovieRecorder *)recorder;
117 | - (void)movieRecorder:(MGMovieRecorder *)recorder didFailWithError:(NSError *)error;
118 | - (void)movieRecorderDidFinishRecording:(MGMovieRecorder *)recorder;
119 |
120 | @end
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/FaceppDemo/MGBaseKit/MGVideoManager.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGVideoManager.h
3 | // MGLivenessDetection
4 | //
5 | // Created by 张英堂 on 16/3/31.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "MGImage.h"
11 | #import "MGBaseDefine.h"
12 |
13 | @protocol MGVideoDelegate;
14 |
15 | @interface MGVideoManager : NSObject
16 |
17 |
18 | @property (nonatomic, assign) id videoDelegate;
19 |
20 | - (dispatch_queue_t)getVideoQueue;
21 |
22 | /**
23 | * 初始化方法
24 | *
25 | * @param sessionPreset 相机分辨率 如果设置为空,则默认为 AVCaptureSessionPreset640x480
26 | * @param devicePosition 前置或者后置相机,则默认为 前置相机
27 | * @param record 是否录像
28 | * @param sound 是否录音,必须在录像模式下设置 yes 才有用
29 | * @return 实例化对象
30 | */
31 | + (instancetype)videoPreset:(NSString *)sessionPreset
32 | devicePosition:(AVCaptureDevicePosition)devicePosition
33 | videoRecord:(BOOL)record
34 | videoSound:(BOOL)sound;
35 |
36 | @property (nonatomic, strong, readonly) AVCaptureSession *videoSession;
37 | @property (nonatomic, strong, readonly) AVCaptureDeviceInput *videoInput;
38 | @property (nonatomic, assign, readonly) AVCaptureDevicePosition devicePosition;
39 |
40 |
41 | ///**
42 | // * 视频流的最大帧率
43 | // */
44 | //@property (nonatomic, assign) int maxFrame;
45 |
46 |
47 | /**
48 | * 视频流的预览layer 默认全屏大小
49 | * @return 实例化对象
50 | */
51 | -(AVCaptureVideoPreviewLayer *)videoPreview;
52 |
53 | /**
54 | * 视频流的方向
55 | */
56 | @property(nonatomic, assign) AVCaptureVideoOrientation videoOrientation;
57 |
58 | /**
59 | * 开启视频流
60 | */
61 | - (void)startRunning;
62 |
63 | /**
64 | * 关闭视频流
65 | */
66 | - (void)stopRunning;
67 |
68 | /**
69 | * 开始录像
70 | */
71 | - (void)startRecording;
72 |
73 | /**
74 | * 关闭录像
75 | *
76 | * @return 录像存放地址
77 | */
78 | - (NSString *)stopRceording;
79 |
80 |
81 | - (CMFormatDescriptionRef)formatDescription;
82 |
83 | /** only valid after startRunning has been called */
84 | - (CGAffineTransform)transformFromVideoBufferOrientationToOrientation:(AVCaptureVideoOrientation)orientation
85 | withAutoMirroring:(BOOL)mirroring;
86 |
87 |
88 |
89 | @end
90 |
91 |
92 | @protocol MGVideoDelegate
93 |
94 | @required
95 | - (void)MGCaptureOutput:(AVCaptureOutput *)captureOutput
96 | didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
97 | fromConnection:(AVCaptureConnection *)connection;
98 |
99 | - (void)MGCaptureOutput:(AVCaptureOutput *)captureOutput error:(NSError *)error;
100 |
101 |
102 |
103 | @end
104 |
105 |
--------------------------------------------------------------------------------
/FaceppDemo/MGBaseKit/MegviiLicMgr-iOS-SDK/MGLicenseCommon.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGLicenseCommon.h
3 | // MGMobileSDKAuth
4 | //
5 | // Created by 张英堂 on 2017/1/10.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #ifndef MGLicenseCommon_h
10 | #define MGLicenseCommon_h
11 |
12 | typedef NS_ENUM(NSInteger, MGAPIDuration) {
13 | MGAPIDurationDay = 1,
14 | MGAPIDurationMonth = 30,
15 | MGAPIDurationYear = 365,
16 | };
17 |
18 | typedef NS_ENUM(NSInteger, MGSDKType) {
19 | MGSDKTypeLandmark = 1,
20 | MGSDKTypeIDCard = 2,
21 | };
22 |
23 | static NSString *MGLicenseURL_CN = @"https://api-cn.faceplusplus.com/sdk/v2/auth";
24 | static NSString *MGLicenseURL_US = @"https://api-us.faceplusplus.com/sdk/v2/auth";
25 |
26 |
27 | #define MG_LICENSE_DEBUG 1
28 | #if MG_LICENSE_DEBUG
29 | #define MG_LICENSE_LOG(FORMAT, ...) fprintf(stderr,"%s:%d \t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
30 | #else
31 | #define NSLog(FORMAT, ...) nil
32 | #endif
33 |
34 |
35 |
36 | #endif /* MGLicenseCommon_h */
37 |
--------------------------------------------------------------------------------
/FaceppDemo/MGBaseKit/MegviiLicMgr-iOS-SDK/MGLicenseManager.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGLicenseManager.h
3 | // MGBaseKit
4 | //
5 | // Created by 张英堂 on 16/9/5.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "MGLicenseCommon.h"
11 |
12 | @interface MGLicenseManager : NSObject
13 |
14 |
15 | /**
16 | 获取过期时间
17 |
18 | @param version SDK 版本号
19 | @return 过期日期
20 | */
21 | + (NSDate *)getExpiretime:(NSString *)version;
22 |
23 |
24 |
25 | #pragma mark - 简单调用联网授权
26 |
27 | /**
28 | 联网获取授权信息
29 |
30 | @param UUID UUID
31 | @param APIName API name
32 | @param sdkType SDK 类型
33 | @param apiKey apiKey
34 | @param apiSecret apiSecret
35 | @param duration appKey有效期类型
36 | @param url
37 | @param complete 授权结束回调
38 | @return SessionTask
39 | */
40 | + (NSURLSessionTask *)takeLicenseFromNetwokrUUID:(NSString *)UUID
41 | version:(NSString *)version
42 | sdkType:(MGSDKType)sdkType
43 | apiKey:(NSString *)apiKey
44 | apiSecret:(NSString *)apiSecret
45 | apiDuration:(MGAPIDuration)duration
46 | URLString:(NSString *)url
47 | finish:(void(^)(bool License, NSError *error))complete;
48 |
49 |
50 |
51 | @end
52 |
--------------------------------------------------------------------------------
/FaceppDemo/MGBaseKit/MegviiLicMgr-iOS-SDK/libMGLicMgrSDK-0.3.0.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/FaceppDemo/MGBaseKit/MegviiLicMgr-iOS-SDK/libMGLicMgrSDK-0.3.0.a
--------------------------------------------------------------------------------
/MGFacepp.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/MGFacepp/MGFacepp.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/MGFacepp/MGFacepp/MGAlgorithmInfo.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGAlgorithmInfo.h
3 | // MGFacepp
4 | //
5 | // Created by 张英堂 on 2017/1/10.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | #define MG_ABILITY_KEY_POSE3D @"pose3D"
13 | #define MG_ABILITY_KEY_EYE_STATUS @"eyeStatus"
14 | #define MG_ABILITY_KEY_MOUTH_SATUS @"mouthStatus"
15 | #define MG_ABILITY_KEY_MINORITY @"minority"
16 | #define MG_ABILITY_KEY_BLURNESS @"blurness"
17 | #define MG_ABILITY_KEY_AGE_GENDER @"ageGender"
18 | #define MG_ABILITY_KEY_EXTRACT_FEATURE @"extractFeature"
19 | #define MG_ABILITY_KEY_TRACK_FAST @"trackFast"
20 | #define MG_ABILITY_KEY_TRACK_ROBUST @"trackRobust"
21 | #define MG_ABILITY_KEY_DETECT @"detect"
22 | #define MG_ABILITY_KEY_DETECT_RECT @"detectRect"
23 | #define MG_ABILITY_KEY_IDCARD_QUALITY @"IDCardQuality"
24 | #define MG_ABILITY_KEY_TRACK @"track"
25 | #define MG_ABILITY_KEY_TRACK_RECT @"track_rect"
26 |
27 |
28 | @interface MGAlgorithmInfo : NSObject
29 |
30 |
31 | /**
32 | SDK 版本号
33 | */
34 | @property (nonatomic, copy, readonly) NSString *version;
35 |
36 | /**
37 | SDK 过期时间
38 | */
39 | @property (nonatomic, strong, readonly) NSDate *expireDate;
40 |
41 |
42 | /**
43 | 是否需要联网授权
44 | */
45 | @property (nonatomic, assign, readonly) BOOL needNetLicense;
46 |
47 |
48 | /**
49 | SDK 功能列表
50 | */
51 | @property (nonatomic, strong, readonly) NSArray *SDKAbility;
52 |
53 |
54 | /**
55 | SDK 限制的bundleId
56 | */
57 | @property (nonatomic, strong, readonly) NSString *bundleId;
58 |
59 |
60 | @end
61 |
--------------------------------------------------------------------------------
/MGFacepp/MGFacepp/MGAlgorithmInfo.m:
--------------------------------------------------------------------------------
1 | //
2 | // MGAlgorithmInfo.m
3 | // MGFacepp
4 | //
5 | // Created by 张英堂 on 2017/1/10.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import "MGAlgorithmInfo.h"
10 | #import "MG_Facepp.h"
11 | #import "MGFaceppCommon.h"
12 |
13 | typedef NS_OPTIONS(NSInteger, MGFaceppAbilityType) {
14 | MGFaceppAbilityTypePose3D = 1U<<0,
15 | MGFaceppAbilityTypeEyeStatus = 1U<<1,
16 | MGFaceppAbilityTypeMouthStatus = 1U<<2,
17 | MGFaceppAbilityTypeMinority = 1U<<3,
18 | MGFaceppAbilityTypeBlurness = 1U<<4,
19 | MGFaceppAbilityTypeAgeGender = 1U<<5,
20 | MGFaceppAbilityTypeExtractFeature = 1U<<6,
21 | MGFaceppAbilityTypeTrackFast = 1U<<7,
22 | MGFaceppAbilityTypeTrackRobust = 1U<<8,
23 | MGFaceppAbilityTypeDetectRect = 1U<<9,
24 | MGFaceppAbilityTypeDetect = 1U<<12,
25 | MGFaceppAbilityTypeIDCardQuality = 1U<<13,
26 | MGFaceppAbilityTypeTrack = 1U<<14,
27 | };
28 |
29 | @implementation MGAlgorithmInfo
30 |
31 | - (void)setAbility:(uint64_t )ability {
32 |
33 | NSDictionary *abilityName = @{@(1U<<0) : MG_ABILITY_KEY_POSE3D,
34 | @(1U<<1) : MG_ABILITY_KEY_EYE_STATUS,
35 | @(1U<<2) : MG_ABILITY_KEY_MOUTH_SATUS,
36 | @(1U<<3) : MG_ABILITY_KEY_MINORITY,
37 | @(1U<<4) : MG_ABILITY_KEY_BLURNESS,
38 | @(1U<<5) : MG_ABILITY_KEY_AGE_GENDER,
39 | @(1U<<6) : MG_ABILITY_KEY_EXTRACT_FEATURE,
40 | @(1U<<7) : MG_ABILITY_KEY_TRACK_FAST,
41 | @(1U<<8) : MG_ABILITY_KEY_TRACK_ROBUST,
42 | @(1U<<9) : MG_ABILITY_KEY_DETECT_RECT,
43 | // 10
44 | // 11
45 | @(1U<<12) : MG_ABILITY_KEY_DETECT,
46 | @(1U<<13) : MG_ABILITY_KEY_IDCARD_QUALITY,
47 | @(1U<<14) : MG_ABILITY_KEY_TRACK,
48 | @(1U<<15) : MG_ABILITY_KEY_TRACK_RECT,
49 | };
50 |
51 | NSMutableArray *names = [NSMutableArray array];
52 | for (int i = 0; i < 16; i++) {
53 | if (i==10 || i==11) {
54 | continue;
55 | }
56 | if (ability & 1<
10 | #import
11 |
12 | typedef NS_ENUM(NSInteger, MGOrientation) {
13 | MGOrientationLeft,
14 | MGOrientationUp,
15 | MGOrientationRight,
16 | MGOrientationDown,
17 | };
18 |
19 | @interface MGDetectRectInfo : NSObject
20 |
21 | @property (nonatomic, assign) float confidence;
22 |
23 | @property (nonatomic, assign) float angle;
24 |
25 | @property (nonatomic, assign) MGOrientation orient;
26 |
27 | @property (nonatomic, assign) CGRect rect;
28 |
29 | @end
30 |
31 |
--------------------------------------------------------------------------------
/MGFacepp/MGFacepp/MGDetectRectInfo.m:
--------------------------------------------------------------------------------
1 | //
2 | // MGDetectRect.m
3 | // MGFacepp
4 | //
5 | // Created by Megvii on 2017/10/18.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import "MGDetectRectInfo.h"
10 |
11 | @implementation MGDetectRectInfo
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/MGFacepp/MGFacepp/MGFaceInfo.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGFaceModel.h
3 | // LandMask
4 | //
5 | // Created by 张英堂 on 16/7/11.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 | #import "MGFaceppCommon.h"
12 |
13 | typedef NS_ENUM(NSInteger, MGGender) {
14 | MGFemale = 0,
15 | MGMale = 1,
16 | };
17 |
18 | @interface MGFaceInfo : NSObject
19 |
20 | /** tracking ID */
21 | @property (nonatomic, assign) NSInteger trackID;
22 |
23 | /** 在该张图片中人脸序号 */
24 | @property (nonatomic, assign) int index;
25 |
26 | /** 人脸的rect */
27 | @property (nonatomic, assign) CGRect rect;
28 |
29 | /** 人脸点坐标 (NSValue -> CGPoints)*/
30 | @property (nonatomic, strong) NSArray *points;
31 |
32 | /** 该张人脸质量 */
33 | @property (nonatomic, assign) CGFloat confidence;
34 |
35 |
36 | #pragma mark 以下属性需要SDK版本支持 请使用 [MGAlgorithmInfo SDKAbility] 属性,获取SDK支持功能
37 |
38 | #pragma mark 需要主动调用 MGFacepp 相关方法获取
39 | //3D info
40 | @property (nonatomic, assign) float pitch;
41 | @property (nonatomic, assign) float yaw;
42 | @property (nonatomic, assign) float roll;
43 |
44 | /** 年龄 */
45 | @property (nonatomic, assign) float age;
46 | /** 性别 */
47 | @property (nonatomic, assign) MGGender gender;
48 | /** blurness */
49 | @property (nonatomic, assign) float blurness;
50 | /** minority */
51 | @property (nonatomic, assign) float minority;
52 |
53 | /** 眼状态 */
54 | @property (nonatomic, assign) MGEyeStatus leftEyesStatus;
55 | @property (nonatomic, assign) MGEyeStatus rightEyesStatus;
56 |
57 | /** 嘴状态 */
58 | @property (nonatomic, assign) MGMouthStatus mouseStatus;
59 |
60 |
61 | #pragma mark -
62 |
63 | /**
64 | 人脸的 feature
65 | */
66 | @property (nonatomic, strong, readonly) NSData *featureData;
67 |
68 |
69 |
70 | @end
71 |
--------------------------------------------------------------------------------
/MGFacepp/MGFacepp/MGFaceInfo.m:
--------------------------------------------------------------------------------
1 | //
2 | // MGFaceModel.m
3 | // LandMask
4 | //
5 | // Created by 张英堂 on 16/7/11.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import "MGFaceInfo.h"
10 | #import "MG_Common.h"
11 | #import "MG_Facepp.h"
12 |
13 | @implementation MGFaceInfo
14 |
15 | -(void)dealloc{
16 | _featureData = nil;
17 | _points = nil;
18 | }
19 |
20 | + (instancetype)modelWithPoint:(MG_FACELANDMARKS )points
21 | pointsCount:(NSInteger)count
22 | mgFaceInfo:(MG_RECTANGLE)faceinfo
23 | confidence:(CGFloat)confidence{
24 |
25 | MGFaceInfo *model = [[MGFaceInfo alloc] init];
26 | if (model) {
27 |
28 | CGRect headerRect = CGRectMake(faceinfo.left,
29 | faceinfo.top,
30 | faceinfo.right - faceinfo.left,
31 | faceinfo.bottom - faceinfo.top);
32 | model.rect = headerRect;
33 | model.confidence = confidence;
34 |
35 | NSMutableArray *tempArray = [NSMutableArray array];
36 |
37 | for (int i = 0; i < count; i++){
38 | CGPoint drawPoint = CGPointMake(points.point[i].x, points.point[i].y);
39 | [tempArray addObject:[NSValue valueWithCGPoint:drawPoint]];
40 | }
41 |
42 | model.points = [NSArray arrayWithArray:tempArray];
43 | }
44 | return model;
45 | }
46 |
47 | - (void)resetPoints:(MG_POINT *)points pointsCount:(int)count{
48 | NSMutableArray *tempArray = [NSMutableArray array];
49 |
50 | for (int i = 0; i < count; i++){
51 | CGPoint drawPoint = CGPointMake(points[i].x, points[i].y);
52 |
53 | [tempArray addObject:[NSValue valueWithCGPoint:drawPoint]];
54 | }
55 |
56 | self.points = [NSArray arrayWithArray:tempArray];
57 | }
58 |
59 | - (void)setFace3D:(MG_FACE)face{
60 | self.pitch = face.pose.pitch;
61 | self.yaw = face.pose.yaw;
62 | self.roll = face.pose.roll;
63 | }
64 |
65 | - (void)set_eyes_status:(float *)eyesStatus isLeft:(BOOL)left{
66 |
67 | int maxStatus = MG_EYESTATUS_NOGLASSES_EYEOPEN;
68 | float size = 0;
69 | for (int i = 0; i < MG_EYESTATUS_COUNT; i++) {
70 | float temp = eyesStatus[i];
71 | if (temp >= size) {
72 | maxStatus = i;
73 | size = temp;
74 | }
75 | }
76 | if (YES == left) {
77 | self.leftEyesStatus = (MGEyeStatus)maxStatus;
78 | }else{
79 | self.rightEyesStatus = (MGEyeStatus)maxStatus;
80 | }
81 | }
82 |
83 | - (void)set_mouse_status:(float *)mouseStatus{
84 |
85 | int maxStatus = MG_MOUTHSTATUS_OPEN;
86 | float size = 0;
87 | for (int i = 0; i < MG_MOUTHSTATUS_COUNT; i++) {
88 | float temp = mouseStatus[i];
89 | if (temp >= size) {
90 | maxStatus = i;
91 | size = temp;
92 | }
93 | }
94 | self.mouseStatus = (MGMouthStatus)maxStatus;
95 | }
96 |
97 | - (void)set_age_status:(float)age gender:(MG_GENDER)gender{
98 | self.age = age;
99 |
100 | if (gender.female > gender.male) {
101 | self.gender = 0;
102 | }else{
103 | self.gender = 1;
104 | }
105 | }
106 |
107 | - (void)set_blurness_status:(float)blurness{
108 | self.blurness = blurness;
109 | }
110 |
111 | - (void)set_minority_status:(float)minority{
112 | self.minority = minority;
113 | }
114 |
115 | - (void)set_feature_data:(NSData *)data{
116 | _featureData = data;
117 | }
118 |
119 |
120 | - (void)setProperty:(int64_t)Property MGFACE:(MG_FACE)face{
121 |
122 | switch (Property) {
123 | case MG_FPP_ATTR_POSE3D:
124 | [self setFace3D:face];
125 | break;
126 | case MG_FPP_ATTR_EYESTATUS:
127 | [self set_eyes_status:face.left_eyestatus isLeft:YES];
128 | [self set_eyes_status:face.right_eyestatus isLeft:NO];
129 | break;
130 | case MG_FPP_ATTR_MOUTHSTATUS:
131 | [self set_mouse_status:face.moutstatus];
132 | break;
133 | case MG_FPP_ATTR_MINORITY:
134 | [self set_minority_status:face.minority];
135 | break;
136 | case MG_FPP_ATTR_BLURNESS:
137 | [self set_blurness_status:face.blurness];
138 | break;
139 | case MG_FPP_ATTR_AGE_GENDER:
140 | [self set_age_status:face.age gender:face.gender];
141 | break;
142 | case MG_FPP_ATTR_EXTRACT_FEATURE:
143 | break;
144 | default:
145 | break;
146 | }
147 | }
148 |
149 |
150 |
151 |
152 |
153 | @end
154 |
--------------------------------------------------------------------------------
/MGFacepp/MGFacepp/MGFaceInfo_Creat.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGFaceInfo_Creat.h
3 | // MGLandMark
4 | //
5 | // Created by 张英堂 on 16/9/5.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import "MGFaceInfo.h"
10 | #import "MG_Common.h"
11 | #import "MGFaceppConfig.h"
12 |
13 | @interface MGFaceInfo ()
14 |
15 | + (instancetype)modelWithPoint:(MG_FACELANDMARKS )points
16 | pointsCount:(NSInteger)count
17 | mgFaceInfo:(MG_RECTANGLE)faceinfo
18 | confidence:(CGFloat)confidence;
19 |
20 |
21 |
22 | - (void)resetPoints:(MG_POINT *)points pointsCount:(int)count;
23 |
24 |
25 | - (void)setFace3D:(MG_FACE)face;
26 |
27 | - (void)set_eyes_status:(float *)eyesStatus isLeft:(BOOL)left;
28 | - (void)set_mouse_status:(float *)mouseStatus;
29 |
30 | - (void)set_age_status:(float)age;
31 | - (void)set_blurness_status:(float)blurness;
32 | - (void)set_minority_status:(float)minority;
33 |
34 | - (void)setProperty:(int64_t)Property MGFACE:(MG_FACE)face;
35 |
36 | - (void)set_feature_data:(NSData *)data;
37 |
38 |
39 |
40 | @end
41 |
--------------------------------------------------------------------------------
/MGFacepp/MGFacepp/MGFacepp.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGFacepp.h
3 | // LandMask
4 | //
5 | // Created by 张英堂 on 16/9/5.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | #import "MGFaceppConfig.h"
13 | #import "MGImageData.h"
14 | #import "MGFaceppCommon.h"
15 | #import "MGAlgorithmInfo.h"
16 | #import "MGFaceInfo.h"
17 | #import "MGDetectRectInfo.h"
18 |
19 | @interface MGFacepp : NSObject
20 |
21 | - (MGFaceppConfig *)getFaceppConfig;
22 |
23 | - (instancetype)init DEPRECATED_ATTRIBUTE;
24 |
25 | /**
26 | * 初始化方法 必须使用该方法初始化,否则会导致初始化失败。
27 | *
28 | * @param modelData model data
29 | * @param config 设置的callback
30 | * @return 实例化
31 | */
32 | - (instancetype)initWithModel:(NSData *)modelData
33 | faceppSetting:(void(^)(MGFaceppConfig *config))config;
34 |
35 | /**
36 | 初始化方法
37 |
38 | @param modelData model data
39 | @param maxFaceCount 一张图像中识别的最大人脸数,设置为1即为单脸跟踪
40 | @param config 设置的callback
41 | @return handle
42 | */
43 | - (instancetype)initWithModel:(NSData *)modelData maxFaceCount:(NSInteger)maxFaceCount faceppSetting:(void(^)(MGFaceppConfig *config))config;
44 |
45 | /**
46 | * @param config 更新设置参数
47 | */
48 | - (BOOL)updateFaceppSetting:(void(^)(MGFaceppConfig *config))config;
49 |
50 |
51 | /**
52 | * 获取检测器目前状态
53 | */
54 | @property (nonatomic, assign, readonly) MGFaceppStatus status;
55 |
56 |
57 | #pragma mark - 检测人脸信息
58 | /**
59 | * 检测人脸信息
60 | *
61 | * @param imagedata 检测的图片
62 | * @return 检测结果(如果为 nil 时候,检测器异常,检测失败,请检测代码以及设置)
63 | */
64 | - (NSArray *)detectWithImageData:(MGImageData *)imagedata;
65 |
66 | /**
67 | * 检测人脸框
68 | *
69 | * @param imagedata 检测的图片
70 | * @return 检测结果(如果为 nil 时候,检测器异常,检测失败,请检测代码以及设置)
71 | */
72 | - (NSInteger)getFaceNumberWithImageData:(MGImageData *)imagedata;
73 |
74 |
75 | /**
76 | * 人脸关键点平滑
77 | *
78 | * @param faceInfo faceinfo model
79 | * @param isSmooth 是否关键点平滑,防止人脸抖动
80 | * @param nr 关键点个数
81 | */
82 | - (BOOL)GetGetLandmark:(MGFaceInfo *)faceInfo isSmooth:(BOOL)isSmooth pointsNumber:(int)nr;
83 |
84 | /**
85 | * 获取人脸框
86 | *
87 | *
88 | * @param index faceinfo model
89 | * @param isSmooth 是否关键点平滑,防止人脸抖动
90 | */
91 | - (MGDetectRectInfo *)GetRectAtIndex:(int)index isSmooth:(BOOL)isSmooth;
92 |
93 | /**
94 | * 获取人脸 3D信息
95 | * @param faceInfo faceInfo
96 | * @return 是否获取成功
97 | */
98 | - (BOOL)GetAttribute3D:(MGFaceInfo *)faceInfo;
99 |
100 | /**
101 | * 获取 眼状态
102 | * @param faceInfo faceInfo
103 | * @return 是否获取成功
104 | */
105 | - (BOOL)GetAttributeEyeStatus:(MGFaceInfo *)faceInfo;
106 |
107 | /**
108 | * 获取 嘴状态
109 | * @param faceInfo faceInfo
110 | * @return 是否获取成功
111 | */
112 | - (BOOL)GetAttributeMouseStatus:(MGFaceInfo *)faceInfo;
113 |
114 | /**
115 | * 获取 年龄
116 | * @param faceInfo faceInfo
117 | * @return 是否获取成功
118 | */
119 | - (BOOL)GetAttributeAgeGenderStatus:(MGFaceInfo *)faceInfo;
120 |
121 | /**
122 | 获取 Blurness 状态
123 |
124 | @param faceInfo faceInfo
125 | @return 是否获取成功
126 | */
127 | - (BOOL)GetBlurnessStatus:(MGFaceInfo *)faceInfo;
128 |
129 | /**
130 | 获取 Minorit 状态
131 |
132 | @param faceInfo faceInfo
133 | @return 是否获取成功
134 | */
135 | - (BOOL)GetMinorityStatus:(MGFaceInfo *)faceInfo;
136 |
137 | /**
138 | 获取人脸的 Feature 数据
139 |
140 | @param faceInfo faceinfo
141 | @return 是否获取成功
142 | */
143 | - (BOOL)GetFeatureData:(MGFaceInfo *)faceInfo;
144 |
145 | /**
146 | 比较两个人脸相似度, 必须改 MGFaceInfo 获取过 Feature 数据才有效
147 | 如果成功返回人脸相似度, 如果比对失败,返回 -1.0
148 |
149 | @param faceInfo MGFaceInfo 1
150 | @param faceInf2 MGFaceInfo 2
151 | @return 比对相似度
152 | */
153 | - (float)faceCompareWithFaceInfo:(MGFaceInfo *)faceInfo faceInf2:(MGFaceInfo *)faceInf2;
154 |
155 | /**
156 | 比较两个人脸相似度
157 | 如果成功返回人脸相似度, 如果比对失败,返回 -1.0
158 |
159 | @param featureData featureData 1
160 | @param featureData2 featureData 2
161 | @return 相似度
162 | */
163 | - (float)faceCompareWithFeatureData:(NSData *)featureData featureData2:(NSData *)featureData2;
164 |
165 |
166 | /** 开启检测新的一帧,在每次调用 detectWithImageData: 之前调用。 */
167 | - (void)beginDetectionFrame;
168 |
169 | /** 停止当前改帧的检测,在获取人脸详细信息后,需要主动调用该方法结束当前帧,以便进入下一帧 */
170 | - (void)endDetectionFrame;
171 |
172 |
173 | /**
174 | 释放算法资源
175 | 算法在计算时需要占用一些内存资源,必须在所有算法的句柄(handle)被释放后再调用
176 |
177 | @return 成功则返回 YES
178 | */
179 | - (BOOL)shutDown;
180 |
181 | #pragma mark - 类方法,获取 SDK 相关信息
182 |
183 |
184 | /**
185 | 获取版本号
186 |
187 | @return 版本号
188 | */
189 | + (NSString *)getSDKVersion;
190 |
191 |
192 | /**
193 | 获取 SDK jenkins 号
194 |
195 | @return SDK jenkins 号
196 | */
197 | + (NSString *)getJenkinsNumber;
198 |
199 |
200 | /**
201 | 清除track缓存
202 |
203 | @return 成功则返回 YES
204 | */
205 | - (BOOL)resetTrack;
206 |
207 |
208 | /**
209 | 获取 SDK 相关信息
210 |
211 | @param modelData model data
212 | @return sdk 相关信息
213 | */
214 | + (MGAlgorithmInfo *)getSDKAlgorithmInfoWithModel:(NSData *)modelData;;
215 |
216 |
217 |
218 |
219 | @end
220 |
221 |
222 |
223 |
224 |
--------------------------------------------------------------------------------
/MGFacepp/MGFacepp/MGFaceppCommon.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGFaceppConfig.h
3 | // MGLandMark
4 | //
5 | // Created by 张英堂 on 16/9/5.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #ifndef MGFaceppConfig_h
10 | #define MGFaceppConfig_h
11 |
12 | #import
13 |
14 | #define KMGFACEMODELNAME @"megviifacepp_0_5_2_model"
15 | #define KMGFACEMODELTYPE @""
16 |
17 |
18 | /** 设置检测视频帧的类型 */
19 | typedef NS_ENUM(NSInteger, MGPixelFormatType) {
20 | PixelFormatTypeGRAY = 0,
21 | PixelFormatTypeBGR,
22 | PixelFormatTypeNV21,
23 | PixelFormatTypeRGBA,
24 | PixelFormatTypeRGB
25 | };
26 |
27 | /** face SDK 功能类型 */
28 | typedef NS_ENUM(NSInteger, MGFaceAbility) {
29 | MGFaceAbilityTrack = 0,
30 | MGFaceAbilityDetect = 1,
31 | MGFaceAbilityPose3d = 2,
32 | MGFaceAbilityEyeStatus = 3,
33 | MGFaceAbilityMouseStatus = 4,
34 | MGFaceAbilityMinority = 5,
35 | MGFaceAbilityBlurness = 6,
36 | MGFaceAbilityAgeGender = 7,
37 | MGFaceAbilityExtractFeature = 8,
38 | };
39 |
40 |
41 | /** 人脸检测框 */
42 | typedef struct {
43 | int left;
44 | int top;
45 | int right;
46 | int bottom;
47 | }MGDetectROI;
48 |
49 | CG_INLINE MGDetectROI MGDetectROIMake(int left, int top, int right,int bottom){
50 | MGDetectROI d;
51 | d.left = left;
52 | d.top = top;
53 | d.right = right;
54 | d.bottom = bottom;
55 | return d;
56 | }
57 |
58 | typedef NS_ENUM(NSUInteger ,MGFaceppStatus) {
59 | MGMarkPrepareWork = 1, //初始化已结束, 准备工作
60 | MGMarkWorking, //正在检测中
61 | MGMarkWaiting, //上一帧已经结束,等待下一帧输入
62 | MGMarkStopped //检测器停止检测,等待释放
63 | };
64 |
65 | typedef NS_ENUM(NSUInteger ,MGFppDetectionMode) {
66 | MGFppDetectionModeDetect = 0,
67 | MGFppDetectionModeTracking = 1, // 此模式已经废弃,请使用 robust 模式
68 | MGFppDetectionModeTrackingFast = 3,
69 | MGFppDetectionModeTrackingRobust = 4,
70 | MGFppDetectionModeDetectRect = 5,
71 | MGFppDetectionModeTrackingRect = 6,
72 | };
73 |
74 |
75 | typedef NS_ENUM(NSUInteger ,MGEyeStatus) {
76 | MGEyeStatusNoGlassesOpen = 0,
77 | MGEyeStatusNoGlassesClose = 1,
78 | MGEyeStatusNormalGlassesOpen = 2, //普通眼镜
79 | MGEyeStatusNormalGlassesClose = 3,
80 | MGEyeStatuoDarkGlasses = 4, //太阳镜
81 | MGEyeStatusOtherOcclusion = 5,
82 | MGEyeStatusCount = 6
83 | };
84 |
85 | typedef NS_ENUM(NSUInteger ,MGMouthStatus) {
86 | MGMouthStatusOpen = 0,
87 | MGMouthStatusClose = 1,
88 | MGMouthStatusMaskOrRespopator = 2, //
89 | MGMouthStatusOtherOcclusion = 3,
90 | MGMouthStatusCount = 4, //
91 | };
92 |
93 |
94 |
95 |
96 |
97 | #endif /* MGFaceppConfig_h */
98 |
--------------------------------------------------------------------------------
/MGFacepp/MGFacepp/MGFaceppConfig.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGFaceppConfig.h
3 | // MGFacepp
4 | //
5 | // Created by 张英堂 on 2016/12/27.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | #import "MGFaceppCommon.h"
13 |
14 | #pragma mark - 设置检测参数
15 |
16 | @interface MGFaceppConfig : NSObject
17 |
18 | /** 人脸大小 默认 100 */
19 | @property (nonatomic, assign) int minFaceSize;
20 |
21 | /** 重新全局检测间隔 40 */
22 | @property (nonatomic, assign) int interval;
23 |
24 | /** 旋转角度 defalut 0, [0,90,180,270,360] */
25 | @property (nonatomic, assign) int orientation;
26 |
27 |
28 | /** 设置Detection类型 默认:MGFppDetectionModeNormal */
29 | @property (nonatomic, assign) MGFppDetectionMode detectionMode;
30 |
31 | /** 设置检测区域(为视频流原图的区域),默认全图检测 */
32 | @property (nonatomic, assign) MGDetectROI detectROI;
33 |
34 | /** 设置视频流格式,默认 PixelFormatTypeRGBA */
35 | @property (nonatomic, assign) MGPixelFormatType pixelFormatType;
36 |
37 |
38 | @property (nonatomic, assign) float faceConfidenceFilter;
39 |
40 |
41 |
42 | @end
43 |
--------------------------------------------------------------------------------
/MGFacepp/MGFacepp/MGFaceppConfig.m:
--------------------------------------------------------------------------------
1 | //
2 | // MGFaceppConfig.m
3 | // MGFacepp
4 | //
5 | // Created by 张英堂 on 2016/12/27.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import "MGFaceppConfig.h"
10 |
11 | @interface MGFaceppConfig ()
12 |
13 | ////** 测试使用 */
14 | @property (nonatomic, assign) float dzt;
15 |
16 | @end
17 |
18 | @implementation MGFaceppConfig
19 |
20 |
21 | - (instancetype)init
22 | {
23 | self = [super init];
24 | if (self) {
25 |
26 | self.detectionMode = MGFppDetectionModeDetect;
27 | self.minFaceSize = 100;
28 | self.interval = 40;
29 | self.orientation = 0;
30 | self.pixelFormatType = PixelFormatTypeRGBA;
31 |
32 | self.detectROI = MGDetectROIMake(0, 0, 0, 0);
33 | }
34 | return self;
35 | }
36 |
37 |
38 | @end
39 |
--------------------------------------------------------------------------------
/MGFacepp/MGFacepp/MGImageData.h:
--------------------------------------------------------------------------------
1 | //
2 | // MGImageData.h
3 | // MGFacepp
4 | //
5 | // Created by 张英堂 on 2016/12/27.
6 | // Copyright © 2016年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 | @interface MGImageData : NSObject
13 |
14 | /** 请不要使用该方法初始化 */
15 | - (instancetype)init DEPRECATED_ATTRIBUTE;
16 |
17 | /**
18 | 初始化方法,二选一
19 |
20 | @param sampleBuffer 视频流帧
21 | @return 实例化对象
22 | */
23 | - (instancetype)initWithSampleBuffer:(CMSampleBufferRef)sampleBuffer;
24 |
25 | /**
26 | 初始化方法,二选一
27 |
28 |
29 | @param image UIImage 对象
30 | @return 实例化对象
31 | */
32 | - (instancetype)initWithImage:(UIImage *)image;
33 |
34 |
35 | /**
36 | 图片宽度
37 | */
38 | @property (nonatomic, assign) CGFloat width;
39 |
40 | /**
41 | 图片高度
42 | */
43 | @property (nonatomic, assign) CGFloat height;
44 |
45 |
46 | /**
47 | 是否为图片
48 | */
49 | @property (nonatomic, assign, readonly) BOOL isUIImage;
50 |
51 |
52 | /**
53 | 获取内存地址
54 |
55 | @return 内存地址
56 | */
57 | - (const char*)getData;
58 |
59 |
60 | /**
61 | 释放内存
62 | */
63 | - (void)releaseImageData;
64 |
65 | @end
66 |
--------------------------------------------------------------------------------
/MGFacepp/MegviiFacepp_C_SDK/libMegviiFacepp-0.5.2.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/MGFacepp/MegviiFacepp_C_SDK/libMegviiFacepp-0.5.2.a
--------------------------------------------------------------------------------
/MGFacepp/MegviiFacepp_C_SDK/megviifacepp_0_5_2_model:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/MGFacepp/MegviiFacepp_C_SDK/megviifacepp_0_5_2_model
--------------------------------------------------------------------------------
/MGFaceppSDKTest/MGFaceppSDKTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/MGFaceppSDKTest/MGFaceppSDKTestTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/MGFaceppSDKTest/MGFaceppSDKTestTests/MGFaceppSDKTestTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // MGFaceppSDKTestTests.m
3 | // MGFaceppSDKTestTests
4 | //
5 | // Created by 张英堂 on 2017/5/23.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface MGFaceppSDKTestTests : XCTestCase
12 |
13 | @end
14 |
15 | @implementation MGFaceppSDKTestTests
16 |
17 | - (void)setUp {
18 | [super setUp];
19 | // Put setup code here. This method is called before the invocation of each test method in the class.
20 | }
21 |
22 | - (void)tearDown {
23 | // Put teardown code here. This method is called after the invocation of each test method in the class.
24 | [super tearDown];
25 | }
26 |
27 | - (void)testExample {
28 | // This is an example of a functional test case.
29 | // Use XCTAssert and related functions to verify your tests produce the correct results.
30 | }
31 |
32 | - (void)testPerformanceExample {
33 | // This is an example of a performance test case.
34 | [self measureBlock:^{
35 | // Put the code you want to measure the time of here.
36 | }];
37 | }
38 |
39 | @end
40 |
--------------------------------------------------------------------------------
/MGFaceppSDKTest/SDKTest/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/MGFaceppSDKTest/SDKTest/2.png
--------------------------------------------------------------------------------
/MGFaceppSDKTest/SDKTest/3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/MGFaceppSDKTest/SDKTest/3.jpg
--------------------------------------------------------------------------------
/MGFaceppSDKTest/SDKTest/81_points_position.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/MGFaceppSDKTest/SDKTest/81_points_position.jpg
--------------------------------------------------------------------------------
/MGFaceppSDKTest/SDKTest/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // SDKTest
4 | //
5 | // Created by 张英堂 on 2017/1/10.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/MGFaceppSDKTest/SDKTest/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // SDKTest
4 | //
5 | // Created by 张英堂 on 2017/1/10.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 |
11 | @interface AppDelegate ()
12 |
13 | @end
14 |
15 | @implementation AppDelegate
16 |
17 |
18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
19 | // Override point for customization after application launch.
20 | return YES;
21 | }
22 |
23 |
24 | - (void)applicationWillResignActive:(UIApplication *)application {
25 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
26 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
27 | }
28 |
29 |
30 | - (void)applicationDidEnterBackground:(UIApplication *)application {
31 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
32 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
33 | }
34 |
35 |
36 | - (void)applicationWillEnterForeground:(UIApplication *)application {
37 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
38 | }
39 |
40 |
41 | - (void)applicationDidBecomeActive:(UIApplication *)application {
42 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
43 | }
44 |
45 |
46 | - (void)applicationWillTerminate:(UIApplication *)application {
47 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
48 | }
49 |
50 |
51 | @end
52 |
--------------------------------------------------------------------------------
/MGFaceppSDKTest/SDKTest/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "20x20",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "20x20",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "29x29",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "29x29",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "40x40",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "40x40",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "size" : "60x60",
36 | "scale" : "2x"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "size" : "60x60",
41 | "scale" : "3x"
42 | }
43 | ],
44 | "info" : {
45 | "version" : 1,
46 | "author" : "xcode"
47 | }
48 | }
--------------------------------------------------------------------------------
/MGFaceppSDKTest/SDKTest/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/MGFaceppSDKTest/SDKTest/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
36 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/MGFaceppSDKTest/SDKTest/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 | LSRequiresIPhoneOS
22 |
23 | UILaunchStoryboardName
24 | LaunchScreen
25 | UIMainStoryboardFile
26 | Main
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/MGFaceppSDKTest/SDKTest/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // SDKTest
4 | //
5 | // Created by 张英堂 on 2017/1/10.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ViewController : UIViewController
12 |
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/MGFaceppSDKTest/SDKTest/ViewController.mm:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.m
3 | // SDKTest
4 | //
5 | // Created by 张英堂 on 2017/1/10.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import "ViewController.h"
10 | #import "../../MGFacepp/MGFacepp/MGFacepp.h"
11 | #import "../../MGFacepp/MGFacepp/MGFaceppConfig.h"
12 | #import "../../MGFacepp/MGFacepp/MGFaceppCommon.h"
13 | #import "../../MGFacepp/MGFacepp/MGAlgorithmInfo.h"
14 |
15 | @interface ViewController ()
16 | @property (nonatomic, strong) MGFacepp *facepp;
17 | @end
18 |
19 | @implementation ViewController
20 |
21 | - (void)viewDidLoad {
22 | [super viewDidLoad];
23 |
24 | NSString *modelPath = [[NSBundle mainBundle] pathForResource:KMGFACEMODELNAME ofType:KMGFACEMODELTYPE];
25 | NSData *modelData = [NSData dataWithContentsOfFile:modelPath];
26 | MGAlgorithmInfo *sdkInfo = [MGFacepp getSDKAlgorithmInfoWithModel:modelData];
27 |
28 | NSLog(@"\n************\nSDK 功能列表: %@\n是否需要联网授权: %d\n版本号:%@\n过期时间:%@ \n************", sdkInfo.SDKAbility, sdkInfo.needNetLicense, sdkInfo.version, sdkInfo.expireDate);
29 |
30 | _facepp = [[MGFacepp alloc] initWithModel:modelData
31 | faceppSetting:^(MGFaceppConfig *config) {
32 | [config setOrientation:0];
33 | }];
34 |
35 | }
36 |
37 | - (IBAction)detectAction:(id)sender {
38 | UIImage *image = [UIImage imageNamed:@"3.jpg"];
39 | MGImageData *imageData = [[MGImageData alloc] initWithImage:image];
40 |
41 | [_facepp beginDetectionFrame];
42 |
43 | NSArray *faceArray = [_facepp detectWithImageData:imageData];
44 | if (faceArray.count > 0) {
45 | NSLog(@"检测到人脸,数量:%zi", faceArray.count);
46 | MGFaceInfo *face = faceArray[0];
47 | [_facepp GetAttributeAgeGenderStatus:face];
48 | NSLog(@"年龄:%.2f", face.age);
49 | } else {
50 | NSLog(@"3.jpg 未检测到人脸");
51 | }
52 |
53 | [_facepp endDetectionFrame];
54 | }
55 |
56 | - (IBAction)compareAction:(id)sender {
57 | UIImage *image1 = [UIImage imageNamed:@"3.jpg"];
58 | UIImage *image2 = [UIImage imageNamed:@"2.png"];
59 | NSData *data1, *data2;
60 |
61 | // image1
62 | MGImageData *imageData = [[MGImageData alloc] initWithImage:image1];
63 | [_facepp beginDetectionFrame];
64 |
65 | NSArray *face = [_facepp detectWithImageData:imageData];
66 | if (face.count > 0) {
67 | MGFaceInfo *faceInfo = face[0];
68 | BOOL success = [_facepp GetFeatureData:faceInfo];
69 | if (success) {
70 | data1 = faceInfo.featureData;
71 | }
72 | } else {
73 | NSLog(@"3.jpg 未检测到人脸");
74 | }
75 | [_facepp endDetectionFrame];
76 |
77 | // image2
78 | MGImageData *imageData2 = [[MGImageData alloc] initWithImage:image2];
79 | [_facepp beginDetectionFrame];
80 |
81 | NSArray *face2 = [_facepp detectWithImageData:imageData2];
82 | if (face.count > 0) {
83 | MGFaceInfo *faceInfo2 = face2[0];
84 | BOOL success = [_facepp GetFeatureData:faceInfo2];
85 | if (success) {
86 | data2 = faceInfo2.featureData;
87 | }
88 | } else {
89 | NSLog(@"2.png 未检测到人脸");
90 | }
91 | [_facepp endDetectionFrame];
92 |
93 | CGFloat like = [_facepp faceCompareWithFeatureData:data1 featureData2:data2];
94 | NSLog(@"相似度:%.2f",like);
95 | }
96 |
97 |
98 | @end
99 |
--------------------------------------------------------------------------------
/MGFaceppSDKTest/SDKTest/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // SDKTest
4 | //
5 | // Created by 张英堂 on 2017/1/10.
6 | // Copyright © 2017年 megvii. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/MGFaceppSDKTest/SDKTest/standard_alpha.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/MegviiFacepp-iOS-SDK/cf98c2b58505ceabd91ea52eb781e9d61f8d72cd/MGFaceppSDKTest/SDKTest/standard_alpha.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MegviiFacepp-iOS-SDK
2 |
3 | An iOS wrapper of MegviiFacepp SDK (the mobile SDK).
4 |
5 | 版本号: 0.5.2(此版本 SDK 适用于 Megvii-Facepp 0.5.2I)
6 |
7 | [学习如何使用 SDK](https://github.com/FacePlusPlus/MegviiFacepp-iOS-SDK/wiki/)
8 |
9 | Version: 0.5.2 (This version is compatible to Megvii-Facepp 0.5.2I)
10 |
11 | [Learn how to use SDK](https://github.com/FacePlusPlus/MegviiFacepp-iOS-SDK/wiki/)
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------