├── FaceSDKDemo
├── body.jpg
├── body.png
├── icon.png
├── idcard.jpg
├── plate.jpg
├── bankCard.jpg
├── beautify.jpg
├── demo-pic.jpg
├── icon@2x.png
├── sunli-1.png
├── sunli-2.png
├── jiashizheng.jpg
├── xingshizheng.jpg
├── mergefaceSource.jpg
├── mergefaceTarget.jpg
├── ViewController.h
├── Controller
│ ├── FCSearchViewController.h
│ ├── FCmergefaceViewController.h
│ ├── FCBankCardViewController.h
│ ├── FCBeautifyViewController.h
│ ├── FCCompareViewController.h
│ ├── FCOCRIDCardViewController.h
│ ├── FCLicensePlateViewController.h
│ ├── FCBodySegmentViewController.h
│ ├── FCOCRDriverLicenceViewController.h
│ ├── FCOCRVehicleLicenseViewController.h
│ ├── FCBodyDetectViewController.h
│ ├── FCDetectViewController.h
│ ├── NSMutableAttributedString+FCExtension.h
│ ├── FCBaseViewController.h
│ ├── NSMutableAttributedString+FCExtension.m
│ ├── FCBodySegmentViewController.m
│ ├── FCLicensePlateViewController.m
│ ├── FCBankCardViewController.m
│ ├── FCBeautifyViewController.m
│ ├── FCOCRIDCardViewController.m
│ ├── FCOCRDriverLicenceViewController.m
│ └── FCOCRVehicleLicenseViewController.m
├── AppDelegate.h
├── main.m
├── Info.plist
├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
└── AppDelegate.m
├── iOS—SDK-Demo运行文档.pdf
├── FaceSDKDemo.xcodeproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
└── xcuserdata
│ ├── yuanle.xcuserdatad
│ └── xcschemes
│ │ ├── xcschememanagement.plist
│ │ └── FaceSDKDemo.xcscheme
│ └── yangyunxing.xcuserdatad
│ └── xcschemes
│ ├── xcschememanagement.plist
│ └── FaceSDKDemo.xcscheme
├── SDWebImage
├── UIImage+MultiFormat.h
├── SDWebImageOperation.h
├── UIImage+GIF.h
├── SDWebImageDecoder.h
├── NSData+ImageContentType.h
├── UIView+WebCacheOperation.h
├── NSData+ImageContentType.m
├── SDWebImageCompat.m
├── SDWebImageCompat.h
├── UIView+WebCacheOperation.m
├── UIImage+MultiFormat.m
├── SDWebImageDecoder.m
├── SDWebImagePrefetcher.h
├── SDWebImageDownloaderOperation.h
├── SDWebImagePrefetcher.m
├── UIImageView+HighlightedWebCache.h
├── UIImageView+HighlightedWebCache.m
└── UIImage+GIF.m
├── FCPPSDK
├── FCPPSDK.h
├── FCPPConfig.h
├── FCPPFaceBeautify.h
├── FCPPFaceDetect.h
├── UIImage+FCExtension.h
├── FCPPBody.h
├── FCPPFaceBeautify.m
├── FCPPMergeface.h
├── FCPPFaceDetect.m
├── FCPPOCR.h
├── FCPPBody.m
├── FCPPOCR.m
├── FCPPFace.h
├── FCPPApi.h
├── FCPPMergeface.m
├── FCPPFaceSet.h
├── FCPPApi.m
├── FCPPFace.m
├── FCPPFaceSet.m
└── UIImage+FCExtension.m
├── AFNetworking
├── UIKit+AFNetworking
│ ├── UIImage+AFNetworking.h
│ ├── UIKit+AFNetworking.h
│ ├── UIActivityIndicatorView+AFNetworking.h
│ ├── UIRefreshControl+AFNetworking.h
│ ├── UIProgressView+AFNetworking.h
│ ├── UIWebView+AFNetworking.h
│ ├── UIRefreshControl+AFNetworking.m
│ ├── UIActivityIndicatorView+AFNetworking.m
│ ├── UIProgressView+AFNetworking.m
│ ├── AFNetworkActivityIndicatorManager.h
│ ├── UIImageView+AFNetworking.h
│ └── AFAutoPurgingImageCache.h
└── AFNetworking
│ └── AFNetworking.h
└── ReadMe.md
/FaceSDKDemo/body.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/facepp-ios-sdk/HEAD/FaceSDKDemo/body.jpg
--------------------------------------------------------------------------------
/FaceSDKDemo/body.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/facepp-ios-sdk/HEAD/FaceSDKDemo/body.png
--------------------------------------------------------------------------------
/FaceSDKDemo/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/facepp-ios-sdk/HEAD/FaceSDKDemo/icon.png
--------------------------------------------------------------------------------
/iOS—SDK-Demo运行文档.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/facepp-ios-sdk/HEAD/iOS—SDK-Demo运行文档.pdf
--------------------------------------------------------------------------------
/FaceSDKDemo/idcard.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/facepp-ios-sdk/HEAD/FaceSDKDemo/idcard.jpg
--------------------------------------------------------------------------------
/FaceSDKDemo/plate.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/facepp-ios-sdk/HEAD/FaceSDKDemo/plate.jpg
--------------------------------------------------------------------------------
/FaceSDKDemo/bankCard.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/facepp-ios-sdk/HEAD/FaceSDKDemo/bankCard.jpg
--------------------------------------------------------------------------------
/FaceSDKDemo/beautify.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/facepp-ios-sdk/HEAD/FaceSDKDemo/beautify.jpg
--------------------------------------------------------------------------------
/FaceSDKDemo/demo-pic.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/facepp-ios-sdk/HEAD/FaceSDKDemo/demo-pic.jpg
--------------------------------------------------------------------------------
/FaceSDKDemo/icon@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/facepp-ios-sdk/HEAD/FaceSDKDemo/icon@2x.png
--------------------------------------------------------------------------------
/FaceSDKDemo/sunli-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/facepp-ios-sdk/HEAD/FaceSDKDemo/sunli-1.png
--------------------------------------------------------------------------------
/FaceSDKDemo/sunli-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/facepp-ios-sdk/HEAD/FaceSDKDemo/sunli-2.png
--------------------------------------------------------------------------------
/FaceSDKDemo/jiashizheng.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/facepp-ios-sdk/HEAD/FaceSDKDemo/jiashizheng.jpg
--------------------------------------------------------------------------------
/FaceSDKDemo/xingshizheng.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/facepp-ios-sdk/HEAD/FaceSDKDemo/xingshizheng.jpg
--------------------------------------------------------------------------------
/FaceSDKDemo/mergefaceSource.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/facepp-ios-sdk/HEAD/FaceSDKDemo/mergefaceSource.jpg
--------------------------------------------------------------------------------
/FaceSDKDemo/mergefaceTarget.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FacePlusPlus/facepp-ios-sdk/HEAD/FaceSDKDemo/mergefaceTarget.jpg
--------------------------------------------------------------------------------
/FaceSDKDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/FaceSDKDemo/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/6/16.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ViewController : UIViewController
12 |
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/FaceSDKDemo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/FCSearchViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCAddFaceViewController.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/7/4.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface FCSearchViewController : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/FCmergefaceViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCmergefaceViewController.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yuan Le on 2018/1/8.
6 | // Copyright © 2018年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface FCmergefaceViewController : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/FCBankCardViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCBankCardViewController.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yuan Le on 2018/6/29.
6 | // Copyright © 2018年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCBaseViewController.h"
10 |
11 | @interface FCBankCardViewController : FCBaseViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/FCBeautifyViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCBeautifyViewController.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yuan Le on 2018/6/29.
6 | // Copyright © 2018年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCBaseViewController.h"
10 |
11 | @interface FCBeautifyViewController : FCBaseViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/FCCompareViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCCompareViewController.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/6/29.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface FCCompareViewController : UIViewController
12 |
13 |
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/FCOCRIDCardViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCOCRIDCardViewController.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/7/19.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCBaseViewController.h"
10 |
11 | @interface FCOCRIDCardViewController : FCBaseViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/SDWebImage/UIImage+MultiFormat.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+MultiFormat.h
3 | // SDWebImage
4 | //
5 | // Created by Olivier Poitrey on 07/06/13.
6 | // Copyright (c) 2013 Dailymotion. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface UIImage (MultiFormat)
12 |
13 | + (UIImage *)sd_imageWithData:(NSData *)data;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/FCLicensePlateViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCLicensePlateViewController.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yuan Le on 2018/7/4.
6 | // Copyright © 2018年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCBaseViewController.h"
10 |
11 | @interface FCLicensePlateViewController : FCBaseViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/FCBodySegmentViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCBodySegmentViewController.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/7/18.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCBaseViewController.h"
10 |
11 | @interface FCBodySegmentViewController : FCBaseViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/FaceSDKDemo/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/6/16.
6 | // Copyright © 2017年 Yang Yunxing. 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 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/FCOCRDriverLicenceViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCOCRDriverLicenceViewController.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/7/19.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCBaseViewController.h"
10 |
11 | @interface FCOCRDriverLicenceViewController : FCBaseViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/FCOCRVehicleLicenseViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCOCRVehicleLicenseViewController.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/7/19.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCBaseViewController.h"
10 |
11 | @interface FCOCRVehicleLicenseViewController : FCBaseViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/FCBodyDetectViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCBodyViewController.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/7/10.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "FCBaseViewController.h"
11 |
12 | @interface FCBodyDetectViewController : FCBaseViewController
13 |
14 |
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/FCDetectViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCDetectViewController.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/6/27.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "FCBaseViewController.h"
11 | #import "FCPPSDK.h"
12 |
13 | @interface FCDetectViewController : FCBaseViewController
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/SDWebImage/SDWebImageOperation.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import
10 |
11 | @protocol SDWebImageOperation
12 |
13 | - (void)cancel;
14 |
15 | @end
16 |
--------------------------------------------------------------------------------
/FaceSDKDemo/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/6/16.
6 | // Copyright © 2017年 Yang Yunxing. 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 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/NSMutableAttributedString+FCExtension.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSMutableAttributedString+FCExtension.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/7/19.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface NSMutableAttributedString (FCExtension)
12 | - (void)appendBoldString:(NSString *)string;
13 | - (void)appendLightString:(NSString *)string;
14 | @end
15 |
--------------------------------------------------------------------------------
/SDWebImage/UIImage+GIF.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+GIF.h
3 | // LBGIFImage
4 | //
5 | // Created by Laurin Brandner on 06.01.12.
6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface UIImage (GIF)
12 |
13 | + (UIImage *)sd_animatedGIFNamed:(NSString *)name;
14 |
15 | + (UIImage *)sd_animatedGIFWithData:(NSData *)data;
16 |
17 | - (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size;
18 |
19 | @end
20 |
--------------------------------------------------------------------------------
/FCPPSDK/FCPPSDK.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCPPSDK.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/6/27.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #ifndef FCPPSDK_h
10 | #define FCPPSDK_h
11 |
12 | #import "FCPPConfig.h"
13 | #import "FCPPApi.h"
14 | #import "FCPPFace.h"
15 | #import "FCPPFaceSet.h"
16 | #import "FCPPBody.h"
17 | #import "FCPPOCR.h"
18 | #import "FCPPFaceDetect.h"
19 | #import "FCPPMergeface.h"
20 |
21 | #endif /* FCPPSDK_h */
22 |
--------------------------------------------------------------------------------
/SDWebImage/SDWebImageDecoder.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * Created by james on 9/28/11.
6 | *
7 | * For the full copyright and license information, please view the LICENSE
8 | * file that was distributed with this source code.
9 | */
10 |
11 | #import
12 | #import "SDWebImageCompat.h"
13 |
14 | @interface UIImage (ForceDecode)
15 |
16 | + (UIImage *)decodedImageWithImage:(UIImage *)image;
17 |
18 | @end
19 |
--------------------------------------------------------------------------------
/FCPPSDK/FCPPConfig.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCPPConfig.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/6/20.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #ifndef FCPPConfig_h
10 | #define FCPPConfig_h
11 |
12 | /**
13 | * 你的ApiKey
14 | * Your ApiKey
15 | */
16 | #define kApiKey @"XXX"
17 |
18 | /**
19 | * 你的ApiSecret
20 | * Your ApiSecret
21 | */
22 | #define kApiSecret @"XXX"
23 |
24 | /**
25 | * 是否为中国地区,中国大陆 : 1 ,其他国家和地区 : 0
26 | * isChina : 1 ,Otherwise : 0
27 | */
28 | #define isChina 1
29 |
30 | #endif /* FCPPConfig_h */
31 |
--------------------------------------------------------------------------------
/FCPPSDK/FCPPFaceBeautify.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCPPFaceBeautify.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yuan Le on 2018/6/29.
6 | // Copyright © 2018年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCPPApi.h"
10 |
11 | @interface FCPPFaceBeautify : FCPPApi
12 |
13 | /**
14 | 人脸美白与磨皮
15 | 中文文档地址:https://console.faceplusplus.com.cn/documents/34878217
16 |
17 | @param ImageObj 图片对象
18 | @param white 美白程度
19 | @param smooth 磨皮程度
20 | @param completion 结果回调
21 | */
22 | -(void)initWithImageObj:(UIImage*)ImageObj withWhite:(int)white withSmoothing:(int)smooth wtihCompletion:(void(^)(id info,NSError *error))completion;
23 |
24 | @end
25 |
--------------------------------------------------------------------------------
/FaceSDKDemo.xcodeproj/xcuserdata/yuanle.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | FaceSDKDemo.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | CC10EAAD1EF378B2000B329D
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/FaceSDKDemo.xcodeproj/xcuserdata/yangyunxing.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | FaceSDKDemo.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | CC10EAAD1EF378B2000B329D
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/SDWebImage/NSData+ImageContentType.h:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Fabrice Aneche on 06/01/14.
3 | // Copyright (c) 2014 Dailymotion. All rights reserved.
4 | //
5 |
6 | #import
7 |
8 | @interface NSData (ImageContentType)
9 |
10 | /**
11 | * Compute the content type for an image data
12 | *
13 | * @param data the input data
14 | *
15 | * @return the content type as string (i.e. image/jpeg, image/gif)
16 | */
17 | + (NSString *)sd_contentTypeForImageData:(NSData *)data;
18 |
19 | @end
20 |
21 |
22 | @interface NSData (ImageContentTypeDeprecated)
23 |
24 | + (NSString *)contentTypeForImageData:(NSData *)data __deprecated_msg("Use `sd_contentTypeForImageData:`");
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/FCPPSDK/FCPPFaceDetect.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCPPFaceDetector.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/7/18.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCPPApi.h"
10 |
11 | @interface FCPPFaceDetect : FCPPApi
12 |
13 | #pragma mark- 人脸检测(face detect)
14 | /**
15 | 检测一张图片并获取人脸信息
16 | 中文文档地址:https://console.faceplusplus.com.cn/documents/4888373
17 |
18 | Detect a image and get the face info.
19 | English document:https://console.faceplusplus.com/documents/5679127
20 |
21 | @param return_landmark 是否返回人脸关键点
22 | @param attributes 需要返回的人脸特征,填写下面的中的一个或多个:gender, age, smiling, headpose, facequality, blur, eyestatus, emotion, ethnicity
23 | */
24 | - (void)detectFaceWithReturnLandmark:(BOOL)return_landmark attributes:(NSArray *)attributes completion:(void(^)(id info,NSError *error))completion;
25 | @end
26 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/FCBaseViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCBaseViewController.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/7/10.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "FCPPSDK.h"
11 | #import "MBProgressHUD.h"
12 |
13 | @interface FCBaseViewController : UIViewController
14 |
15 | @property (strong , nonatomic) UIImage *image;
16 |
17 | @property (strong , nonatomic) NSMutableArray *dataArray;
18 |
19 | @property (strong, nonatomic) UIImageView *imageView;
20 |
21 | @property (strong, nonatomic) UITableView *tableView;
22 |
23 | - (void)handleImage:(UIImage *)image;
24 | - (void)showResult:(id)result;
25 | - (void)showError:(NSError *)error;
26 | - (void)showContent:(NSString *)content;
27 | @end
28 |
--------------------------------------------------------------------------------
/FCPPSDK/UIImage+FCExtension.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+FCExtension.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/7/14.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 |
12 | @interface UIImage (FCExtension)
13 |
14 | /**
15 | 调整图片,使其不超过最大尺寸
16 |
17 | @param maxSize 最大尺寸
18 | @return UIImage *
19 | */
20 | - (UIImage *)fixImageWithMaxSize:(CGSize)maxSize;
21 |
22 |
23 | /**
24 | 将图片转为二进制数据
25 |
26 | @return NSData
27 | */
28 | - (NSData *)imageData;
29 |
30 |
31 | /**
32 | 将图片转为base64编码的字符串
33 |
34 | @return NSString *
35 | */
36 | - (NSString *)base64String;
37 |
38 |
39 | /**
40 | 图片裁剪
41 |
42 | @param rect 裁剪范围
43 | @return UIImage *
44 | */
45 | - (UIImage *)cropWithRect:(CGRect)rect;
46 |
47 | /**
48 | 将已知图片与灰度图进行合并
49 |
50 | @param grayImage 灰度图
51 | @param hexColor 16进制的背景色
52 | @return 返回抠图结果
53 | */
54 | - (UIImage *)blendWithGrayImage:(UIImage *)grayImage backgroudColor:(long)hexColor;
55 |
56 | @end
57 |
--------------------------------------------------------------------------------
/FCPPSDK/FCPPBody.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCPPBodyManager.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/6/22.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "FCPPApi.h"
11 |
12 | @interface FCPPBody : FCPPApi
13 | /**
14 | 检测人体
15 | 中文文档:https://console.faceplusplus.com.cn/documents/7774430
16 |
17 | detect body
18 | English document: https://console.faceplusplus.com/documents/7774480
19 |
20 | @param attributes 额外返回的属性,比如gender,cloth_color
21 | @param completion 回调
22 | */
23 | - (void)detectBodyWithAttributes:(NSArray *)attributes completion:(void(^)(id info,NSError *error))completion;
24 |
25 |
26 | /**
27 | 人像抠图,返回一张base64编码的灰度图
28 | 中文文档:https://console.faceplusplus.com.cn/documents/7774432
29 |
30 | English document:https://console.faceplusplus.com/documents/7774482
31 |
32 | @param completion 结果回调
33 | */
34 | - (void)segmentBodyCompletion:(void(^)(id info,NSError *error))completion;
35 |
36 | @end
37 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/NSMutableAttributedString+FCExtension.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSMutableAttributedString+FCExtension.m
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/7/19.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "NSMutableAttributedString+FCExtension.h"
10 |
11 | @implementation NSMutableAttributedString (FCExtension)
12 | - (void)appendBoldString:(NSString *)string{
13 | if (string) {
14 | NSAttributedString *attString = [[NSAttributedString alloc] initWithString:string attributes:@{NSForegroundColorAttributeName : [UIColor blackColor],NSFontAttributeName : [UIFont boldSystemFontOfSize:18]}];
15 | [self appendAttributedString:attString];
16 | }
17 | }
18 |
19 | - (void)appendLightString:(NSString *)string{
20 | if (string) {
21 | NSAttributedString *attString = [[NSAttributedString alloc] initWithString:string attributes:@{NSForegroundColorAttributeName : [UIColor grayColor],NSFontAttributeName : [UIFont systemFontOfSize:16]}];
22 | [self appendAttributedString:attString];
23 | }
24 | }
25 | @end
26 |
--------------------------------------------------------------------------------
/SDWebImage/UIView+WebCacheOperation.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import
10 | #import "SDWebImageManager.h"
11 |
12 | @interface UIView (WebCacheOperation)
13 |
14 | /**
15 | * Set the image load operation (storage in a UIView based dictionary)
16 | *
17 | * @param operation the operation
18 | * @param key key for storing the operation
19 | */
20 | - (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key;
21 |
22 | /**
23 | * Cancel all operations for the current UIView and key
24 | *
25 | * @param key key for identifying the operations
26 | */
27 | - (void)sd_cancelImageLoadOperationWithKey:(NSString *)key;
28 |
29 | /**
30 | * Just remove the operations corresponding to the current UIView and key without cancelling them
31 | *
32 | * @param key key for identifying the operations
33 | */
34 | - (void)sd_removeImageLoadOperationWithKey:(NSString *)key;
35 |
36 | @end
37 |
--------------------------------------------------------------------------------
/FCPPSDK/FCPPFaceBeautify.m:
--------------------------------------------------------------------------------
1 | //
2 | // FCPPFaceBeautify.m
3 | // FaceSDKDemo
4 | //
5 | // Created by Yuan Le on 2018/6/29.
6 | // Copyright © 2018年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCPPFaceBeautify.h"
10 |
11 | @implementation FCPPFaceBeautify
12 |
13 | /**
14 | 人脸美白与磨皮
15 | 中文文档地址:https://console.faceplusplus.com.cn/documents/34878217
16 |
17 | @param ImageObj 图片对象
18 | @param white 美白程度
19 | @param smooth 磨皮程度
20 | @param completion 结果回调
21 | */
22 | -(void)initWithImageObj:(UIImage*)ImageObj withWhite:(int)white withSmoothing:(int)smooth wtihCompletion:(void(^)(id info,NSError *error))completion{
23 |
24 | NSString *url = [NSString stringWithFormat:@"%@%@",FACE_BEAUTIFY_WEB_BASE_CN,FACE_BEAUTIFY];
25 | NSMutableDictionary *param = [NSMutableDictionary dictionary];
26 | if (ImageObj) {
27 | NSString *baseStr = ImageObj.base64String;
28 | [param setObject:baseStr forKey:@"image_base64"];
29 | }
30 |
31 | if (white>=0&&white<=100) {
32 | [param setObject:@(white) forKey:@"whitening"];//默认为100
33 | }
34 | if (smooth>=0&&smooth<=100) {
35 | [param setObject:@(smooth) forKey:@"smoothing"];//默认为100
36 | }
37 | [FCPPApi POST:url param:param completion:completion];
38 |
39 | }
40 |
41 |
42 | @end
43 |
--------------------------------------------------------------------------------
/FCPPSDK/FCPPMergeface.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCPPMergeface.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yuan Le on 2018/1/9.
6 | // Copyright © 2018年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCPPApi.h"
10 |
11 | @interface FCPPMergeface : FCPPApi
12 |
13 | @property(copy, nonatomic)NSString* imageRectangle;///<图片中人脸框位置,如@“234,456,456,356”,分别表示人脸框在图片中的x,y,width,height坐标
14 |
15 | /**
16 | 对模板图和融合图中的人脸进行融合操作
17 | 中文文档地址:https://console.faceplusplus.com.cn/documents/20813963
18 |
19 | Fusion operation of image in template and face image.
20 | English document:https://console.faceplusplus.com/documents/20815649
21 |
22 | 初始化对象
23 | @param image 图片对象
24 | @param ImageRectangle 图片人脸框位置,如@“234,456,456,356”,分别表示人脸框在图片中的x,y,width,height坐标,当image表示融合图时候,如果该字段为nil时,则不上传该参数,如果无效时返回错误;当image表示模板图时,如果该字段为nil时,则默认会调用人脸检测再进行人脸融合,如果无效时返回错误。
25 | @return 当前对象
26 | */
27 | -(instancetype)initWithImage:(UIImage*)image withImageRectangle:(NSString*)ImageRectangle;
28 |
29 |
30 | /**
31 | 由模板图生成的对象调用该方法和融合图进行融合
32 |
33 | @param fuseImageObj 融合图对象
34 | @param mergeRate 融合比例,范围 [0,100]。数字越大融合结果包含越多融合图,当该值无效时,默认为50
35 | @param completion 结果回调
36 | */
37 | -(void)mergeWithFuseImageObj:(FCPPMergeface*)fuseImageObj withMergeRate:(int)mergeRate wtihCompletion:(void(^)(id info,NSError *error))completion;
38 |
39 | @end
40 |
--------------------------------------------------------------------------------
/SDWebImage/NSData+ImageContentType.m:
--------------------------------------------------------------------------------
1 | //
2 | // Created by Fabrice Aneche on 06/01/14.
3 | // Copyright (c) 2014 Dailymotion. All rights reserved.
4 | //
5 |
6 | #import "NSData+ImageContentType.h"
7 |
8 |
9 | @implementation NSData (ImageContentType)
10 |
11 | + (NSString *)sd_contentTypeForImageData:(NSData *)data {
12 | uint8_t c;
13 | [data getBytes:&c length:1];
14 | switch (c) {
15 | case 0xFF:
16 | return @"image/jpeg";
17 | case 0x89:
18 | return @"image/png";
19 | case 0x47:
20 | return @"image/gif";
21 | case 0x49:
22 | case 0x4D:
23 | return @"image/tiff";
24 | case 0x52:
25 | // R as RIFF for WEBP
26 | if ([data length] < 12) {
27 | return nil;
28 | }
29 |
30 | NSString *testString = [[NSString alloc] initWithData:[data subdataWithRange:NSMakeRange(0, 12)] encoding:NSASCIIStringEncoding];
31 | if ([testString hasPrefix:@"RIFF"] && [testString hasSuffix:@"WEBP"]) {
32 | return @"image/webp";
33 | }
34 |
35 | return nil;
36 | }
37 | return nil;
38 | }
39 |
40 | @end
41 |
42 |
43 | @implementation NSData (ImageContentTypeDeprecated)
44 |
45 | + (NSString *)contentTypeForImageData:(NSData *)data {
46 | return [self sd_contentTypeForImageData:data];
47 | }
48 |
49 | @end
50 |
--------------------------------------------------------------------------------
/AFNetworking/UIKit+AFNetworking/UIImage+AFNetworking.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+AFNetworking.h
3 | //
4 | //
5 | // Created by Paulo Ferreira on 08/07/15.
6 | //
7 | // Permission is hereby granted, free of charge, to any person obtaining a copy
8 | // of this software and associated documentation files (the "Software"), to deal
9 | // in the Software without restriction, including without limitation the rights
10 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | // copies of the Software, and to permit persons to whom the Software is
12 | // furnished to do so, subject to the following conditions:
13 | //
14 | // The above copyright notice and this permission notice shall be included in
15 | // all copies or substantial portions of the Software.
16 | //
17 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 | // THE SOFTWARE.
24 |
25 | #if TARGET_OS_IOS || TARGET_OS_TV
26 |
27 | #import
28 |
29 | @interface UIImage (AFNetworking)
30 |
31 | + (UIImage*) safeImageWithData:(NSData*)data;
32 |
33 | @end
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/ReadMe.md:
--------------------------------------------------------------------------------
1 | ## 中文文档
2 |
3 | * 这个Demo里面的SDK是对官网在线Api接口的封装,需要联网使用.官网接口文档地址:
4 | * 如何运行Demo:
5 | * 在官网注册账号:
6 | * 创建APIKey来使用: (试用的APIKey可以免费使用,可能有并发数错误.正式APIKey需要充值后使用)
7 | * 配置`FCPPConfig.h`文件,将生成的`APIKey`和`APISecret`写到这个文件,`isChina` 设置为`1`.
8 | * 运行
9 |
10 | * 如何集成到自己的项目
11 |
12 | * 把`FCPPSDK`和`AFNetworking`这个文件夹拖入到自己的项目即可
13 | * 配置`FCPPConfig.h`文件,方法同上面第三步.
14 |
15 | * 如果集成中有问题,请[联系我们](https://www.faceplusplus.com.cn/contact-us/)
16 |
17 | ## English Document
18 |
19 | * The SDK in the Demo is a package of online api which need to use the network. The api document:
20 | * How to run the Demo ?
21 | * Register an account in the offcial website:
22 | * Creating a APIKey and APISecret to use: (The free APIKey has a limit of on the number of concurrent,and if using the official APIKey, please make sure the account balance is sufficient)
23 | * Set the `APIKey` and `APISecret` in the file `FCPPConfig.h`. The value of `isChina` is `0`.
24 |
25 | * To integrate SDK into your iOS project
26 |
27 | * Drag `FaceppSDK` and `AFNetworking` into project's file folder.
28 | * Config the file `FCPPConfig.h` just like the third step above.
29 | * If have any problem please [contact us](https://www.faceplusplus.com/contact-us/)
30 |
31 |
--------------------------------------------------------------------------------
/SDWebImage/SDWebImageCompat.m:
--------------------------------------------------------------------------------
1 | //
2 | // SDWebImageCompat.m
3 | // SDWebImage
4 | //
5 | // Created by Olivier Poitrey on 11/12/12.
6 | // Copyright (c) 2012 Dailymotion. All rights reserved.
7 | //
8 |
9 | #import "SDWebImageCompat.h"
10 |
11 | #if !__has_feature(objc_arc)
12 | #error SDWebImage is ARC only. Either turn on ARC for the project or use -fobjc-arc flag
13 | #endif
14 |
15 | inline UIImage *SDScaledImageForKey(NSString *key, UIImage *image) {
16 | if (!image) {
17 | return nil;
18 | }
19 |
20 | if ([image.images count] > 0) {
21 | NSMutableArray *scaledImages = [NSMutableArray array];
22 |
23 | for (UIImage *tempImage in image.images) {
24 | [scaledImages addObject:SDScaledImageForKey(key, tempImage)];
25 | }
26 |
27 | return [UIImage animatedImageWithImages:scaledImages duration:image.duration];
28 | }
29 | else {
30 | if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
31 | CGFloat scale = 1;
32 | if (key.length >= 8) {
33 | NSRange range = [key rangeOfString:@"@2x."];
34 | if (range.location != NSNotFound) {
35 | scale = 2.0;
36 | }
37 |
38 | range = [key rangeOfString:@"@3x."];
39 | if (range.location != NSNotFound) {
40 | scale = 3.0;
41 | }
42 | }
43 |
44 | UIImage *scaledImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:scale orientation:image.imageOrientation];
45 | image = scaledImage;
46 | }
47 | return image;
48 | }
49 | }
50 |
51 | NSString *const SDWebImageErrorDomain = @"SDWebImageErrorDomain";
52 |
--------------------------------------------------------------------------------
/FCPPSDK/FCPPFaceDetect.m:
--------------------------------------------------------------------------------
1 | //
2 | // FCPPFaceDetector.m
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/7/18.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCPPFaceDetect.h"
10 |
11 | @implementation FCPPFaceDetect
12 |
13 | - (instancetype)initWithImage:(UIImage *)image{
14 | if (self = [super initWithImage:image]) {
15 | self.image = [image fixImageWithMaxSize:CGSizeMake(4096, 4096)];
16 | }
17 | return self;
18 | }
19 |
20 | - (void)detectFaceWithReturnLandmark:(BOOL)return_landmark attributes:(NSArray *)attributes completion:(void(^)(id info,NSError *error))completion{
21 |
22 | NSString *url = [NSString stringWithFormat:@"%@/%@",FACE_WEB_BASE,FACE_DETECT];
23 | NSNumber *landmark = return_landmark ? @(1) : @(0);
24 |
25 | NSMutableDictionary *param = [NSMutableDictionary dictionary];
26 | [param setObject:landmark forKey:@"return_landmark"];
27 |
28 | NSString *att = [attributes componentsJoinedByString:@","];
29 | if (att.length) {
30 | [param setObject:att.copy forKey:@"return_attributes"];
31 | }
32 |
33 | if (self.image) {
34 | NSString *baseStr = self.image.base64String;
35 | [param setObject:baseStr forKey:@"image_base64"];
36 | // [param setObject:self.image.imageData forKey:@"image_file"];
37 | }else if (self.imageUrl){
38 | if ([self.imageUrl hasPrefix:@"http"]) {
39 | [param setObject:self.imageUrl forKey:@"image_url"];
40 | }else{
41 | NSLog(@"please input a vaild url");
42 | }
43 | }else{
44 | NSLog(@"please set a image object or url ");
45 | }
46 | [FCPPApi POST:url param:param completion:completion];
47 | }
48 | @end
49 |
--------------------------------------------------------------------------------
/AFNetworking/AFNetworking/AFNetworking.h:
--------------------------------------------------------------------------------
1 | // AFNetworking.h
2 | //
3 | // Copyright (c) 2013 AFNetworking (http://afnetworking.com/)
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #import
24 | #import
25 | #import
26 |
27 | #ifndef _AFNETWORKING_
28 | #define _AFNETWORKING_
29 |
30 | #import "AFURLRequestSerialization.h"
31 | #import "AFURLResponseSerialization.h"
32 | #import "AFSecurityPolicy.h"
33 |
34 | #if !TARGET_OS_WATCH
35 | #import "AFNetworkReachabilityManager.h"
36 | #endif
37 |
38 | #import "AFURLSessionManager.h"
39 | #import "AFHTTPSessionManager.h"
40 |
41 | #endif /* _AFNETWORKING_ */
42 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | FaceppApi
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 | 1.0
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | NSCameraUsageDescription
26 | 相机授权
27 | NSPhotoLibraryUsageDescription
28 | 相册授权
29 | UILaunchStoryboardName
30 | LaunchScreen
31 | UIMainStoryboardFile
32 | Main
33 | UIRequiredDeviceCapabilities
34 |
35 | armv7
36 |
37 | UISupportedInterfaceOrientations
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationLandscapeLeft
41 | UIInterfaceOrientationLandscapeRight
42 |
43 | UISupportedInterfaceOrientations~ipad
44 |
45 | UIInterfaceOrientationPortrait
46 | UIInterfaceOrientationPortraitUpsideDown
47 | UIInterfaceOrientationLandscapeLeft
48 | UIInterfaceOrientationLandscapeRight
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/FaceSDKDemo/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 |
--------------------------------------------------------------------------------
/AFNetworking/UIKit+AFNetworking/UIKit+AFNetworking.h:
--------------------------------------------------------------------------------
1 | // UIKit+AFNetworking.h
2 | //
3 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #if TARGET_OS_IOS || TARGET_OS_TV
24 | #import
25 |
26 | #ifndef _UIKIT_AFNETWORKING_
27 | #define _UIKIT_AFNETWORKING_
28 |
29 | #if TARGET_OS_IOS
30 | #import "AFAutoPurgingImageCache.h"
31 | #import "AFImageDownloader.h"
32 | #import "AFNetworkActivityIndicatorManager.h"
33 | #import "UIRefreshControl+AFNetworking.h"
34 | #import "UIWebView+AFNetworking.h"
35 | #endif
36 |
37 | #import "UIActivityIndicatorView+AFNetworking.h"
38 | #import "UIButton+AFNetworking.h"
39 | #import "UIImageView+AFNetworking.h"
40 | #import "UIProgressView+AFNetworking.h"
41 | #endif /* _UIKIT_AFNETWORKING_ */
42 | #endif
43 |
--------------------------------------------------------------------------------
/FCPPSDK/FCPPOCR.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCPPOCRManager.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/6/22.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "FCPPApi.h"
11 |
12 | /**
13 | * Only for China,please ignore if you are use international version
14 | */
15 | @interface FCPPOCR : FCPPApi
16 |
17 |
18 | /**
19 | 身份证识别 https://console.faceplusplus.com.cn/documents/5671702
20 |
21 | @param completion 结果回调
22 | */
23 | - (void)ocrIDCardCompletion:(void(^)(id info,NSError *error))completion;
24 |
25 | /**
26 | 机动车驾驶证识别 https://console.faceplusplus.com.cn/documents/5671704
27 |
28 | @param completion 结果回调
29 | */
30 | - (void)ocrDriverLicenseCompletion:(void(^)(id info,NSError *error))completion;
31 |
32 | /**
33 | 机动车行驶证识别 https://console.faceplusplus.com.cn/documents/5671706
34 |
35 | @param completion 结果回调
36 | */
37 | - (void)ocrVehicleLicenseCompletion:(void(^)(id info,NSError *error))completion;
38 |
39 | /**
40 | 文字识别 https://console.faceplusplus.com.cn/documents/7776484
41 |
42 | @param completion 结果回调
43 | */
44 | - (void)ocrTextCompletion:(void(^)(id info,NSError *error))completion;
45 |
46 | /**
47 | 文字识别beta版 https://console.faceplusplus.com.cn/documents/5671710
48 |
49 | @param completion 结果回调
50 | */
51 | - (void)ocrTextBetaCompletion:(void(^)(id info,NSError *error))completion;
52 |
53 | /**
54 | 场景物体识别 https://console.faceplusplus.com.cn/documents/5671708
55 |
56 | @param completion 结果回调
57 | */
58 | - (void)detectSceneAndObjectCompletion:(void(^)(id info,NSError *error))completion;
59 |
60 |
61 | /**
62 | 银行卡识别 https://console.faceplusplus.com.cn/documents/28070070
63 |
64 | @param completion 结果回调
65 | */
66 | - (void)ocrBankCardCompletion:(void(^)(id info,NSError *error))completion;
67 |
68 | /**
69 | 车牌号识别 https://console.faceplusplus.com.cn/documents/33915254
70 |
71 | @param completion 结果回调
72 | */
73 | - (void)licensePlateCompletion:(void(^)(id info,NSError *error))completion;
74 |
75 | @end
76 |
--------------------------------------------------------------------------------
/FaceSDKDemo/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 | "idiom" : "ipad",
45 | "size" : "20x20",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "20x20",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "29x29",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "29x29",
61 | "scale" : "2x"
62 | },
63 | {
64 | "idiom" : "ipad",
65 | "size" : "40x40",
66 | "scale" : "1x"
67 | },
68 | {
69 | "idiom" : "ipad",
70 | "size" : "40x40",
71 | "scale" : "2x"
72 | },
73 | {
74 | "idiom" : "ipad",
75 | "size" : "76x76",
76 | "scale" : "1x"
77 | },
78 | {
79 | "idiom" : "ipad",
80 | "size" : "76x76",
81 | "scale" : "2x"
82 | },
83 | {
84 | "idiom" : "ipad",
85 | "size" : "83.5x83.5",
86 | "scale" : "2x"
87 | },
88 | {
89 | "idiom" : "ios-marketing",
90 | "size" : "1024x1024",
91 | "scale" : "1x"
92 | }
93 | ],
94 | "info" : {
95 | "version" : 1,
96 | "author" : "xcode"
97 | }
98 | }
--------------------------------------------------------------------------------
/SDWebImage/SDWebImageCompat.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | * (c) Jamie Pinkham
5 | *
6 | * For the full copyright and license information, please view the LICENSE
7 | * file that was distributed with this source code.
8 | */
9 |
10 | #import
11 |
12 | #ifdef __OBJC_GC__
13 | #error SDWebImage does not support Objective-C Garbage Collection
14 | #endif
15 |
16 | #if __IPHONE_OS_VERSION_MIN_REQUIRED != 20000 && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_5_0
17 | #error SDWebImage doesn't support Deployment Target version < 5.0
18 | #endif
19 |
20 | #if !TARGET_OS_IPHONE
21 | #import
22 | #ifndef UIImage
23 | #define UIImage NSImage
24 | #endif
25 | #ifndef UIImageView
26 | #define UIImageView NSImageView
27 | #endif
28 | #else
29 |
30 | #import
31 |
32 | #endif
33 |
34 | #ifndef NS_ENUM
35 | #define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
36 | #endif
37 |
38 | #ifndef NS_OPTIONS
39 | #define NS_OPTIONS(_type, _name) enum _name : _type _name; enum _name : _type
40 | #endif
41 |
42 | #if OS_OBJECT_USE_OBJC
43 | #undef SDDispatchQueueRelease
44 | #undef SDDispatchQueueSetterSementics
45 | #define SDDispatchQueueRelease(q)
46 | #define SDDispatchQueueSetterSementics strong
47 | #else
48 | #undef SDDispatchQueueRelease
49 | #undef SDDispatchQueueSetterSementics
50 | #define SDDispatchQueueRelease(q) (dispatch_release(q))
51 | #define SDDispatchQueueSetterSementics assign
52 | #endif
53 |
54 | extern UIImage *SDScaledImageForKey(NSString *key, UIImage *image);
55 |
56 | typedef void(^SDWebImageNoParamsBlock)();
57 |
58 | extern NSString *const SDWebImageErrorDomain;
59 |
60 | #define dispatch_main_sync_safe(block)\
61 | if ([NSThread isMainThread]) {\
62 | block();\
63 | } else {\
64 | dispatch_sync(dispatch_get_main_queue(), block);\
65 | }
66 |
67 | #define dispatch_main_async_safe(block)\
68 | if ([NSThread isMainThread]) {\
69 | block();\
70 | } else {\
71 | dispatch_async(dispatch_get_main_queue(), block);\
72 | }
73 |
--------------------------------------------------------------------------------
/SDWebImage/UIView+WebCacheOperation.m:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import "UIView+WebCacheOperation.h"
10 | #import "objc/runtime.h"
11 |
12 | static char loadOperationKey;
13 |
14 | @implementation UIView (WebCacheOperation)
15 |
16 | - (NSMutableDictionary *)operationDictionary {
17 | NSMutableDictionary *operations = objc_getAssociatedObject(self, &loadOperationKey);
18 | if (operations) {
19 | return operations;
20 | }
21 | operations = [NSMutableDictionary dictionary];
22 | objc_setAssociatedObject(self, &loadOperationKey, operations, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
23 | return operations;
24 | }
25 |
26 | - (void)sd_setImageLoadOperation:(id)operation forKey:(NSString *)key {
27 | [self sd_cancelImageLoadOperationWithKey:key];
28 | NSMutableDictionary *operationDictionary = [self operationDictionary];
29 | [operationDictionary setObject:operation forKey:key];
30 | }
31 |
32 | - (void)sd_cancelImageLoadOperationWithKey:(NSString *)key {
33 | // Cancel in progress downloader from queue
34 | NSMutableDictionary *operationDictionary = [self operationDictionary];
35 | id operations = [operationDictionary objectForKey:key];
36 | if (operations) {
37 | if ([operations isKindOfClass:[NSArray class]]) {
38 | for (id operation in operations) {
39 | if (operation) {
40 | [operation cancel];
41 | }
42 | }
43 | } else if ([operations conformsToProtocol:@protocol(SDWebImageOperation)]){
44 | [(id) operations cancel];
45 | }
46 | [operationDictionary removeObjectForKey:key];
47 | }
48 | }
49 |
50 | - (void)sd_removeImageLoadOperationWithKey:(NSString *)key {
51 | NSMutableDictionary *operationDictionary = [self operationDictionary];
52 | [operationDictionary removeObjectForKey:key];
53 | }
54 |
55 | @end
56 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/FCBodySegmentViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // FCBodySegmentViewController.m
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/7/18.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCBodySegmentViewController.h"
10 | #import "UIImage+FCExtension.h"
11 |
12 | @interface FCBodySegmentViewController ()
13 |
14 | @end
15 |
16 | @implementation FCBodySegmentViewController
17 |
18 | - (void)viewDidLoad {
19 | [super viewDidLoad];
20 | [self handleImage:self.image];
21 | }
22 |
23 | - (void)handleImage:(UIImage *)image{
24 | FCPPBody *body = [[FCPPBody alloc] initWithImage:image];
25 | self.imageView.image = body.image;
26 | MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
27 | [body segmentBodyCompletion:^(id info, NSError *error) {
28 | [hud hideAnimated:YES];
29 | if (info) {
30 | NSString *base64Str = info[@"result"];
31 | if (base64Str.length) {
32 | NSData *data = [[NSData alloc] initWithBase64EncodedString:base64Str options:NSDataBase64DecodingIgnoreUnknownCharacters];
33 | UIImage *image = [UIImage imageWithData:data];
34 | //抠图
35 | self.imageView.image = [body.image blendWithGrayImage:image backgroudColor:0xFFFFFF];
36 | }
37 | [self showResult:info];
38 | }else{
39 | [self showError:error];
40 | }
41 | }];
42 | }
43 | - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
44 | return 0;
45 | }
46 | - (void)didReceiveMemoryWarning {
47 | [super didReceiveMemoryWarning];
48 | // Dispose of any resources that can be recreated.
49 | }
50 |
51 | /*
52 | #pragma mark - Navigation
53 |
54 | // In a storyboard-based application, you will often want to do a little preparation before navigation
55 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
56 | // Get the new view controller using [segue destinationViewController].
57 | // Pass the selected object to the new view controller.
58 | }
59 | */
60 |
61 | @end
62 |
--------------------------------------------------------------------------------
/FCPPSDK/FCPPBody.m:
--------------------------------------------------------------------------------
1 | //
2 | // FCPPBodyManager.m
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/6/22.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCPPBody.h"
10 |
11 | @implementation FCPPBody
12 | - (instancetype)initWithImage:(UIImage *)image{
13 | if (self = [super initWithImage:image]) {
14 | self.image = [image fixImageWithMaxSize:CGSizeMake(1080, 1080)];
15 | }
16 | return self;
17 | }
18 | - (void)detectBodyWithAttributes:(NSArray *)attributes completion:(void(^)(id info,NSError *error))completion{
19 | NSString *url = HUMANBODY_DETECT;
20 | NSMutableDictionary *param = [NSMutableDictionary dictionary];
21 |
22 | NSString *att = [attributes componentsJoinedByString:@","];
23 | if (att.length) {
24 | [param setObject:att.copy forKey:@"return_attributes"];
25 | }
26 |
27 | if (self.image) {
28 | NSString *baseStr = self.image.base64String;
29 | [param setObject:baseStr forKey:@"image_base64"];
30 | }else if (self.imageUrl){
31 | if ([self.imageUrl hasPrefix:@"http"]) {
32 | [param setObject:self.imageUrl forKey:@"image_url"];
33 | }else{
34 | NSLog(@"please input a vaild url");
35 | }
36 | }else{
37 | NSLog(@"please set a image object or url ");
38 | }
39 | [FCPPApi POST:url param:param completion:completion];
40 | }
41 |
42 | - (void)segmentBodyCompletion:(void(^)(id info,NSError *error))completion{
43 | NSString *url = HUMANBODY_SEGMENT;
44 | NSMutableDictionary *param = [NSMutableDictionary dictionary];
45 |
46 | if (self.image) {
47 | NSString *baseStr = self.image.base64String;
48 | [param setObject:baseStr forKey:@"image_base64"];
49 | }else if (self.imageUrl){
50 | if ([self.imageUrl hasPrefix:@"http"]) {
51 | [param setObject:self.imageUrl forKey:@"image_url"];
52 | }else{
53 | NSLog(@"please input a vaild url");
54 | }
55 | }else{
56 | NSLog(@"please set a image object or url ");
57 | }
58 |
59 | [FCPPApi POST:url param:param completion:completion];
60 | }
61 | @end
62 |
--------------------------------------------------------------------------------
/AFNetworking/UIKit+AFNetworking/UIActivityIndicatorView+AFNetworking.h:
--------------------------------------------------------------------------------
1 | // UIActivityIndicatorView+AFNetworking.h
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 |
24 | #import
25 |
26 | #if TARGET_OS_IOS || TARGET_OS_TV
27 |
28 | #import
29 |
30 | /**
31 | This category adds methods to the UIKit framework's `UIActivityIndicatorView` class. The methods in this category provide support for automatically starting and stopping animation depending on the loading state of a session task.
32 | */
33 | @interface UIActivityIndicatorView (AFNetworking)
34 |
35 | ///----------------------------------
36 | /// @name Animating for Session Tasks
37 | ///----------------------------------
38 |
39 | /**
40 | Binds the animating state to the state of the specified task.
41 |
42 | @param task The task. If `nil`, automatic updating from any previously specified operation will be disabled.
43 | */
44 | - (void)setAnimatingWithStateOfTask:(nullable NSURLSessionTask *)task;
45 |
46 | @end
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/FaceSDKDemo/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/6/16.
6 | // Copyright © 2017年 Yang Yunxing. 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 |
--------------------------------------------------------------------------------
/AFNetworking/UIKit+AFNetworking/UIRefreshControl+AFNetworking.h:
--------------------------------------------------------------------------------
1 | // UIRefreshControl+AFNetworking.m
2 | //
3 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #import
24 |
25 | #import
26 |
27 | #if TARGET_OS_IOS
28 |
29 | #import
30 |
31 | NS_ASSUME_NONNULL_BEGIN
32 |
33 | /**
34 | This category adds methods to the UIKit framework's `UIRefreshControl` class. The methods in this category provide support for automatically beginning and ending refreshing depending on the loading state of a session task.
35 | */
36 | @interface UIRefreshControl (AFNetworking)
37 |
38 | ///-----------------------------------
39 | /// @name Refreshing for Session Tasks
40 | ///-----------------------------------
41 |
42 | /**
43 | Binds the refreshing state to the state of the specified task.
44 |
45 | @param task The task. If `nil`, automatic updating from any previously specified operation will be disabled.
46 | */
47 | - (void)setRefreshingWithStateOfTask:(NSURLSessionTask *)task;
48 |
49 | @end
50 |
51 | NS_ASSUME_NONNULL_END
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/AFNetworking/UIKit+AFNetworking/UIProgressView+AFNetworking.h:
--------------------------------------------------------------------------------
1 | // UIProgressView+AFNetworking.h
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 |
24 | #import
25 |
26 | #if TARGET_OS_IOS || TARGET_OS_TV
27 |
28 | #import
29 |
30 | NS_ASSUME_NONNULL_BEGIN
31 |
32 |
33 | /**
34 | This category adds methods to the UIKit framework's `UIProgressView` class. The methods in this category provide support for binding the progress to the upload and download progress of a session task.
35 | */
36 | @interface UIProgressView (AFNetworking)
37 |
38 | ///------------------------------------
39 | /// @name Setting Session Task Progress
40 | ///------------------------------------
41 |
42 | /**
43 | Binds the progress to the upload progress of the specified session task.
44 |
45 | @param task The session task.
46 | @param animated `YES` if the change should be animated, `NO` if the change should happen immediately.
47 | */
48 | - (void)setProgressWithUploadProgressOfTask:(NSURLSessionUploadTask *)task
49 | animated:(BOOL)animated;
50 |
51 | /**
52 | Binds the progress to the download progress of the specified session task.
53 |
54 | @param task The session task.
55 | @param animated `YES` if the change should be animated, `NO` if the change should happen immediately.
56 | */
57 | - (void)setProgressWithDownloadProgressOfTask:(NSURLSessionDownloadTask *)task
58 | animated:(BOOL)animated;
59 |
60 | @end
61 |
62 | NS_ASSUME_NONNULL_END
63 |
64 | #endif
65 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/FCLicensePlateViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // FCLicensePlateViewController.m
3 | // FaceSDKDemo
4 | //
5 | // Created by Yuan Le on 2018/7/4.
6 | // Copyright © 2018年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCLicensePlateViewController.h"
10 | #import "NSMutableAttributedString+FCExtension.h"
11 |
12 | @interface FCLicensePlateViewController ()
13 |
14 | @end
15 |
16 | @implementation FCLicensePlateViewController
17 |
18 | - (void)viewDidLoad {
19 | [super viewDidLoad];
20 | [self handleImage:self.image];
21 | }
22 |
23 | - (void)handleImage:(UIImage *)image{
24 | FCPPOCR *ocr = [[FCPPOCR alloc] initWithImage:image];
25 | self.imageView.image = ocr.image;
26 | NSLog(@"%f",ocr.image.imageData.length/1024.0/1024.0);
27 | MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
28 | [ocr licensePlateCompletion:^(id info, NSError *error) {
29 | [hud hideAnimated:YES];
30 | self.tableView.contentOffset = CGPointMake(0, 0);
31 | [self.dataArray removeAllObjects];
32 | if (info) {
33 | [self showResult:info];
34 | NSArray *array = info[@"results"];
35 | [self.dataArray addObjectsFromArray:array];
36 | }else{
37 | [self showError:error];
38 | }
39 | [self.tableView reloadData];
40 | }];
41 | }
42 | #pragma mark- tableViewDelegate
43 |
44 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
45 | static NSString *cellId = @"vehicleCellllId";
46 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fccellId"];
47 | if (cell == nil) {
48 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
49 | cell.textLabel.numberOfLines = 0;
50 | }
51 | NSDictionary *dic = self.dataArray[0];
52 |
53 | NSMutableAttributedString *detailStr = [[NSMutableAttributedString alloc] init];
54 | [detailStr appendBoldString:@"车牌颜色: "];
55 |
56 | [detailStr appendLightString:[NSString stringWithFormat:@"%@",dic[@"color"]]];
57 | [detailStr appendBoldString:@"\n车牌号: "];
58 | [detailStr appendLightString:dic[@"license_plate_number"]];
59 | cell.textLabel.attributedText = detailStr;
60 |
61 | return cell;
62 | }
63 |
64 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
65 | return 80;
66 | }
67 |
68 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
69 | return self.dataArray.count;
70 | }
71 |
72 | - (void)didReceiveMemoryWarning {
73 | [super didReceiveMemoryWarning];
74 | // Dispose of any resources that can be recreated.
75 | }
76 |
77 | @end
78 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/FCBankCardViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // FCBankCardViewController.m
3 | // FaceSDKDemo
4 | //
5 | // Created by Yuan Le on 2018/6/29.
6 | // Copyright © 2018年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCBankCardViewController.h"
10 | #import "NSMutableAttributedString+FCExtension.h"
11 |
12 | @interface FCBankCardViewController ()
13 |
14 | @end
15 |
16 | @implementation FCBankCardViewController
17 |
18 | - (void)viewDidLoad {
19 | [super viewDidLoad];
20 | [self handleImage:self.image];
21 | }
22 |
23 | - (void)handleImage:(UIImage *)image{
24 | FCPPOCR *ocr = [[FCPPOCR alloc] initWithImage:image];
25 | self.imageView.image = ocr.image;
26 | NSLog(@"%f",ocr.image.imageData.length/1024.0/1024.0);
27 | MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
28 | [ocr ocrBankCardCompletion:^(id info, NSError *error) {
29 | [hud hideAnimated:YES];
30 | self.tableView.contentOffset = CGPointMake(0, 0);
31 | [self.dataArray removeAllObjects];
32 | if (info) {
33 | [self showResult:info];
34 | NSArray *array = info[@"bank_cards"];
35 | [self.dataArray addObjectsFromArray:array];
36 | }else{
37 | [self showError:error];
38 | }
39 | [self.tableView reloadData];
40 | }];
41 | }
42 | #pragma mark- tableViewDelegate
43 |
44 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
45 | static NSString *cellId = @"vehicleCellllId";
46 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fccellId"];
47 | if (cell == nil) {
48 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
49 | cell.textLabel.numberOfLines = 0;
50 | }
51 | NSDictionary *dic = self.dataArray[0];
52 |
53 | NSMutableAttributedString *detailStr = [[NSMutableAttributedString alloc] init];
54 | [detailStr appendBoldString:@"银行卡号: "];
55 | [detailStr appendLightString:dic[@"number"]];
56 | [detailStr appendBoldString:@"\n银行: "];
57 | [detailStr appendLightString:dic[@"bank"]];
58 | [detailStr appendBoldString:@"\n金融组织: "];
59 | //金融组织是个数组
60 | NSArray*orga = dic[@"organization"];
61 | NSMutableString* str = [NSMutableString new];
62 | for (NSString* strTmp in orga) {
63 | [str appendString:strTmp];
64 | }
65 | [detailStr appendLightString:str];
66 | cell.textLabel.attributedText = detailStr;
67 |
68 | return cell;
69 | }
70 |
71 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
72 | return 80;
73 | }
74 |
75 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
76 | return self.dataArray.count;
77 | }
78 |
79 | - (void)didReceiveMemoryWarning {
80 | [super didReceiveMemoryWarning];
81 | // Dispose of any resources that can be recreated.
82 | }
83 |
84 | @end
85 |
--------------------------------------------------------------------------------
/FCPPSDK/FCPPOCR.m:
--------------------------------------------------------------------------------
1 | //
2 | // FCPPOCRManager.m
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/6/22.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCPPOCR.h"
10 | #import "FCPPConfig.h"
11 |
12 | @implementation FCPPOCR
13 | - (instancetype)initWithImage:(UIImage *)image{
14 | if (self = [super initWithImage:image]) {
15 | self.image = [image fixImageWithMaxSize:CGSizeMake(4096, 4096)];
16 | }
17 | return self;
18 | }
19 | - (void)ocrIDCardCompletion:(void(^)(id info,NSError *error))completion{
20 | NSString *url = [NSString stringWithFormat:@"%@/%@",OCR_CN,OCR_CARD];
21 | [self POST:url completion:completion];
22 | }
23 |
24 | - (void)ocrDriverLicenseCompletion:(void(^)(id info,NSError *error))completion{
25 | NSString *url = [NSString stringWithFormat:@"%@/%@",OCR_CN,OCR_DRIVER_LICENSE];
26 | [self POST:url completion:completion];
27 | }
28 |
29 | - (void)ocrVehicleLicenseCompletion:(void(^)(id info,NSError *error))completion{
30 | NSString *url = [NSString stringWithFormat:@"%@/%@",OCR_CN,OCR_VEHICLE_LICENSE];
31 | [self POST:url completion:completion];
32 | }
33 |
34 | - (void)ocrTextCompletion:(void(^)(id info,NSError *error))completion{
35 | NSString *url = [NSString stringWithFormat:@"%@/%@",IMAGE_CN,IMAGE_Text];
36 | [self POST:url completion:completion];
37 | }
38 |
39 | - (void)ocrTextBetaCompletion:(void(^)(id info,NSError *error))completion{
40 | NSString *url = [NSString stringWithFormat:@"%@/%@",IMAGE_CN,IMAGE_Text_Beta];
41 | [self POST:url completion:completion];
42 | }
43 |
44 | - (void)detectSceneAndObjectCompletion:(void(^)(id info,NSError *error))completion{
45 | NSString *url = [NSString stringWithFormat:@"%@/%@",IMAGE_CN,IMAGE_Object];
46 | [self POST:url completion:completion];
47 | }
48 |
49 | - (void)ocrBankCardCompletion:(void(^)(id info,NSError *error))completion{
50 | NSString *url = [NSString stringWithFormat:@"%@/%@",OCR_CN,OCR_BANK_CARD];
51 | [self POST:url completion:completion];
52 | }
53 |
54 | - (void)licensePlateCompletion:(void(^)(id info,NSError *error))completion{
55 | NSString *url = [NSString stringWithFormat:@"%@%@",IMAGE_MERGEFACE_CN,OCR_LICENSE_PLATE];
56 | [self POST:url completion:completion];
57 | }
58 |
59 | - (void)POST:(NSString *)url completion:(void(^)(id info,NSError *error))completion{
60 | if (!isChina) {
61 | NSLog(@"Error-->This method is only for China");
62 | }
63 | NSMutableDictionary *param = [NSMutableDictionary dictionary];
64 |
65 | if (self.image) {
66 | NSString *baseStr = self.image.base64String;
67 | [param setObject:baseStr forKey:@"image_base64"];
68 | // [param setObject:self.image.imageData forKey:@"image_file"];
69 | }else if (self.imageUrl){
70 | if ([self.imageUrl hasPrefix:@"http"]) {
71 | [param setObject:self.imageUrl forKey:@"image_url"];
72 | }else{
73 | NSLog(@"please input a vaild url");
74 | }
75 | }
76 |
77 | [FCPPApi POST:url param:param completion:completion];
78 | }
79 |
80 | @end
81 |
--------------------------------------------------------------------------------
/FCPPSDK/FCPPFace.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCPPFaceManager.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/6/20.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "FCPPApi.h"
11 | #import "FCPPFaceSet.h"
12 |
13 | @interface FCPPFace : FCPPApi
14 |
15 | /**
16 | * 用来标识检已经测到的人脸
17 | * The id of a detected face
18 | */
19 | @property (copy , nonatomic) NSString *faceToken;
20 |
21 | /**
22 | * 用faceToken初始化示例,可以用来比对和搜索
23 | */
24 | - (instancetype)initWithFaceToken:(NSString *)faceToken;
25 |
26 | #pragma mark- 人脸比对(1:1)
27 | /**
28 | 将两个人脸进行比对,来判断是否为同一个人以及相似度
29 | 中文文档地址:https://console.faceplusplus.com.cn/documents/4887586
30 |
31 | compare two face and get the similarity
32 | English document:https://console.faceplusplus.com/documents/5679308
33 |
34 | @param face 另外一张人脸
35 | @param completion 结果回调
36 | */
37 | - (void)compareFaceWithOther:(FCPPFace *)face completion:(void(^)(id info,NSError *error))completion;
38 |
39 | #pragma mark- 人脸搜索(1:N)
40 |
41 | /**
42 | 从多个人脸中找出最像似的1个或多个(最多5个)
43 | 中文文档:https://console.faceplusplus.com.cn/documents/4888381
44 |
45 | search the most similar face in the faceSet, return 5 tokens at most.
46 | English document:https://console.faceplusplus.com/documents/5681455
47 |
48 | @param faceSet faceSet
49 | @param returnCount 返回的数量,范围是1~5
50 | @param completion 结果回调
51 | */
52 | - (void)searchFromFaceSet:(FCPPFaceSet *)faceSet returnCount:(int)returnCount completion:(void(^)(id info,NSError *error))completion;
53 |
54 | #pragma mark- 其他
55 | /**
56 | 根据token获取人脸的详细信息
57 | 中文文档地址:https://console.faceplusplus.com.cn/documents/4888383
58 |
59 | analyze face by face_token
60 | English document:https://console.faceplusplus.com/documents/6329465
61 |
62 | @param faceTokens faceToken的数组
63 | @param returnLandmark 是否返回人脸关键点
64 | @param returnAttributes 需要返回的人脸特征,填写下面的中的一个或多个:gender, age, smiling, headpose, facequality, blur, eyestatus, emotion, ethnicity
65 | @param completion 结果回调
66 | */
67 | + (void)analyzeFaceTokens:(NSArray *)faceTokens return_landmark:(BOOL)returnLandmark attribute:(NSArray *)returnAttributes completion:(void(^)(id info,NSError *error))completion;
68 |
69 |
70 | /**
71 | 为检测出的某一个人脸添加自定义标识信息,该信息会在Search接口结果中返回,用来确定用户身份.
72 | 中文文档:https://console.faceplusplus.com.cn/documents/4888387
73 |
74 | Set user_id for a detected face. user_id can be returned in Search results to determine the identity of user
75 | English document:https://console.faceplusplus.com/documents/6329500
76 |
77 | @param userid 用户自定义的user_id,不超过255个字符,不能包括^@,&=*'"
78 | @param faceToken 人脸标识face_token
79 | @param completion 结果回调
80 | */
81 | + (void)setUserId:(NSString *)userid toFaceToken:(NSString *)faceToken completion:(void(^)(id info,NSError *error))completion;
82 |
83 |
84 | /**
85 | 通过传入在Detect API检测出的人脸标识face_token,获取一个人脸的关联信息,包括源图片ID、归属的FaceSet
86 | 中文文档:https://console.faceplusplus.com.cn/documents/4888385
87 |
88 | Get related information to a face by passing its face_token which you can get from Detect API. Such as the face related information includes image_id and FaceSet which it belongs to.
89 | English document:https://console.faceplusplus.com/documents/6329496
90 |
91 | @param token 人脸标识face_token
92 | @param completion 结果回调
93 | */
94 |
95 | + (void)getDetailWithToken:(NSString *)token completion:(void(^)(id info,NSError *error))completion;
96 | @end
97 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/FCBeautifyViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // FCBeautifyViewController.m
3 | // FaceSDKDemo
4 | //
5 | // Created by Yuan Le on 2018/6/29.
6 | // Copyright © 2018年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCBeautifyViewController.h"
10 | #import "FCPPFaceBeautify.h"
11 |
12 | @interface FCBeautifyCell : UITableViewCell
13 | @property (strong , nonatomic) UIImageView *imageV;
14 | @end
15 |
16 | @implementation FCBeautifyCell
17 |
18 | - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
19 | if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
20 | _imageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width-10*2, [UIScreen mainScreen].bounds.size.height*.5)];
21 | _imageV.contentMode = UIViewContentModeScaleAspectFit;
22 | _imageV.backgroundColor = [UIColor groupTableViewBackgroundColor];
23 | _imageV.clipsToBounds = YES;
24 | [self addSubview:_imageV];
25 | }
26 | return self;
27 | }
28 |
29 | - (void)setFaceInfoWithBase64:(NSString *)beautifyInfo{
30 |
31 | NSString* base64_img = beautifyInfo;
32 | if (base64_img.length) {
33 | NSData *data = [[NSData alloc] initWithBase64EncodedString:base64_img options:NSDataBase64DecodingIgnoreUnknownCharacters];
34 | UIImage *image = [UIImage imageWithData:data];
35 | _imageV.image = image;
36 | }
37 | }
38 |
39 | @end
40 |
41 |
42 | @interface FCBeautifyViewController ()
43 | @end
44 |
45 | @implementation FCBeautifyViewController
46 |
47 | - (void)viewDidLoad {
48 | [super viewDidLoad];
49 | [self handleImage:self.image];
50 | }
51 |
52 | - (void)handleImage:(UIImage *)image{
53 | [MBProgressHUD showHUDAddedTo:self.view animated:YES];
54 | self.imageView.image = image;
55 | [[FCPPFaceBeautify alloc]initWithImageObj:image withWhite:100 withSmoothing:100 wtihCompletion:^(id info, NSError *error) {
56 | [MBProgressHUD hideHUDForView:self.view animated:YES];
57 | NSLog(@"info = %@",info);
58 |
59 | [self.dataArray removeAllObjects];
60 | if (info) {
61 | [self showResult:info];
62 | NSString *base64 = info[@"result"];
63 | [self.dataArray addObject:base64];
64 | }else{
65 | [self showError:error];
66 | }
67 | [self.tableView reloadData];
68 |
69 | }];
70 | }
71 |
72 | - (void)didReceiveMemoryWarning {
73 | [super didReceiveMemoryWarning];
74 | }
75 |
76 | #pragma mark- tableViewDelegate
77 |
78 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
79 | static NSString *cellIdenfify = @"faceBeautify";
80 | FCBeautifyCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdenfify];
81 | if (cell == nil) {
82 | cell = [[FCBeautifyCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdenfify];
83 | }
84 | cell.selectionStyle = UITableViewCellSelectionStyleNone;
85 | NSString *base64 = self.dataArray[0];
86 | [cell setFaceInfoWithBase64:base64];
87 | return cell;
88 | }
89 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
90 | return [UIScreen mainScreen].bounds.size.height/2;
91 | }
92 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
93 | return self.dataArray.count;
94 | }
95 |
96 | @end
97 |
--------------------------------------------------------------------------------
/FaceSDKDemo.xcodeproj/xcuserdata/yuanle.xcuserdatad/xcschemes/FaceSDKDemo.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
75 |
81 |
82 |
83 |
84 |
86 |
87 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/FaceSDKDemo.xcodeproj/xcuserdata/yangyunxing.xcuserdatad/xcschemes/FaceSDKDemo.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
54 |
56 |
62 |
63 |
64 |
65 |
66 |
67 |
73 |
75 |
81 |
82 |
83 |
84 |
86 |
87 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/SDWebImage/UIImage+MultiFormat.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+MultiFormat.m
3 | // SDWebImage
4 | //
5 | // Created by Olivier Poitrey on 07/06/13.
6 | // Copyright (c) 2013 Dailymotion. All rights reserved.
7 | //
8 |
9 | #import "UIImage+MultiFormat.h"
10 | #import "UIImage+GIF.h"
11 | #import "NSData+ImageContentType.h"
12 | #import
13 |
14 | #ifdef SD_WEBP
15 | #import "UIImage+WebP.h"
16 | #endif
17 |
18 | @implementation UIImage (MultiFormat)
19 |
20 | + (UIImage *)sd_imageWithData:(NSData *)data {
21 | if (!data) {
22 | return nil;
23 | }
24 |
25 | UIImage *image;
26 | NSString *imageContentType = [NSData sd_contentTypeForImageData:data];
27 | if ([imageContentType isEqualToString:@"image/gif"]) {
28 | image = [UIImage sd_animatedGIFWithData:data];
29 | }
30 | #ifdef SD_WEBP
31 | else if ([imageContentType isEqualToString:@"image/webp"])
32 | {
33 | image = [UIImage sd_imageWithWebPData:data];
34 | }
35 | #endif
36 | else {
37 | image = [[UIImage alloc] initWithData:data];
38 | UIImageOrientation orientation = [self sd_imageOrientationFromImageData:data];
39 | if (orientation != UIImageOrientationUp) {
40 | image = [UIImage imageWithCGImage:image.CGImage
41 | scale:image.scale
42 | orientation:orientation];
43 | }
44 | }
45 |
46 |
47 | return image;
48 | }
49 |
50 |
51 | +(UIImageOrientation)sd_imageOrientationFromImageData:(NSData *)imageData {
52 | UIImageOrientation result = UIImageOrientationUp;
53 | CGImageSourceRef imageSource = CGImageSourceCreateWithData((__bridge CFDataRef)imageData, NULL);
54 | if (imageSource) {
55 | CFDictionaryRef properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, NULL);
56 | if (properties) {
57 | CFTypeRef val;
58 | int exifOrientation;
59 | val = CFDictionaryGetValue(properties, kCGImagePropertyOrientation);
60 | if (val) {
61 | CFNumberGetValue(val, kCFNumberIntType, &exifOrientation);
62 | result = [self sd_exifOrientationToiOSOrientation:exifOrientation];
63 | } // else - if it's not set it remains at up
64 | CFRelease((CFTypeRef) properties);
65 | } else {
66 | //NSLog(@"NO PROPERTIES, FAIL");
67 | }
68 | CFRelease(imageSource);
69 | }
70 | return result;
71 | }
72 |
73 | #pragma mark EXIF orientation tag converter
74 | // Convert an EXIF image orientation to an iOS one.
75 | // reference see here: http://sylvana.net/jpegcrop/exif_orientation.html
76 | + (UIImageOrientation) sd_exifOrientationToiOSOrientation:(int)exifOrientation {
77 | UIImageOrientation orientation = UIImageOrientationUp;
78 | switch (exifOrientation) {
79 | case 1:
80 | orientation = UIImageOrientationUp;
81 | break;
82 |
83 | case 3:
84 | orientation = UIImageOrientationDown;
85 | break;
86 |
87 | case 8:
88 | orientation = UIImageOrientationLeft;
89 | break;
90 |
91 | case 6:
92 | orientation = UIImageOrientationRight;
93 | break;
94 |
95 | case 2:
96 | orientation = UIImageOrientationUpMirrored;
97 | break;
98 |
99 | case 4:
100 | orientation = UIImageOrientationDownMirrored;
101 | break;
102 |
103 | case 5:
104 | orientation = UIImageOrientationLeftMirrored;
105 | break;
106 |
107 | case 7:
108 | orientation = UIImageOrientationRightMirrored;
109 | break;
110 | default:
111 | break;
112 | }
113 | return orientation;
114 | }
115 |
116 |
117 |
118 | @end
119 |
--------------------------------------------------------------------------------
/FCPPSDK/FCPPApi.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCPPApi.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/6/16.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "UIImage+FCExtension.h"
11 | #import "FCPPConfig.h"
12 |
13 | #ifdef isChina
14 | #if isChina
15 | #define FACE_WEB_BASE FACE_WEB_BASE_CN
16 | #define HUMANBODY_DETECT HUMANBODY_DETECT_CN
17 | #define HUMANBODY_SEGMENT HUMANBODY_SEGMENT_CN
18 | #define IMAGE_MERGEFACE IMAGE_MERGEFACE_CN
19 | #define FACE_BUEATIFY_BASE FACE_BEAUTIFY_WEB_BASE_CN
20 |
21 | #else
22 | #define FACE_WEB_BASE FACE_WEB_BASE_US
23 | #define HUMANBODY_DETECT HUMANBODY_DETECT_US
24 | #define HUMANBODY_SEGMENT HUMANBODY_SEGMENT_US
25 | #define IMAGE_MERGEFACE IMAGE_MERGEFACE_US
26 | #endif
27 | #endif
28 |
29 | #pragma mark- api
30 |
31 | //base url for China
32 | static NSString * FACE_WEB_BASE_CN = @"https://api-cn.faceplusplus.com/facepp/v3";
33 | static NSString * FACE_BEAUTIFY_WEB_BASE_CN = @"https://api-cn.faceplusplus.com/facepp";
34 |
35 | //base url for other country
36 | static NSString * FACE_WEB_BASE_US = @"https://api-us.faceplusplus.com/facepp/v3";
37 |
38 | static NSString * FACE_DETECT = @"detect";
39 | static NSString * FACE_BEAUTIFY = @"/beta/beautify";
40 | static NSString * FACE_COMPARE = @"compare";
41 | static NSString * FACE_SEARCH = @"search";
42 |
43 |
44 | static NSString * FACETOEKN = @"face";
45 | static NSString * FACETOEKN_ANALYZE = @"analyze";
46 | static NSString * FACETOEKN_SET_USERID = @"setuserid";
47 | static NSString * FACETOEKN_GET_DETAIL = @"getdetail";
48 |
49 | //faceSet
50 | static NSString * FACESET = @"faceset";
51 | static NSString * FACESET_CREATE = @"create";
52 | static NSString * FACESET_ADDFACE = @"addface";
53 | static NSString * FACESET_REMOVE_FACE = @"removeface";
54 | static NSString * FACESET_UPDATE = @"update";
55 | static NSString * FACESET_GET_DETAIL = @"getdetail";
56 | static NSString * FACESET_GET_FACESETS = @"getfacesets";
57 | static NSString * FACESET_DELETE = @"delete";
58 |
59 | //人体检测和人体抠图
60 | static NSString * HUMANBODY_DETECT_CN = @"https://api-cn.faceplusplus.com/humanbodypp/beta/detect";
61 | static NSString * HUMANBODY_SEGMENT_CN = @"https://api-cn.faceplusplus.com/humanbodypp/beta/segment";
62 |
63 | static NSString * HUMANBODY_DETECT_US = @"https://api-us.faceplusplus.com/humanbodypp/beta/detect";
64 | static NSString * HUMANBODY_SEGMENT_US = @"https://api-us.faceplusplus.com/humanbodypp/beta/segment";
65 |
66 | //OCR 识别身份证/驾驶证/行驶证/文字/场景物体/银行卡识别,Only for china
67 | static NSString * OCR_CN = @"https://api-cn.faceplusplus.com/cardpp/v1";
68 | static NSString * OCR_CARD = @"ocridcard";
69 | static NSString * OCR_DRIVER_LICENSE = @"ocrdriverlicense";
70 | static NSString * OCR_VEHICLE_LICENSE = @"ocrvehiclelicense";
71 | static NSString * OCR_BANK_CARD = @"ocrbankcard";
72 | static NSString * OCR_LICENSE_PLATE = @"licenseplate";
73 |
74 | static NSString * IMAGE_CN = @"https://api-cn.faceplusplus.com/imagepp";
75 | static NSString * IMAGE_Object = @"beta/detectsceneandobject";
76 | static NSString * IMAGE_Text = @"v1/recognizetext";
77 | static NSString * IMAGE_Text_Beta = @"beta/recognizetext";
78 |
79 | //图像识别之图像融合
80 | static NSString * IMAGE_MERGEFACE_CN = @"https://api-cn.faceplusplus.com/imagepp/v1/";
81 | static NSString * IMAGE_MERGEFACE_US = @"https://api-us.faceplusplus.com/imagepp/v1/";
82 | static NSString * MERGEFACE = @"mergeface";
83 |
84 | @interface FCPPApi : NSObject
85 | /**
86 | * 图片的网络地址
87 | * The image URL
88 | */
89 | @property (copy , nonatomic) NSString *imageUrl;
90 |
91 | @property (strong , nonatomic) UIImage *image;
92 |
93 | - (instancetype)initWithImageUrl:(NSString *)imageUrl;
94 |
95 | - (instancetype)initWithImage:(UIImage *)image;
96 |
97 | /**
98 | POST请求
99 |
100 | @param url 请求地址
101 | @param dic 参数
102 | @param completion 请求结果
103 | */
104 | + (void)POST:(NSString *)url param:(NSDictionary *)dic completion:(void(^)(id info,NSError *error))completion;
105 | @end
106 |
--------------------------------------------------------------------------------
/SDWebImage/SDWebImageDecoder.m:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * Created by james on 9/28/11.
6 | *
7 | * For the full copyright and license information, please view the LICENSE
8 | * file that was distributed with this source code.
9 | */
10 |
11 | #import "SDWebImageDecoder.h"
12 |
13 | @implementation UIImage (ForceDecode)
14 |
15 | + (UIImage *)decodedImageWithImage:(UIImage *)image {
16 | // while downloading huge amount of images
17 | // autorelease the bitmap context
18 | // and all vars to help system to free memory
19 | // when there are memory warning.
20 | // on iOS7, do not forget to call
21 | // [[SDImageCache sharedImageCache] clearMemory];
22 |
23 | if (image == nil) { // Prevent "CGBitmapContextCreateImage: invalid context 0x0" error
24 | return nil;
25 | }
26 |
27 | @autoreleasepool{
28 | // do not decode animated images
29 | if (image.images != nil) {
30 | return image;
31 | }
32 |
33 | CGImageRef imageRef = image.CGImage;
34 |
35 | CGImageAlphaInfo alpha = CGImageGetAlphaInfo(imageRef);
36 | BOOL anyAlpha = (alpha == kCGImageAlphaFirst ||
37 | alpha == kCGImageAlphaLast ||
38 | alpha == kCGImageAlphaPremultipliedFirst ||
39 | alpha == kCGImageAlphaPremultipliedLast);
40 | if (anyAlpha) {
41 | return image;
42 | }
43 |
44 | // current
45 | CGColorSpaceModel imageColorSpaceModel = CGColorSpaceGetModel(CGImageGetColorSpace(imageRef));
46 | CGColorSpaceRef colorspaceRef = CGImageGetColorSpace(imageRef);
47 |
48 | BOOL unsupportedColorSpace = (imageColorSpaceModel == kCGColorSpaceModelUnknown ||
49 | imageColorSpaceModel == kCGColorSpaceModelMonochrome ||
50 | imageColorSpaceModel == kCGColorSpaceModelCMYK ||
51 | imageColorSpaceModel == kCGColorSpaceModelIndexed);
52 | if (unsupportedColorSpace) {
53 | colorspaceRef = CGColorSpaceCreateDeviceRGB();
54 | }
55 |
56 | size_t width = CGImageGetWidth(imageRef);
57 | size_t height = CGImageGetHeight(imageRef);
58 | NSUInteger bytesPerPixel = 4;
59 | NSUInteger bytesPerRow = bytesPerPixel * width;
60 | NSUInteger bitsPerComponent = 8;
61 |
62 |
63 | // kCGImageAlphaNone is not supported in CGBitmapContextCreate.
64 | // Since the original image here has no alpha info, use kCGImageAlphaNoneSkipLast
65 | // to create bitmap graphics contexts without alpha info.
66 | CGContextRef context = CGBitmapContextCreate(NULL,
67 | width,
68 | height,
69 | bitsPerComponent,
70 | bytesPerRow,
71 | colorspaceRef,
72 | kCGBitmapByteOrderDefault|kCGImageAlphaNoneSkipLast);
73 |
74 | // Draw the image into the context and retrieve the new bitmap image without alpha
75 | CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
76 | CGImageRef imageRefWithoutAlpha = CGBitmapContextCreateImage(context);
77 | UIImage *imageWithoutAlpha = [UIImage imageWithCGImage:imageRefWithoutAlpha
78 | scale:image.scale
79 | orientation:image.imageOrientation];
80 |
81 | if (unsupportedColorSpace) {
82 | CGColorSpaceRelease(colorspaceRef);
83 | }
84 |
85 | CGContextRelease(context);
86 | CGImageRelease(imageRefWithoutAlpha);
87 |
88 | return imageWithoutAlpha;
89 | }
90 | }
91 |
92 | @end
93 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/FCOCRIDCardViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // FCOCRIDCardViewController.m
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/7/19.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCOCRIDCardViewController.h"
10 | #import "NSMutableAttributedString+FCExtension.h"
11 |
12 | @interface FCOCRIDCardViewController ()
13 |
14 | @end
15 |
16 | @implementation FCOCRIDCardViewController
17 |
18 | - (void)viewDidLoad {
19 | [super viewDidLoad];
20 | [self handleImage:self.image];
21 | }
22 |
23 | - (void)handleImage:(UIImage *)image{
24 | FCPPOCR *ocr = [[FCPPOCR alloc] initWithImage:image];
25 | self.imageView.image = ocr.image;
26 | MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
27 | [ocr ocrIDCardCompletion:^(id info, NSError *error) {
28 | [hud hideAnimated:YES];
29 | self.tableView.contentOffset = CGPointMake(0, 0);
30 | [self.dataArray removeAllObjects];
31 | if (info) {
32 | [self showResult:info];
33 | NSArray *array = info[@"cards"];
34 | [self.dataArray addObjectsFromArray:array];
35 | }else{
36 | [self showError:error];
37 | }
38 | [self.tableView reloadData];
39 | }];
40 | }
41 | #pragma mark- tableViewDelegate
42 |
43 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
44 | static NSString *cellId = @"IDCardCellllId";
45 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fccellId"];
46 | if (cell == nil) {
47 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
48 | cell.textLabel.numberOfLines = 0;
49 | }
50 | NSDictionary *dic = self.dataArray[indexPath.row];
51 |
52 | NSMutableAttributedString *detailStr = [[NSMutableAttributedString alloc] init];
53 |
54 | BOOL isBack = [dic[@"side"] isEqualToString:@"back"];
55 | if (isBack) {
56 | [detailStr appendBoldString:@"签发机关: "];
57 | [detailStr appendLightString:dic[@"issued_by"]];
58 | [detailStr appendBoldString:@"\n\n有效日期: "];
59 | [detailStr appendLightString:dic[@"valid_date"]];
60 | [detailStr appendBoldString:@"\n\n证件正反面: "];
61 | [detailStr appendLightString:@"国徽面"];
62 | }else{
63 | [detailStr appendBoldString:@"姓名: "];
64 | [detailStr appendLightString:dic[@"name"]];
65 | [detailStr appendBoldString:@"\n性别: "];
66 | [detailStr appendLightString:dic[@"gender"]];
67 | [detailStr appendBoldString:@"\n民族: "];
68 | [detailStr appendLightString:dic[@"race"]];
69 | [detailStr appendBoldString:@"\n出生: "];
70 | [detailStr appendLightString:dic[@"birthday"]];
71 | [detailStr appendBoldString:@"\n住址: "];
72 | [detailStr appendLightString:dic[@"address"]];
73 | [detailStr appendBoldString:@"\n公民身份证号: "];
74 | [detailStr appendLightString:dic[@"id_card_number"]];
75 | [detailStr appendBoldString:@"\n证件正反面: "];
76 | [detailStr appendLightString:@"人像面"];
77 | }
78 |
79 | //正式key,可判断身份证真实性.
80 | // [detailStr appendBoldString:@"\n证件照片真实性: "];
81 |
82 | cell.textLabel.attributedText = detailStr;
83 |
84 | return cell;
85 | }
86 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
87 | return 222;
88 | }
89 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
90 | return self.dataArray.count;
91 | }
92 | - (void)didReceiveMemoryWarning {
93 | [super didReceiveMemoryWarning];
94 | // Dispose of any resources that can be recreated.
95 | }
96 |
97 | /*
98 | #pragma mark - Navigation
99 |
100 | // In a storyboard-based application, you will often want to do a little preparation before navigation
101 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
102 | // Get the new view controller using [segue destinationViewController].
103 | // Pass the selected object to the new view controller.
104 | }
105 | */
106 |
107 | @end
108 |
--------------------------------------------------------------------------------
/FCPPSDK/FCPPMergeface.m:
--------------------------------------------------------------------------------
1 | //
2 | // FCPPMergeface.m
3 | // FaceSDKDemo
4 | //
5 | // Created by Yuan Le on 2018/1/9.
6 | // Copyright © 2018年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCPPMergeface.h"
10 | #import "FCPPFaceDetect.h"
11 |
12 |
13 | @implementation FCPPMergeface
14 | {
15 | FCPPMergeface* _fuseImageObj;
16 | }
17 |
18 | -(instancetype)initWithImage:(UIImage*)image withImageRectangle:(NSString*)ImageRectangle{
19 | if (self = [super initWithImage:image]) {
20 | self.image = [image fixImageWithMaxSize:CGSizeMake(4096, 4096)];
21 | self.imageRectangle = ImageRectangle;
22 | }
23 | return self;
24 | }
25 |
26 | -(void)mergeWithFuseImageObj:(FCPPMergeface*)fuseImageObj withMergeRate:(int)mergeRate wtihCompletion:(void(^)(id info,NSError *error))completion{
27 | NSString *url = [NSString stringWithFormat:@"%@%@",IMAGE_MERGEFACE,MERGEFACE];
28 | NSMutableDictionary *param = [NSMutableDictionary dictionary];
29 | _fuseImageObj = fuseImageObj;
30 | if (self.image) {
31 | NSString *baseStr = self.image.base64String;
32 | [param setObject:baseStr forKey:@"template_base64"];
33 | }else if (self.imageUrl) {
34 | [param setObject:self.imageUrl forKey:@"template_url"];
35 | }
36 |
37 | if (fuseImageObj.image) {
38 | NSString *baseStr = fuseImageObj.image.base64String;
39 | [param setObject:baseStr forKey:@"merge_base64"];
40 | }else if (fuseImageObj.imageUrl) {
41 | [param setObject:self.imageUrl forKey:@"merge_url"];
42 | }
43 |
44 | if (fuseImageObj.imageRectangle) {
45 | [param setObject:fuseImageObj.imageRectangle forKey:@"merge_rectangle"];
46 | }
47 | if (mergeRate>=0&&mergeRate<=100) {
48 | [param setObject:@(mergeRate) forKey:@"merge_rate"];//默认为50
49 | }
50 | //模板图人脸框位置是必传参数,如果有直接走融合接口,如果没有此参数走else先进行人人脸检测
51 | if (self.imageRectangle) {
52 | [param setObject:self.imageRectangle forKey:@"template_rectangle"];
53 | [FCPPApi POST:url param:param completion:completion];
54 | }else{
55 | [self beginDetechWtihUrl:url withParam:param withCompletion:completion];
56 | }
57 | }
58 | #pragma mark- private method
59 | -(void)beginDetechWtihUrl:(NSString*)url withParam:(NSDictionary*)param withCompletion:(void(^)(id info,NSError *error))completion{
60 | if (!param) {
61 | param = [NSMutableDictionary new];
62 | }
63 | FCPPFaceDetect *templateDetect = [[FCPPFaceDetect alloc] initWithImage:self.image];
64 | [templateDetect detectFaceWithReturnLandmark:YES attributes:nil completion:^(id info, NSError *error) {
65 | if (info) {
66 | NSArray *templateArray = info[@"faces"];
67 | [param setValue:[self getRectangle:templateArray] forKey:@"template_rectangle"];
68 | if (templateArray.count) {
69 | //检测检融合图人脸
70 | FCPPFaceDetect *targetDetect = [[FCPPFaceDetect alloc] initWithImage:_fuseImageObj.image];
71 | [targetDetect detectFaceWithReturnLandmark:YES attributes:nil completion:^(id info, NSError *error) {
72 | if (info) {
73 | NSArray *targetArray = info[@"faces"];
74 | [param setValue:[self getRectangle:targetArray] forKey:@"merge_rectangle"];
75 | if (targetArray.count) {
76 | [FCPPApi POST:url param:param completion:completion];
77 | }else{
78 | completion(@"融合图没有识别到人脸",nil);
79 | }
80 | }else{
81 | completion(@"融合图没有识别到人脸",nil);
82 | }
83 | }];
84 |
85 | }else{
86 | completion(@"模板图没有识别到人脸",nil);
87 | }
88 | }else{
89 | completion(nil,error);
90 | }
91 | }];
92 | }
93 |
94 | -(NSString*)getRectangle:(NSArray*)array{
95 | NSString* rectangle = nil;
96 | for (NSDictionary *dic in array) {
97 | NSDictionary *rect = dic[@"face_rectangle"];
98 | rectangle = [NSString stringWithFormat:@"%@,%@,%@,%@",rect[@"top"],rect[@"left"],rect[@"width"],rect[@"height"]];
99 | }
100 | return rectangle;
101 | }
102 |
103 | @end
104 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/FCOCRDriverLicenceViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // FCOCRDriverLicenceViewController.m
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/7/19.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCOCRDriverLicenceViewController.h"
10 | #import "NSMutableAttributedString+FCExtension.h"
11 |
12 | @interface FCOCRDriverLicenceViewController ()
13 |
14 | @end
15 |
16 | @implementation FCOCRDriverLicenceViewController
17 |
18 | - (void)viewDidLoad {
19 | [super viewDidLoad];
20 | [self handleImage:self.image];
21 | }
22 |
23 | - (void)handleImage:(UIImage *)image{
24 | FCPPOCR *ocr = [[FCPPOCR alloc] initWithImage:image];
25 | self.imageView.image = ocr.image;
26 | NSLog(@"%f",ocr.image.imageData.length/1024.0/1024.0);
27 | MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
28 | [ocr ocrDriverLicenseCompletion:^(id info, NSError *error) {
29 | [hud hideAnimated:YES];
30 | self.tableView.contentOffset = CGPointMake(0, 0);
31 | [self.dataArray removeAllObjects];
32 | if (info) {
33 | [self showResult:info];
34 | NSArray *array = info[@"cards"];
35 | [self.dataArray addObjectsFromArray:array];
36 | }else{
37 | [self showError:error];
38 | }
39 | [self.tableView reloadData];
40 | }];
41 | }
42 | #pragma mark- tableViewDelegate
43 |
44 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
45 | static NSString *cellId = @"driverLicenseCellllId";
46 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fccellId"];
47 | if (cell == nil) {
48 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
49 | cell.textLabel.numberOfLines = 0;
50 | }
51 | NSDictionary *dic = self.dataArray[indexPath.row];
52 |
53 | NSMutableAttributedString *detailStr = [[NSMutableAttributedString alloc] init];
54 | BOOL isFront = [dic[@"side"] isEqualToString:@"front"];
55 |
56 | if (isFront) {
57 | [detailStr appendBoldString:@"姓名: "];
58 | [detailStr appendLightString:dic[@"name"]];
59 | [detailStr appendBoldString:@"\n性别: "];
60 | [detailStr appendLightString:dic[@"gender"]];
61 | [detailStr appendBoldString:@"\n国籍: "];
62 | [detailStr appendLightString:dic[@"nationality"]];
63 | [detailStr appendBoldString:@"\n生日: "];
64 | [detailStr appendLightString:dic[@"birthday"]];
65 | [detailStr appendBoldString:@"\n住址: "];
66 | [detailStr appendLightString:dic[@"address"]];
67 | [detailStr appendBoldString:@"\n初次领证时间: "];
68 | [detailStr appendLightString:dic[@"issue_date"]];
69 | [detailStr appendBoldString:@"\n有效期限: "];
70 | [detailStr appendLightString:dic[@"valid_date"]];
71 | [detailStr appendBoldString:@"\n准驾车型: "];
72 | [detailStr appendLightString:dic[@"class"]];
73 | [detailStr appendBoldString:@"\n驾驶证号: "];
74 | [detailStr appendLightString:dic[@"license_number"]];
75 | [detailStr appendBoldString:@"\n签发机关: "];
76 | [detailStr appendLightString:dic[@"issued_by"]];
77 | [detailStr appendBoldString:@"\n证件正反面: "];
78 | [detailStr appendLightString:@"正面"];
79 | }
80 | cell.textLabel.attributedText = detailStr;
81 |
82 | return cell;
83 | }
84 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
85 | return 290;
86 | }
87 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
88 | return self.dataArray.count;
89 | }
90 |
91 | - (void)didReceiveMemoryWarning {
92 | [super didReceiveMemoryWarning];
93 | // Dispose of any resources that can be recreated.
94 | }
95 |
96 | /*
97 | #pragma mark - Navigation
98 |
99 | // In a storyboard-based application, you will often want to do a little preparation before navigation
100 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
101 | // Get the new view controller using [segue destinationViewController].
102 | // Pass the selected object to the new view controller.
103 | }
104 | */
105 |
106 | @end
107 |
--------------------------------------------------------------------------------
/SDWebImage/SDWebImagePrefetcher.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import
10 | #import "SDWebImageManager.h"
11 |
12 | @class SDWebImagePrefetcher;
13 |
14 | @protocol SDWebImagePrefetcherDelegate
15 |
16 | @optional
17 |
18 | /**
19 | * Called when an image was prefetched.
20 | *
21 | * @param imagePrefetcher The current image prefetcher
22 | * @param imageURL The image url that was prefetched
23 | * @param finishedCount The total number of images that were prefetched (successful or not)
24 | * @param totalCount The total number of images that were to be prefetched
25 | */
26 | - (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didPrefetchURL:(NSURL *)imageURL finishedCount:(NSUInteger)finishedCount totalCount:(NSUInteger)totalCount;
27 |
28 | /**
29 | * Called when all images are prefetched.
30 | * @param imagePrefetcher The current image prefetcher
31 | * @param totalCount The total number of images that were prefetched (whether successful or not)
32 | * @param skippedCount The total number of images that were skipped
33 | */
34 | - (void)imagePrefetcher:(SDWebImagePrefetcher *)imagePrefetcher didFinishWithTotalCount:(NSUInteger)totalCount skippedCount:(NSUInteger)skippedCount;
35 |
36 | @end
37 |
38 | typedef void(^SDWebImagePrefetcherProgressBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfTotalUrls);
39 | typedef void(^SDWebImagePrefetcherCompletionBlock)(NSUInteger noOfFinishedUrls, NSUInteger noOfSkippedUrls);
40 |
41 | /**
42 | * Prefetch some URLs in the cache for future use. Images are downloaded in low priority.
43 | */
44 | @interface SDWebImagePrefetcher : NSObject
45 |
46 | /**
47 | * The web image manager
48 | */
49 | @property (strong, nonatomic, readonly) SDWebImageManager *manager;
50 |
51 | /**
52 | * Maximum number of URLs to prefetch at the same time. Defaults to 3.
53 | */
54 | @property (nonatomic, assign) NSUInteger maxConcurrentDownloads;
55 |
56 | /**
57 | * SDWebImageOptions for prefetcher. Defaults to SDWebImageLowPriority.
58 | */
59 | @property (nonatomic, assign) SDWebImageOptions options;
60 |
61 | /**
62 | * Queue options for Prefetcher. Defaults to Main Queue.
63 | */
64 | @property (nonatomic, assign) dispatch_queue_t prefetcherQueue;
65 |
66 | @property (weak, nonatomic) id delegate;
67 |
68 | /**
69 | * Return the global image prefetcher instance.
70 | */
71 | + (SDWebImagePrefetcher *)sharedImagePrefetcher;
72 |
73 | /**
74 | * Allows you to instantiate a prefetcher with any arbitrary image manager.
75 | */
76 | - (id)initWithImageManager:(SDWebImageManager *)manager;
77 |
78 | /**
79 | * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching,
80 | * currently one image is downloaded at a time,
81 | * and skips images for failed downloads and proceed to the next image in the list
82 | *
83 | * @param urls list of URLs to prefetch
84 | */
85 | - (void)prefetchURLs:(NSArray *)urls;
86 |
87 | /**
88 | * Assign list of URLs to let SDWebImagePrefetcher to queue the prefetching,
89 | * currently one image is downloaded at a time,
90 | * and skips images for failed downloads and proceed to the next image in the list
91 | *
92 | * @param urls list of URLs to prefetch
93 | * @param progressBlock block to be called when progress updates;
94 | * first parameter is the number of completed (successful or not) requests,
95 | * second parameter is the total number of images originally requested to be prefetched
96 | * @param completionBlock block to be called when prefetching is completed
97 | * first param is the number of completed (successful or not) requests,
98 | * second parameter is the number of skipped requests
99 | */
100 | - (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock;
101 |
102 | /**
103 | * Remove and cancel queued list
104 | */
105 | - (void)cancelPrefetching;
106 |
107 |
108 | @end
109 |
--------------------------------------------------------------------------------
/FaceSDKDemo/Controller/FCOCRVehicleLicenseViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // FCOCRVehicleLicenseViewController.m
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/7/19.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCOCRVehicleLicenseViewController.h"
10 | #import "NSMutableAttributedString+FCExtension.h"
11 |
12 | @interface FCOCRVehicleLicenseViewController ()
13 |
14 | @end
15 |
16 | @implementation FCOCRVehicleLicenseViewController
17 |
18 | - (void)viewDidLoad {
19 | [super viewDidLoad];
20 | [self handleImage:self.image];
21 | }
22 |
23 | - (void)handleImage:(UIImage *)image{
24 | FCPPOCR *ocr = [[FCPPOCR alloc] initWithImage:image];
25 | self.imageView.image = ocr.image;
26 | NSLog(@"%f",ocr.image.imageData.length/1024.0/1024.0);
27 | MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
28 | [ocr ocrVehicleLicenseCompletion:^(id info, NSError *error) {
29 | [hud hideAnimated:YES];
30 | self.tableView.contentOffset = CGPointMake(0, 0);
31 | [self.dataArray removeAllObjects];
32 | if (info) {
33 | [self showResult:info];
34 | NSArray *array = info[@"cards"];
35 | [self.dataArray addObjectsFromArray:array];
36 | }else{
37 | [self showError:error];
38 | }
39 | [self.tableView reloadData];
40 | }];
41 | }
42 | #pragma mark- tableViewDelegate
43 |
44 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
45 | static NSString *cellId = @"vehicleCellllId";
46 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"fccellId"];
47 | if (cell == nil) {
48 | cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
49 | cell.textLabel.numberOfLines = 0;
50 | }
51 | NSDictionary *dic = self.dataArray[indexPath.row];
52 |
53 | NSMutableAttributedString *detailStr = [[NSMutableAttributedString alloc] init];
54 | BOOL isFront = [dic[@"side"] isEqualToString:@"front"];
55 |
56 | if (isFront) {
57 | [detailStr appendBoldString:@"号牌号码: "];
58 | [detailStr appendLightString:dic[@"plate_no"]];
59 | [detailStr appendBoldString:@"\n车辆类型: "];
60 | [detailStr appendLightString:dic[@"vehicle_type"]];
61 | [detailStr appendBoldString:@"\n所有人: "];
62 | [detailStr appendLightString:dic[@"owner"]];
63 | [detailStr appendBoldString:@"\n住址: "];
64 | [detailStr appendLightString:dic[@"address"]];
65 | [detailStr appendBoldString:@"\n使用性质: "];
66 | [detailStr appendLightString:dic[@"use_character"]];
67 | [detailStr appendBoldString:@"\n品牌型号: "];
68 | [detailStr appendLightString:dic[@"model"]];
69 | [detailStr appendBoldString:@"\n车辆识别代码: "];
70 | [detailStr appendLightString:dic[@"vin"]];
71 | [detailStr appendBoldString:@"\n发动机号码: "];
72 | [detailStr appendLightString:dic[@"engine_no"]];
73 | [detailStr appendBoldString:@"\n注册日期: "];
74 | [detailStr appendLightString:dic[@"register_date"]];
75 | [detailStr appendBoldString:@"\n发证日期: "];
76 | [detailStr appendLightString:dic[@"issue_date"]];
77 | [detailStr appendBoldString:@"\n签证机关: "];
78 | [detailStr appendLightString:dic[@"issued_by"]];
79 | [detailStr appendBoldString:@"\n证件正反面: "];
80 | [detailStr appendLightString:@"正面"];
81 | }
82 | cell.textLabel.attributedText = detailStr;
83 |
84 | return cell;
85 | }
86 |
87 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
88 | return 290;
89 | }
90 |
91 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
92 | return self.dataArray.count;
93 | }
94 |
95 | - (void)didReceiveMemoryWarning {
96 | [super didReceiveMemoryWarning];
97 | // Dispose of any resources that can be recreated.
98 | }
99 |
100 | /*
101 | #pragma mark - Navigation
102 |
103 | // In a storyboard-based application, you will often want to do a little preparation before navigation
104 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
105 | // Get the new view controller using [segue destinationViewController].
106 | // Pass the selected object to the new view controller.
107 | }
108 | */
109 |
110 | @end
111 |
--------------------------------------------------------------------------------
/FCPPSDK/FCPPFaceSet.h:
--------------------------------------------------------------------------------
1 | //
2 | // FCPPFaceSetManager.h
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/6/21.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "FCPPApi.h"
11 |
12 | @interface FCPPFaceSet : NSObject
13 |
14 | /**
15 | * faceSet的唯一标识,由系统返回
16 | * The id of a faceSet which returned by api.
17 | */
18 | @property (copy , nonatomic) NSString *faceset_token;
19 |
20 | /**
21 | * 用户提供的FaceSet唯一标识
22 | * User-defined id of Faceset
23 | */
24 | @property (copy , nonatomic) NSString *outer_id;
25 |
26 | - (instancetype)initWithFaceSetToken:(NSString *)faceSetToken;
27 |
28 | - (instancetype)initWithOuterId:(NSString *)outerId;
29 |
30 | /**
31 | 创建一个人脸的集合FaceSet,用于存储人脸标识face_token,用于后续的搜索功能.
32 | 中文文档: https://console.faceplusplus.com.cn/documents/4888391
33 |
34 | Create a face collection to store face_token. The collection will be used in the search operation.
35 | English document:https://console.faceplusplus.com/documents/6329329
36 |
37 | @param displayName 人脸集合的名字,256个字符,不能包括字符^@,&=*'"
38 | @param outerId 自定义唯一的FaceSet标识,可以用来管理FaceSet对象。最长255个字符,不能包括字符^@,&=*'"
39 | @param tags FaceSet自定义标签组成的字符串,用来对FaceSet分组。最长255个字符,多个tag用逗号分隔,每个tag不能包括字符^@,&=*'"
40 | @param tokens 人脸标识face_token,可以是一个或者多个,用逗号分隔。最多不超过5个face_token,会被直接加入faceset中
41 | @param userData 自定义用户信息,不大于16KB,不能包括字符^@,&=*'"
42 | @param forceMerge 在传入outer_id的情况下,如果outer_id已经存在,是否将face_token加入已经存在的FaceSet中,0:不将face_tokens加入已存在的FaceSet中,直接返回FACESET_EXIST错误
43 | @param completion 回调
44 | */
45 | + (void)createFaceSetWithDisplayName:(NSString *)displayName outerId:(NSString *)outerId tgas:(NSArray *)tags faceTokens:(NSArray *)tokens userData:(NSString *)userData forceMerge:(BOOL)forceMerge completion:(void(^)(id info,NSError *error))completion;
46 |
47 |
48 | /**
49 | 获取指定tag的faceset,如果为空,则返回所有faceset
50 | 中文文档: https://console.faceplusplus.com.cn/documents/4888397
51 |
52 | get the faceset by tags,if tags == nil, return all the facesets
53 | 英文文档: https://console.faceplusplus.com/documents/6329430
54 |
55 | @param tags faceset的tag
56 | @param completion 结果回调
57 | */
58 | + (void)getFaceSetsWithTags:(NSArray *)tags completion:(void(^)(id info,NSError *error))completion;
59 |
60 | /**
61 | 添加多个faceToken到faceset中
62 | 中文文档: https://console.faceplusplus.com.cn/documents/4888389
63 |
64 | add several faceTokens to the faceset
65 | English document: https://console.faceplusplus.com/documents/6329371
66 |
67 | @param tokens faceTokens
68 | @param completion 结果回调
69 | */
70 | - (void)addFaceTokens:(NSArray *)tokens completion:(void(^)(id info,NSError *error))completion;
71 |
72 |
73 | /**
74 | 从faceset中移除faceTokens
75 | 中文文档: https://console.faceplusplus.com.cn/documents/4888399
76 |
77 | remove faceTokens from faceset
78 | English document: https://console.faceplusplus.com/documents/6329376
79 |
80 | @param tokens faceTokens
81 | @param completion 结果回调
82 | */
83 | - (void)removeFaceToken:(NSArray *)tokens completion:(void(^)(id info,NSError *error))completion;
84 |
85 |
86 | /**
87 | 更新一个人脸集合的属性
88 | 中文文档: https://console.faceplusplus.com.cn/documents/4888401
89 |
90 | update a faceset with some attributes such as new_outer_id,display_name,user_data,tags
91 | English document: https://console.faceplusplus.com/documents/6329383
92 |
93 | @param dic 需要更新的属性字典,key为 @"new_outer_id",@"display_name",@"user_data",tags其中的一个或者多个
94 | @param completion 结果回调
95 | */
96 | - (void)updateFaceSetWithDic:(NSDictionary *)dic completion:(void(^)(id info,NSError *error))completion;
97 |
98 |
99 | /**
100 | 获取一个FaceSet的所有信息
101 | 中文文档: https://console.faceplusplus.com.cn/documents/4888395
102 |
103 | Get details about a FaceSet.
104 | English document: https://console.faceplusplus.com/documents/6329388
105 |
106 | @param completion 结果回调
107 | */
108 | - (void)getDetailCompletion:(void(^)(id info,NSError *error))completion;
109 |
110 |
111 | /**
112 | 删除一个人脸集合
113 | 中文文档: https://console.faceplusplus.com.cn/documents/4888393
114 |
115 | delete a faceset
116 | English document: https://console.faceplusplus.com/documents/6329394
117 |
118 | @param checkEmpty 删除时是否检查FaceSet中是否存在face_token,默认值为1,FaceSet中存在face_token则不能删除.
119 | @param completion 结果回调
120 | */
121 | - (void)deleteFaceSetCheckEmpty:(BOOL)checkEmpty completion:(void(^)(id info,NSError *error))completion;
122 |
123 |
124 | @end
125 |
--------------------------------------------------------------------------------
/FCPPSDK/FCPPApi.m:
--------------------------------------------------------------------------------
1 | //
2 | // FCPPApi.m
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/6/16.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCPPApi.h"
10 | #import "AFNetworking.h"
11 |
12 | @interface FCPPApi()
13 |
14 | @end
15 |
16 | @implementation FCPPApi
17 |
18 | - (instancetype)initWithImage:(UIImage *)image{
19 | if (self = [super init]) {
20 | //留给子类重写
21 | }
22 | return self;
23 | }
24 |
25 | - (instancetype)initWithImageUrl:(NSString *)imageUrl{
26 | if (self = [super init]) {
27 | self.imageUrl = imageUrl;
28 | }
29 | return self;
30 | }
31 |
32 | + (void)POST:(NSString *)url param:(NSDictionary *)dic completion:(void(^)(id info,NSError *error))completion{
33 |
34 | if (kApiKey.length == 0 || kApiSecret.length == 0) {
35 | NSDictionary *userInfo = @{@"reason" : @"please config a apikey and secret"};
36 | NSLog(@"%@",userInfo);
37 | if (completion) {
38 | NSError *error = [NSError errorWithDomain:url code:401 userInfo:userInfo];
39 | completion(nil,error);
40 | return;
41 | }
42 | }
43 |
44 | NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:dic];
45 | [param setValue:kApiKey forKey:@"api_key"];
46 | [param setValue:kApiSecret forKey:@"api_secret"];
47 |
48 | //fileData抽取出来
49 | NSMutableDictionary *fileDic = [NSMutableDictionary dictionary];
50 |
51 | [dic enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
52 | if ([key hasPrefix:@"image_file"]) {
53 | [param removeObjectForKey:key];
54 | if ([obj isKindOfClass:[NSData class]]) {
55 | [fileDic setObject:obj forKey:key];
56 | }
57 | }
58 | }];
59 |
60 | NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:url parameters:param constructingBodyWithBlock:^(id formData) {
61 | [fileDic enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
62 | [formData appendPartWithFileData:obj name:key fileName:key mimeType:@"image/jpeg"];
63 | }];
64 | } error:nil];
65 |
66 | AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
67 |
68 | NSURLSessionUploadTask *uploadTask;
69 | uploadTask = [manager
70 | uploadTaskWithStreamedRequest:request
71 | progress:^(NSProgress * _Nonnull uploadProgress) {
72 | }
73 | completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
74 | if(error == nil){
75 | if (completion) {
76 | completion(responseObject,nil);
77 | }
78 | }else{
79 | if (completion) {
80 | NSData *errorData = error.userInfo[@"com.alamofire.serialization.response.error.data"];
81 | if (errorData) {
82 | NSString *errorStr = [[NSString alloc] initWithData:errorData encoding:NSUTF8StringEncoding];
83 | NSLog(@"%@",errorStr);
84 | }else{
85 | NSLog(@"error: %@",error);
86 | }
87 | completion(nil,error);
88 | }
89 | }
90 | }];
91 |
92 | [uploadTask resume];
93 |
94 |
95 | // AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
96 | // [manager POST:url parameters:param progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
97 | // if (completion) {
98 | // completion(responseObject,nil);
99 | // }
100 | // } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
101 | // if (completion) {
102 | // NSData *errorData = error.userInfo[@"com.alamofire.serialization.response.error.data"];
103 | // if (errorData) {
104 | // NSString *errorStr = [[NSString alloc] initWithData:errorData encoding:NSUTF8StringEncoding];
105 | // NSLog(@"%@",errorStr);
106 | // }else{
107 | // NSLog(@"%@",error);
108 | // }
109 | // completion(nil,error);
110 | // }
111 | // }];
112 | }
113 | @end
114 |
--------------------------------------------------------------------------------
/AFNetworking/UIKit+AFNetworking/UIWebView+AFNetworking.h:
--------------------------------------------------------------------------------
1 | // UIWebView+AFNetworking.h
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 |
24 | #import
25 |
26 | #if TARGET_OS_IOS
27 |
28 | #import
29 |
30 | NS_ASSUME_NONNULL_BEGIN
31 |
32 | @class AFHTTPSessionManager;
33 |
34 | /**
35 | This category adds methods to the UIKit framework's `UIWebView` class. The methods in this category provide increased control over the request cycle, including progress monitoring and success / failure handling.
36 |
37 | @discussion When using these category methods, make sure to assign `delegate` for the web view, which implements `–webView:shouldStartLoadWithRequest:navigationType:` appropriately. This allows for tapped links to be loaded through AFNetworking, and can ensure that `canGoBack` & `canGoForward` update their values correctly.
38 | */
39 | @interface UIWebView (AFNetworking)
40 |
41 | /**
42 | The session manager used to download all requests.
43 | */
44 | @property (nonatomic, strong) AFHTTPSessionManager *sessionManager;
45 |
46 | /**
47 | Asynchronously loads the specified request.
48 |
49 | @param request A URL request identifying the location of the content to load. This must not be `nil`.
50 | @param progress A progress object monitoring the current download progress.
51 | @param success A block object to be executed when the request finishes loading successfully. This block returns the HTML string to be loaded by the web view, and takes two arguments: the response, and the response string.
52 | @param failure A block object to be executed when the data task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a single argument: the error that occurred.
53 | */
54 | - (void)loadRequest:(NSURLRequest *)request
55 | progress:(NSProgress * _Nullable __autoreleasing * _Nullable)progress
56 | success:(nullable NSString * (^)(NSHTTPURLResponse *response, NSString *HTML))success
57 | failure:(nullable void (^)(NSError *error))failure;
58 |
59 | /**
60 | Asynchronously loads the data associated with a particular request with a specified MIME type and text encoding.
61 |
62 | @param request A URL request identifying the location of the content to load. This must not be `nil`.
63 | @param MIMEType The MIME type of the content. Defaults to the content type of the response if not specified.
64 | @param textEncodingName The IANA encoding name, as in `utf-8` or `utf-16`. Defaults to the response text encoding if not specified.
65 | @param progress A progress object monitoring the current download progress.
66 | @param success A block object to be executed when the request finishes loading successfully. This block returns the data to be loaded by the web view and takes two arguments: the response, and the downloaded data.
67 | @param failure A block object to be executed when the data task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a single argument: the error that occurred.
68 | */
69 | - (void)loadRequest:(NSURLRequest *)request
70 | MIMEType:(nullable NSString *)MIMEType
71 | textEncodingName:(nullable NSString *)textEncodingName
72 | progress:(NSProgress * _Nullable __autoreleasing * _Nullable)progress
73 | success:(nullable NSData * (^)(NSHTTPURLResponse *response, NSData *data))success
74 | failure:(nullable void (^)(NSError *error))failure;
75 |
76 | @end
77 |
78 | NS_ASSUME_NONNULL_END
79 |
80 | #endif
81 |
--------------------------------------------------------------------------------
/SDWebImage/SDWebImageDownloaderOperation.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import
10 | #import "SDWebImageDownloader.h"
11 | #import "SDWebImageOperation.h"
12 |
13 | extern NSString *const SDWebImageDownloadStartNotification;
14 | extern NSString *const SDWebImageDownloadReceiveResponseNotification;
15 | extern NSString *const SDWebImageDownloadStopNotification;
16 | extern NSString *const SDWebImageDownloadFinishNotification;
17 |
18 | @interface SDWebImageDownloaderOperation : NSOperation
19 |
20 | /**
21 | * The request used by the operation's task.
22 | */
23 | @property (strong, nonatomic, readonly) NSURLRequest *request;
24 |
25 | /**
26 | * The operation's task
27 | */
28 | @property (strong, nonatomic, readonly) NSURLSessionTask *dataTask;
29 |
30 |
31 | @property (assign, nonatomic) BOOL shouldDecompressImages;
32 |
33 | /**
34 | * Was used to determine whether the URL connection should consult the credential storage for authenticating the connection.
35 | * @deprecated Not used for a couple of versions
36 | */
37 | @property (nonatomic, assign) BOOL shouldUseCredentialStorage __deprecated_msg("Property deprecated. Does nothing. Kept only for backwards compatibility");
38 |
39 | /**
40 | * The credential used for authentication challenges in `-connection:didReceiveAuthenticationChallenge:`.
41 | *
42 | * This will be overridden by any shared credentials that exist for the username or password of the request URL, if present.
43 | */
44 | @property (nonatomic, strong) NSURLCredential *credential;
45 |
46 | /**
47 | * The SDWebImageDownloaderOptions for the receiver.
48 | */
49 | @property (assign, nonatomic, readonly) SDWebImageDownloaderOptions options;
50 |
51 | /**
52 | * The expected size of data.
53 | */
54 | @property (assign, nonatomic) NSInteger expectedSize;
55 |
56 | /**
57 | * The response returned by the operation's connection.
58 | */
59 | @property (strong, nonatomic) NSURLResponse *response;
60 |
61 | /**
62 | * Initializes a `SDWebImageDownloaderOperation` object
63 | *
64 | * @see SDWebImageDownloaderOperation
65 | *
66 | * @param request the URL request
67 | * @param session the URL session in which this operation will run
68 | * @param options downloader options
69 | * @param progressBlock the block executed when a new chunk of data arrives.
70 | * @note the progress block is executed on a background queue
71 | * @param completedBlock the block executed when the download is done.
72 | * @note the completed block is executed on the main queue for success. If errors are found, there is a chance the block will be executed on a background queue
73 | * @param cancelBlock the block executed if the download (operation) is cancelled
74 | *
75 | * @return the initialized instance
76 | */
77 | - (id)initWithRequest:(NSURLRequest *)request
78 | inSession:(NSURLSession *)session
79 | options:(SDWebImageDownloaderOptions)options
80 | progress:(SDWebImageDownloaderProgressBlock)progressBlock
81 | completed:(SDWebImageDownloaderCompletedBlock)completedBlock
82 | cancelled:(SDWebImageNoParamsBlock)cancelBlock;
83 |
84 | /**
85 | * Initializes a `SDWebImageDownloaderOperation` object
86 | *
87 | * @see SDWebImageDownloaderOperation
88 | *
89 | * @param request the URL request
90 | * @param options downloader options
91 | * @param progressBlock the block executed when a new chunk of data arrives.
92 | * @note the progress block is executed on a background queue
93 | * @param completedBlock the block executed when the download is done.
94 | * @note the completed block is executed on the main queue for success. If errors are found, there is a chance the block will be executed on a background queue
95 | * @param cancelBlock the block executed if the download (operation) is cancelled
96 | *
97 | * @return the initialized instance. The operation will run in a separate session created for this operation
98 | */
99 | - (id)initWithRequest:(NSURLRequest *)request
100 | options:(SDWebImageDownloaderOptions)options
101 | progress:(SDWebImageDownloaderProgressBlock)progressBlock
102 | completed:(SDWebImageDownloaderCompletedBlock)completedBlock
103 | cancelled:(SDWebImageNoParamsBlock)cancelBlock
104 | __deprecated_msg("Method deprecated. Use `initWithRequest:inSession:options:progress:completed:cancelled`");
105 |
106 | @end
107 |
--------------------------------------------------------------------------------
/FCPPSDK/FCPPFace.m:
--------------------------------------------------------------------------------
1 | //
2 | // FCPPFaceManager.m
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/6/20.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCPPFace.h"
10 | #import "FCPPConfig.h"
11 |
12 | @implementation FCPPFace
13 |
14 | - (instancetype)initWithFaceToken:(NSString *)faceToken{
15 | if (self = [super init]) {
16 | self.faceToken = faceToken;
17 | }
18 | return self;
19 | }
20 | - (instancetype)initWithImage:(UIImage *)image{
21 | if (self = [super initWithImage:image]) {
22 | self.image = [image fixImageWithMaxSize:CGSizeMake(4096, 4096)];
23 | }
24 | return self;
25 | }
26 |
27 |
28 | - (void)compareFaceWithOther:(FCPPFace *)face completion:(void(^)(id info,NSError *error))completion{
29 | NSString *url = [NSString stringWithFormat:@"%@/%@",FACE_WEB_BASE,FACE_COMPARE];
30 | NSMutableDictionary *param = [NSMutableDictionary dictionary];
31 |
32 | if (self.faceToken){
33 | [param setObject:self.faceToken forKey:@"face_token1"];
34 | }else if (self.image){
35 | NSString *baseStr = self.image.base64String;
36 | [param setObject:baseStr forKey:@"image_base64_1"];
37 | }else if (self.imageUrl) {
38 | [param setObject:self.imageUrl forKey:@"image_url1"];
39 | }
40 |
41 | if (face.faceToken){
42 | [param setObject:face.faceToken forKey:@"face_token2"];
43 | }else if (face.image){
44 | NSString *baseStr = face.image.base64String;
45 | [param setObject:baseStr forKey:@"image_base64_2"];
46 | }else if (face.imageUrl) {
47 | [param setObject:face.imageUrl forKey:@"image_url2"];
48 | }
49 |
50 | [FCPPApi POST:url param:param completion:completion];
51 | }
52 |
53 | - (void)searchFromFaceSet:(FCPPFaceSet *)faceSet returnCount:(int)returnCount completion:(void(^)(id info,NSError *error))completion{
54 | NSString *url = [NSString stringWithFormat:@"%@/%@",FACE_WEB_BASE,FACE_SEARCH];
55 | NSMutableDictionary *param = [NSMutableDictionary dictionary];
56 |
57 | if (self.faceToken){
58 | [param setObject:self.faceToken forKey:@"face_token"];
59 | }else if (self.image){
60 | NSString *baseStr = self.image.base64String;
61 | [param setObject:baseStr forKey:@"image_base64"];
62 | }else if (self.imageUrl) {
63 | [param setObject:self.imageUrl forKey:@"image_url"];
64 | }
65 |
66 | if (returnCount > 0 && returnCount < 6) {
67 | [param setObject:@(returnCount) forKey:@"return_result_count"];
68 | }
69 |
70 | if (faceSet.faceset_token) {
71 | [param setObject:faceSet.faceset_token forKey:@"faceset_token"];
72 | }else if (faceSet.outer_id){
73 | [param setObject:faceSet.outer_id forKey:@"outer_id"];
74 | }
75 |
76 | [FCPPApi POST:url param:param completion:completion];
77 | }
78 |
79 | + (void)analyzeFaceTokens:(NSArray *)tokens return_landmark:(BOOL)return_landmark attribute:(NSArray *)attributes completion:(void(^)(id info,NSError *error))completion{
80 | NSString *url = [NSString stringWithFormat:@"%@/%@/%@",FACE_WEB_BASE,FACETOEKN,FACETOEKN_ANALYZE];
81 | NSMutableDictionary *param = [NSMutableDictionary dictionary];
82 | NSString *tokenStr = [tokens componentsJoinedByString:@","];
83 |
84 | if (tokenStr.length) {
85 | [param setObject:tokenStr forKey:@"face_tokens"];
86 | }else{
87 | NSLog(@"faceTokens can not be nil");
88 | }
89 |
90 | NSNumber *landmark = return_landmark ? @(1) : @(0);
91 | [param setObject:landmark forKey:@"return_landmark"];
92 |
93 | NSString *att = [attributes componentsJoinedByString:@","];
94 | if (att.length) {
95 | [param setObject:att.copy forKey:@"return_attributes"];
96 | }
97 |
98 | [FCPPApi POST:url param:param completion:completion];
99 | }
100 |
101 | + (void)setUserId:(NSString *)userid toFaceToken:(NSString *)token completion:(void(^)(id info,NSError *error))completion{
102 | NSString *url = [NSString stringWithFormat:@"%@/%@/%@",FACE_WEB_BASE,FACETOEKN,FACETOEKN_SET_USERID];
103 | NSMutableDictionary *param = [NSMutableDictionary dictionary];
104 | if (userid.length == 0 || token.length == 0) {
105 | NSLog(@"userid and token can not be nil");
106 | }
107 |
108 | [param setObject:userid forKey:@"user_id"];
109 | [param setObject:token forKey:@"face_token"];
110 |
111 | [FCPPApi POST:url param:param completion:completion];
112 | }
113 |
114 | + (void)getDetailWithToken:(NSString *)token completion:(void(^)(id info,NSError *error))completion{
115 | NSString *url = [NSString stringWithFormat:@"%@/%@/%@",FACE_WEB_BASE,FACETOEKN,FACETOEKN_GET_DETAIL];
116 | NSMutableDictionary *param = [NSMutableDictionary dictionary];
117 | if (token.length == 0) {
118 | NSLog(@"token can not be nil");
119 | }else{
120 | [param setObject:token forKey:@"face_token"];
121 | }
122 |
123 | [FCPPApi POST:url param:param completion:completion];
124 | }
125 | @end
126 |
--------------------------------------------------------------------------------
/AFNetworking/UIKit+AFNetworking/UIRefreshControl+AFNetworking.m:
--------------------------------------------------------------------------------
1 | // UIRefreshControl+AFNetworking.m
2 | //
3 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
4 | //
5 | // Permission is hereby granted, free of charge, to any person obtaining a copy
6 | // of this software and associated documentation files (the "Software"), to deal
7 | // in the Software without restriction, including without limitation the rights
8 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | // copies of the Software, and to permit persons to whom the Software is
10 | // furnished to do so, subject to the following conditions:
11 | //
12 | // The above copyright notice and this permission notice shall be included in
13 | // all copies or substantial portions of the Software.
14 | //
15 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | // THE SOFTWARE.
22 |
23 | #import "UIRefreshControl+AFNetworking.h"
24 | #import
25 |
26 | #if TARGET_OS_IOS
27 |
28 | #import "AFURLSessionManager.h"
29 |
30 | @interface AFRefreshControlNotificationObserver : NSObject
31 | @property (readonly, nonatomic, weak) UIRefreshControl *refreshControl;
32 | - (instancetype)initWithActivityRefreshControl:(UIRefreshControl *)refreshControl;
33 |
34 | - (void)setRefreshingWithStateOfTask:(NSURLSessionTask *)task;
35 |
36 | @end
37 |
38 | @implementation UIRefreshControl (AFNetworking)
39 |
40 | - (AFRefreshControlNotificationObserver *)af_notificationObserver {
41 | AFRefreshControlNotificationObserver *notificationObserver = objc_getAssociatedObject(self, @selector(af_notificationObserver));
42 | if (notificationObserver == nil) {
43 | notificationObserver = [[AFRefreshControlNotificationObserver alloc] initWithActivityRefreshControl:self];
44 | objc_setAssociatedObject(self, @selector(af_notificationObserver), notificationObserver, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
45 | }
46 | return notificationObserver;
47 | }
48 |
49 | - (void)setRefreshingWithStateOfTask:(NSURLSessionTask *)task {
50 | [[self af_notificationObserver] setRefreshingWithStateOfTask:task];
51 | }
52 |
53 | @end
54 |
55 | @implementation AFRefreshControlNotificationObserver
56 |
57 | - (instancetype)initWithActivityRefreshControl:(UIRefreshControl *)refreshControl
58 | {
59 | self = [super init];
60 | if (self) {
61 | _refreshControl = refreshControl;
62 | }
63 | return self;
64 | }
65 |
66 | - (void)setRefreshingWithStateOfTask:(NSURLSessionTask *)task {
67 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
68 |
69 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidResumeNotification object:nil];
70 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidSuspendNotification object:nil];
71 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidCompleteNotification object:nil];
72 |
73 | if (task) {
74 | #pragma clang diagnostic push
75 | #pragma clang diagnostic ignored "-Wreceiver-is-weak"
76 | #pragma clang diagnostic ignored "-Warc-repeated-use-of-weak"
77 | if (task.state == NSURLSessionTaskStateRunning) {
78 | [self.refreshControl beginRefreshing];
79 |
80 | [notificationCenter addObserver:self selector:@selector(af_beginRefreshing) name:AFNetworkingTaskDidResumeNotification object:task];
81 | [notificationCenter addObserver:self selector:@selector(af_endRefreshing) name:AFNetworkingTaskDidCompleteNotification object:task];
82 | [notificationCenter addObserver:self selector:@selector(af_endRefreshing) name:AFNetworkingTaskDidSuspendNotification object:task];
83 | } else {
84 | [self.refreshControl endRefreshing];
85 | }
86 | #pragma clang diagnostic pop
87 | }
88 | }
89 |
90 | #pragma mark -
91 |
92 | - (void)af_beginRefreshing {
93 | dispatch_async(dispatch_get_main_queue(), ^{
94 | #pragma clang diagnostic push
95 | #pragma clang diagnostic ignored "-Wreceiver-is-weak"
96 | [self.refreshControl beginRefreshing];
97 | #pragma clang diagnostic pop
98 | });
99 | }
100 |
101 | - (void)af_endRefreshing {
102 | dispatch_async(dispatch_get_main_queue(), ^{
103 | #pragma clang diagnostic push
104 | #pragma clang diagnostic ignored "-Wreceiver-is-weak"
105 | [self.refreshControl endRefreshing];
106 | #pragma clang diagnostic pop
107 | });
108 | }
109 |
110 | #pragma mark -
111 |
112 | - (void)dealloc {
113 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
114 |
115 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidCompleteNotification object:nil];
116 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidResumeNotification object:nil];
117 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidSuspendNotification object:nil];
118 | }
119 |
120 | @end
121 |
122 | #endif
123 |
--------------------------------------------------------------------------------
/FaceSDKDemo/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 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/SDWebImage/SDWebImagePrefetcher.m:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import "SDWebImagePrefetcher.h"
10 |
11 | @interface SDWebImagePrefetcher ()
12 |
13 | @property (strong, nonatomic) SDWebImageManager *manager;
14 | @property (strong, nonatomic) NSArray *prefetchURLs;
15 | @property (assign, nonatomic) NSUInteger requestedCount;
16 | @property (assign, nonatomic) NSUInteger skippedCount;
17 | @property (assign, nonatomic) NSUInteger finishedCount;
18 | @property (assign, nonatomic) NSTimeInterval startedTime;
19 | @property (copy, nonatomic) SDWebImagePrefetcherCompletionBlock completionBlock;
20 | @property (copy, nonatomic) SDWebImagePrefetcherProgressBlock progressBlock;
21 |
22 | @end
23 |
24 | @implementation SDWebImagePrefetcher
25 |
26 | + (SDWebImagePrefetcher *)sharedImagePrefetcher {
27 | static dispatch_once_t once;
28 | static id instance;
29 | dispatch_once(&once, ^{
30 | instance = [self new];
31 | });
32 | return instance;
33 | }
34 |
35 | - (id)init {
36 | return [self initWithImageManager:[SDWebImageManager new]];
37 | }
38 |
39 | - (id)initWithImageManager:(SDWebImageManager *)manager {
40 | if ((self = [super init])) {
41 | _manager = manager;
42 | _options = SDWebImageLowPriority;
43 | _prefetcherQueue = dispatch_get_main_queue();
44 | self.maxConcurrentDownloads = 3;
45 | }
46 | return self;
47 | }
48 |
49 | - (void)setMaxConcurrentDownloads:(NSUInteger)maxConcurrentDownloads {
50 | self.manager.imageDownloader.maxConcurrentDownloads = maxConcurrentDownloads;
51 | }
52 |
53 | - (NSUInteger)maxConcurrentDownloads {
54 | return self.manager.imageDownloader.maxConcurrentDownloads;
55 | }
56 |
57 | - (void)startPrefetchingAtIndex:(NSUInteger)index {
58 | if (index >= self.prefetchURLs.count) return;
59 | self.requestedCount++;
60 | [self.manager downloadImageWithURL:self.prefetchURLs[index] options:self.options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
61 | if (!finished) return;
62 | self.finishedCount++;
63 |
64 | if (image) {
65 | if (self.progressBlock) {
66 | self.progressBlock(self.finishedCount,[self.prefetchURLs count]);
67 | }
68 | }
69 | else {
70 | if (self.progressBlock) {
71 | self.progressBlock(self.finishedCount,[self.prefetchURLs count]);
72 | }
73 | // Add last failed
74 | self.skippedCount++;
75 | }
76 | if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didPrefetchURL:finishedCount:totalCount:)]) {
77 | [self.delegate imagePrefetcher:self
78 | didPrefetchURL:self.prefetchURLs[index]
79 | finishedCount:self.finishedCount
80 | totalCount:self.prefetchURLs.count
81 | ];
82 | }
83 | if (self.prefetchURLs.count > self.requestedCount) {
84 | dispatch_async(self.prefetcherQueue, ^{
85 | [self startPrefetchingAtIndex:self.requestedCount];
86 | });
87 | } else if (self.finishedCount == self.requestedCount) {
88 | [self reportStatus];
89 | if (self.completionBlock) {
90 | self.completionBlock(self.finishedCount, self.skippedCount);
91 | self.completionBlock = nil;
92 | }
93 | self.progressBlock = nil;
94 | }
95 | }];
96 | }
97 |
98 | - (void)reportStatus {
99 | NSUInteger total = [self.prefetchURLs count];
100 | if ([self.delegate respondsToSelector:@selector(imagePrefetcher:didFinishWithTotalCount:skippedCount:)]) {
101 | [self.delegate imagePrefetcher:self
102 | didFinishWithTotalCount:(total - self.skippedCount)
103 | skippedCount:self.skippedCount
104 | ];
105 | }
106 | }
107 |
108 | - (void)prefetchURLs:(NSArray *)urls {
109 | [self prefetchURLs:urls progress:nil completed:nil];
110 | }
111 |
112 | - (void)prefetchURLs:(NSArray *)urls progress:(SDWebImagePrefetcherProgressBlock)progressBlock completed:(SDWebImagePrefetcherCompletionBlock)completionBlock {
113 | [self cancelPrefetching]; // Prevent duplicate prefetch request
114 | self.startedTime = CFAbsoluteTimeGetCurrent();
115 | self.prefetchURLs = urls;
116 | self.completionBlock = completionBlock;
117 | self.progressBlock = progressBlock;
118 |
119 | if (urls.count == 0) {
120 | if (completionBlock) {
121 | completionBlock(0,0);
122 | }
123 | } else {
124 | // Starts prefetching from the very first image on the list with the max allowed concurrency
125 | NSUInteger listCount = self.prefetchURLs.count;
126 | for (NSUInteger i = 0; i < self.maxConcurrentDownloads && self.requestedCount < listCount; i++) {
127 | [self startPrefetchingAtIndex:i];
128 | }
129 | }
130 | }
131 |
132 | - (void)cancelPrefetching {
133 | self.prefetchURLs = nil;
134 | self.skippedCount = 0;
135 | self.requestedCount = 0;
136 | self.finishedCount = 0;
137 | [self.manager cancelAll];
138 | }
139 |
140 | @end
141 |
--------------------------------------------------------------------------------
/SDWebImage/UIImageView+HighlightedWebCache.h:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import
10 | #import "SDWebImageCompat.h"
11 | #import "SDWebImageManager.h"
12 |
13 | /**
14 | * Integrates SDWebImage async downloading and caching of remote images with UIImageView for highlighted state.
15 | */
16 | @interface UIImageView (HighlightedWebCache)
17 |
18 | /**
19 | * Set the imageView `highlightedImage` with an `url`.
20 | *
21 | * The download is asynchronous and cached.
22 | *
23 | * @param url The url for the image.
24 | */
25 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url;
26 |
27 | /**
28 | * Set the imageView `highlightedImage` with an `url` and custom options.
29 | *
30 | * The download is asynchronous and cached.
31 | *
32 | * @param url The url for the image.
33 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
34 | */
35 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options;
36 |
37 | /**
38 | * Set the imageView `highlightedImage` with an `url`.
39 | *
40 | * The download is asynchronous and cached.
41 | *
42 | * @param url The url for the image.
43 | * @param completedBlock A block called when operation has been completed. This block has no return value
44 | * and takes the requested UIImage as first parameter. In case of error the image parameter
45 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
46 | * indicating if the image was retrieved from the local cache or from the network.
47 | * The fourth parameter is the original image url.
48 | */
49 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock;
50 |
51 | /**
52 | * Set the imageView `highlightedImage` with an `url` and custom options.
53 | *
54 | * The download is asynchronous and cached.
55 | *
56 | * @param url The url for the image.
57 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
58 | * @param completedBlock A block called when operation has been completed. This block has no return value
59 | * and takes the requested UIImage as first parameter. In case of error the image parameter
60 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
61 | * indicating if the image was retrieved from the local cache or from the network.
62 | * The fourth parameter is the original image url.
63 | */
64 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock;
65 |
66 | /**
67 | * Set the imageView `highlightedImage` with an `url` and custom options.
68 | *
69 | * The download is asynchronous and cached.
70 | *
71 | * @param url The url for the image.
72 | * @param options The options to use when downloading the image. @see SDWebImageOptions for the possible values.
73 | * @param progressBlock A block called while image is downloading
74 | * @param completedBlock A block called when operation has been completed. This block has no return value
75 | * and takes the requested UIImage as first parameter. In case of error the image parameter
76 | * is nil and the second parameter may contain an NSError. The third parameter is a Boolean
77 | * indicating if the image was retrieved from the local cache or from the network.
78 | * The fourth parameter is the original image url.
79 | */
80 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock;
81 |
82 | /**
83 | * Cancel the current download
84 | */
85 | - (void)sd_cancelCurrentHighlightedImageLoad;
86 |
87 | @end
88 |
89 |
90 | @interface UIImageView (HighlightedWebCacheDeprecated)
91 |
92 | - (void)setHighlightedImageWithURL:(NSURL *)url __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:`");
93 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:`");
94 | - (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:completed:`");
95 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:completed:`");
96 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock __deprecated_msg("Method deprecated. Use `sd_setHighlightedImageWithURL:options:progress:completed:`");
97 |
98 | - (void)cancelCurrentHighlightedImageLoad __deprecated_msg("Use `sd_cancelCurrentHighlightedImageLoad`");
99 |
100 | @end
101 |
--------------------------------------------------------------------------------
/SDWebImage/UIImageView+HighlightedWebCache.m:
--------------------------------------------------------------------------------
1 | /*
2 | * This file is part of the SDWebImage package.
3 | * (c) Olivier Poitrey
4 | *
5 | * For the full copyright and license information, please view the LICENSE
6 | * file that was distributed with this source code.
7 | */
8 |
9 | #import "UIImageView+HighlightedWebCache.h"
10 | #import "UIView+WebCacheOperation.h"
11 |
12 | #define UIImageViewHighlightedWebCacheOperationKey @"highlightedImage"
13 |
14 | @implementation UIImageView (HighlightedWebCache)
15 |
16 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url {
17 | [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
18 | }
19 |
20 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {
21 | [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil];
22 | }
23 |
24 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletionBlock)completedBlock {
25 | [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:completedBlock];
26 | }
27 |
28 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletionBlock)completedBlock {
29 | [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:completedBlock];
30 | }
31 |
32 | - (void)sd_setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletionBlock)completedBlock {
33 | [self sd_cancelCurrentHighlightedImageLoad];
34 |
35 | if (url) {
36 | __weak __typeof(self)wself = self;
37 | id operation = [SDWebImageManager.sharedManager downloadImageWithURL:url options:options progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
38 | if (!wself) return;
39 | dispatch_main_sync_safe (^
40 | {
41 | if (!wself) return;
42 | if (image && (options & SDWebImageAvoidAutoSetImage) && completedBlock)
43 | {
44 | completedBlock(image, error, cacheType, url);
45 | return;
46 | }
47 | else if (image) {
48 | wself.highlightedImage = image;
49 | [wself setNeedsLayout];
50 | }
51 | if (completedBlock && finished) {
52 | completedBlock(image, error, cacheType, url);
53 | }
54 | });
55 | }];
56 | [self sd_setImageLoadOperation:operation forKey:UIImageViewHighlightedWebCacheOperationKey];
57 | } else {
58 | dispatch_main_async_safe(^{
59 | NSError *error = [NSError errorWithDomain:SDWebImageErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey : @"Trying to load a nil url"}];
60 | if (completedBlock) {
61 | completedBlock(nil, error, SDImageCacheTypeNone, url);
62 | }
63 | });
64 | }
65 | }
66 |
67 | - (void)sd_cancelCurrentHighlightedImageLoad {
68 | [self sd_cancelImageLoadOperationWithKey:UIImageViewHighlightedWebCacheOperationKey];
69 | }
70 |
71 | @end
72 |
73 |
74 | @implementation UIImageView (HighlightedWebCacheDeprecated)
75 |
76 | - (void)setHighlightedImageWithURL:(NSURL *)url {
77 | [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:nil];
78 | }
79 |
80 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options {
81 | [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:nil];
82 | }
83 |
84 | - (void)setHighlightedImageWithURL:(NSURL *)url completed:(SDWebImageCompletedBlock)completedBlock {
85 | [self sd_setHighlightedImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
86 | if (completedBlock) {
87 | completedBlock(image, error, cacheType);
88 | }
89 | }];
90 | }
91 |
92 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options completed:(SDWebImageCompletedBlock)completedBlock {
93 | [self sd_setHighlightedImageWithURL:url options:options progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
94 | if (completedBlock) {
95 | completedBlock(image, error, cacheType);
96 | }
97 | }];
98 | }
99 |
100 | - (void)setHighlightedImageWithURL:(NSURL *)url options:(SDWebImageOptions)options progress:(SDWebImageDownloaderProgressBlock)progressBlock completed:(SDWebImageCompletedBlock)completedBlock {
101 | [self sd_setHighlightedImageWithURL:url options:0 progress:progressBlock completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
102 | if (completedBlock) {
103 | completedBlock(image, error, cacheType);
104 | }
105 | }];
106 | }
107 |
108 | - (void)cancelCurrentHighlightedImageLoad {
109 | [self sd_cancelCurrentHighlightedImageLoad];
110 | }
111 |
112 | @end
113 |
--------------------------------------------------------------------------------
/AFNetworking/UIKit+AFNetworking/UIActivityIndicatorView+AFNetworking.m:
--------------------------------------------------------------------------------
1 | // UIActivityIndicatorView+AFNetworking.m
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import "UIActivityIndicatorView+AFNetworking.h"
23 | #import
24 |
25 | #if TARGET_OS_IOS || TARGET_OS_TV
26 |
27 | #import "AFURLSessionManager.h"
28 |
29 | @interface AFActivityIndicatorViewNotificationObserver : NSObject
30 | @property (readonly, nonatomic, weak) UIActivityIndicatorView *activityIndicatorView;
31 | - (instancetype)initWithActivityIndicatorView:(UIActivityIndicatorView *)activityIndicatorView;
32 |
33 | - (void)setAnimatingWithStateOfTask:(NSURLSessionTask *)task;
34 |
35 | @end
36 |
37 | @implementation UIActivityIndicatorView (AFNetworking)
38 |
39 | - (AFActivityIndicatorViewNotificationObserver *)af_notificationObserver {
40 | AFActivityIndicatorViewNotificationObserver *notificationObserver = objc_getAssociatedObject(self, @selector(af_notificationObserver));
41 | if (notificationObserver == nil) {
42 | notificationObserver = [[AFActivityIndicatorViewNotificationObserver alloc] initWithActivityIndicatorView:self];
43 | objc_setAssociatedObject(self, @selector(af_notificationObserver), notificationObserver, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
44 | }
45 | return notificationObserver;
46 | }
47 |
48 | - (void)setAnimatingWithStateOfTask:(NSURLSessionTask *)task {
49 | [[self af_notificationObserver] setAnimatingWithStateOfTask:task];
50 | }
51 |
52 | @end
53 |
54 | @implementation AFActivityIndicatorViewNotificationObserver
55 |
56 | - (instancetype)initWithActivityIndicatorView:(UIActivityIndicatorView *)activityIndicatorView
57 | {
58 | self = [super init];
59 | if (self) {
60 | _activityIndicatorView = activityIndicatorView;
61 | }
62 | return self;
63 | }
64 |
65 | - (void)setAnimatingWithStateOfTask:(NSURLSessionTask *)task {
66 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
67 |
68 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidResumeNotification object:nil];
69 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidSuspendNotification object:nil];
70 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidCompleteNotification object:nil];
71 |
72 | if (task) {
73 | if (task.state != NSURLSessionTaskStateCompleted) {
74 |
75 | #pragma clang diagnostic push
76 | #pragma clang diagnostic ignored "-Wreceiver-is-weak"
77 | #pragma clang diagnostic ignored "-Warc-repeated-use-of-weak"
78 | if (task.state == NSURLSessionTaskStateRunning) {
79 | [self.activityIndicatorView startAnimating];
80 | } else {
81 | [self.activityIndicatorView stopAnimating];
82 | }
83 | #pragma clang diagnostic pop
84 |
85 | [notificationCenter addObserver:self selector:@selector(af_startAnimating) name:AFNetworkingTaskDidResumeNotification object:task];
86 | [notificationCenter addObserver:self selector:@selector(af_stopAnimating) name:AFNetworkingTaskDidCompleteNotification object:task];
87 | [notificationCenter addObserver:self selector:@selector(af_stopAnimating) name:AFNetworkingTaskDidSuspendNotification object:task];
88 | }
89 | }
90 | }
91 |
92 | #pragma mark -
93 |
94 | - (void)af_startAnimating {
95 | dispatch_async(dispatch_get_main_queue(), ^{
96 | #pragma clang diagnostic push
97 | #pragma clang diagnostic ignored "-Wreceiver-is-weak"
98 | [self.activityIndicatorView startAnimating];
99 | #pragma clang diagnostic pop
100 | });
101 | }
102 |
103 | - (void)af_stopAnimating {
104 | dispatch_async(dispatch_get_main_queue(), ^{
105 | #pragma clang diagnostic push
106 | #pragma clang diagnostic ignored "-Wreceiver-is-weak"
107 | [self.activityIndicatorView stopAnimating];
108 | #pragma clang diagnostic pop
109 | });
110 | }
111 |
112 | #pragma mark -
113 |
114 | - (void)dealloc {
115 | NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
116 |
117 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidCompleteNotification object:nil];
118 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidResumeNotification object:nil];
119 | [notificationCenter removeObserver:self name:AFNetworkingTaskDidSuspendNotification object:nil];
120 | }
121 |
122 | @end
123 |
124 | #endif
125 |
--------------------------------------------------------------------------------
/SDWebImage/UIImage+GIF.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+GIF.m
3 | // LBGIFImage
4 | //
5 | // Created by Laurin Brandner on 06.01.12.
6 | // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
7 | //
8 |
9 | #import "UIImage+GIF.h"
10 | #import
11 |
12 | @implementation UIImage (GIF)
13 |
14 | + (UIImage *)sd_animatedGIFWithData:(NSData *)data {
15 | if (!data) {
16 | return nil;
17 | }
18 |
19 | CGImageSourceRef source = CGImageSourceCreateWithData((__bridge CFDataRef)data, NULL);
20 |
21 | size_t count = CGImageSourceGetCount(source);
22 |
23 | UIImage *animatedImage;
24 |
25 | if (count <= 1) {
26 | animatedImage = [[UIImage alloc] initWithData:data];
27 | }
28 | else {
29 | NSMutableArray *images = [NSMutableArray array];
30 |
31 | NSTimeInterval duration = 0.0f;
32 |
33 | for (size_t i = 0; i < count; i++) {
34 | CGImageRef image = CGImageSourceCreateImageAtIndex(source, i, NULL);
35 | if (!image) {
36 | continue;
37 | }
38 |
39 | duration += [self sd_frameDurationAtIndex:i source:source];
40 |
41 | [images addObject:[UIImage imageWithCGImage:image scale:[UIScreen mainScreen].scale orientation:UIImageOrientationUp]];
42 |
43 | CGImageRelease(image);
44 | }
45 |
46 | if (!duration) {
47 | duration = (1.0f / 10.0f) * count;
48 | }
49 |
50 | animatedImage = [UIImage animatedImageWithImages:images duration:duration];
51 | }
52 |
53 | CFRelease(source);
54 |
55 | return animatedImage;
56 | }
57 |
58 | + (float)sd_frameDurationAtIndex:(NSUInteger)index source:(CGImageSourceRef)source {
59 | float frameDuration = 0.1f;
60 | CFDictionaryRef cfFrameProperties = CGImageSourceCopyPropertiesAtIndex(source, index, nil);
61 | NSDictionary *frameProperties = (__bridge NSDictionary *)cfFrameProperties;
62 | NSDictionary *gifProperties = frameProperties[(NSString *)kCGImagePropertyGIFDictionary];
63 |
64 | NSNumber *delayTimeUnclampedProp = gifProperties[(NSString *)kCGImagePropertyGIFUnclampedDelayTime];
65 | if (delayTimeUnclampedProp) {
66 | frameDuration = [delayTimeUnclampedProp floatValue];
67 | }
68 | else {
69 |
70 | NSNumber *delayTimeProp = gifProperties[(NSString *)kCGImagePropertyGIFDelayTime];
71 | if (delayTimeProp) {
72 | frameDuration = [delayTimeProp floatValue];
73 | }
74 | }
75 |
76 | // Many annoying ads specify a 0 duration to make an image flash as quickly as possible.
77 | // We follow Firefox's behavior and use a duration of 100 ms for any frames that specify
78 | // a duration of <= 10 ms. See and
79 | // for more information.
80 |
81 | if (frameDuration < 0.011f) {
82 | frameDuration = 0.100f;
83 | }
84 |
85 | CFRelease(cfFrameProperties);
86 | return frameDuration;
87 | }
88 |
89 | + (UIImage *)sd_animatedGIFNamed:(NSString *)name {
90 | CGFloat scale = [UIScreen mainScreen].scale;
91 |
92 | if (scale > 1.0f) {
93 | NSString *retinaPath = [[NSBundle mainBundle] pathForResource:[name stringByAppendingString:@"@2x"] ofType:@"gif"];
94 |
95 | NSData *data = [NSData dataWithContentsOfFile:retinaPath];
96 |
97 | if (data) {
98 | return [UIImage sd_animatedGIFWithData:data];
99 | }
100 |
101 | NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"];
102 |
103 | data = [NSData dataWithContentsOfFile:path];
104 |
105 | if (data) {
106 | return [UIImage sd_animatedGIFWithData:data];
107 | }
108 |
109 | return [UIImage imageNamed:name];
110 | }
111 | else {
112 | NSString *path = [[NSBundle mainBundle] pathForResource:name ofType:@"gif"];
113 |
114 | NSData *data = [NSData dataWithContentsOfFile:path];
115 |
116 | if (data) {
117 | return [UIImage sd_animatedGIFWithData:data];
118 | }
119 |
120 | return [UIImage imageNamed:name];
121 | }
122 | }
123 |
124 | - (UIImage *)sd_animatedImageByScalingAndCroppingToSize:(CGSize)size {
125 | if (CGSizeEqualToSize(self.size, size) || CGSizeEqualToSize(size, CGSizeZero)) {
126 | return self;
127 | }
128 |
129 | CGSize scaledSize = size;
130 | CGPoint thumbnailPoint = CGPointZero;
131 |
132 | CGFloat widthFactor = size.width / self.size.width;
133 | CGFloat heightFactor = size.height / self.size.height;
134 | CGFloat scaleFactor = (widthFactor > heightFactor) ? widthFactor : heightFactor;
135 | scaledSize.width = self.size.width * scaleFactor;
136 | scaledSize.height = self.size.height * scaleFactor;
137 |
138 | if (widthFactor > heightFactor) {
139 | thumbnailPoint.y = (size.height - scaledSize.height) * 0.5;
140 | }
141 | else if (widthFactor < heightFactor) {
142 | thumbnailPoint.x = (size.width - scaledSize.width) * 0.5;
143 | }
144 |
145 | NSMutableArray *scaledImages = [NSMutableArray array];
146 |
147 | for (UIImage *image in self.images) {
148 | UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
149 |
150 | [image drawInRect:CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledSize.width, scaledSize.height)];
151 | UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
152 |
153 | [scaledImages addObject:newImage];
154 |
155 | UIGraphicsEndImageContext();
156 | }
157 |
158 | return [UIImage animatedImageWithImages:scaledImages duration:self.duration];
159 | }
160 |
161 | @end
162 |
--------------------------------------------------------------------------------
/AFNetworking/UIKit+AFNetworking/UIProgressView+AFNetworking.m:
--------------------------------------------------------------------------------
1 | // UIProgressView+AFNetworking.m
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import "UIProgressView+AFNetworking.h"
23 |
24 | #import
25 |
26 | #if TARGET_OS_IOS || TARGET_OS_TV
27 |
28 | #import "AFURLSessionManager.h"
29 |
30 | static void * AFTaskCountOfBytesSentContext = &AFTaskCountOfBytesSentContext;
31 | static void * AFTaskCountOfBytesReceivedContext = &AFTaskCountOfBytesReceivedContext;
32 |
33 | #pragma mark -
34 |
35 | @implementation UIProgressView (AFNetworking)
36 |
37 | - (BOOL)af_uploadProgressAnimated {
38 | return [(NSNumber *)objc_getAssociatedObject(self, @selector(af_uploadProgressAnimated)) boolValue];
39 | }
40 |
41 | - (void)af_setUploadProgressAnimated:(BOOL)animated {
42 | objc_setAssociatedObject(self, @selector(af_uploadProgressAnimated), @(animated), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
43 | }
44 |
45 | - (BOOL)af_downloadProgressAnimated {
46 | return [(NSNumber *)objc_getAssociatedObject(self, @selector(af_downloadProgressAnimated)) boolValue];
47 | }
48 |
49 | - (void)af_setDownloadProgressAnimated:(BOOL)animated {
50 | objc_setAssociatedObject(self, @selector(af_downloadProgressAnimated), @(animated), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
51 | }
52 |
53 | #pragma mark -
54 |
55 | - (void)setProgressWithUploadProgressOfTask:(NSURLSessionUploadTask *)task
56 | animated:(BOOL)animated
57 | {
58 | [task addObserver:self forKeyPath:@"state" options:(NSKeyValueObservingOptions)0 context:AFTaskCountOfBytesSentContext];
59 | [task addObserver:self forKeyPath:@"countOfBytesSent" options:(NSKeyValueObservingOptions)0 context:AFTaskCountOfBytesSentContext];
60 |
61 | [self af_setUploadProgressAnimated:animated];
62 | }
63 |
64 | - (void)setProgressWithDownloadProgressOfTask:(NSURLSessionDownloadTask *)task
65 | animated:(BOOL)animated
66 | {
67 | [task addObserver:self forKeyPath:@"state" options:(NSKeyValueObservingOptions)0 context:AFTaskCountOfBytesReceivedContext];
68 | [task addObserver:self forKeyPath:@"countOfBytesReceived" options:(NSKeyValueObservingOptions)0 context:AFTaskCountOfBytesReceivedContext];
69 |
70 | [self af_setDownloadProgressAnimated:animated];
71 | }
72 |
73 | #pragma mark - NSKeyValueObserving
74 |
75 | - (void)observeValueForKeyPath:(NSString *)keyPath
76 | ofObject:(id)object
77 | change:(__unused NSDictionary *)change
78 | context:(void *)context
79 | {
80 | if (context == AFTaskCountOfBytesSentContext || context == AFTaskCountOfBytesReceivedContext) {
81 | if ([keyPath isEqualToString:NSStringFromSelector(@selector(countOfBytesSent))]) {
82 | if ([object countOfBytesExpectedToSend] > 0) {
83 | dispatch_async(dispatch_get_main_queue(), ^{
84 | [self setProgress:[object countOfBytesSent] / ([object countOfBytesExpectedToSend] * 1.0f) animated:self.af_uploadProgressAnimated];
85 | });
86 | }
87 | }
88 |
89 | if ([keyPath isEqualToString:NSStringFromSelector(@selector(countOfBytesReceived))]) {
90 | if ([object countOfBytesExpectedToReceive] > 0) {
91 | dispatch_async(dispatch_get_main_queue(), ^{
92 | [self setProgress:[object countOfBytesReceived] / ([object countOfBytesExpectedToReceive] * 1.0f) animated:self.af_downloadProgressAnimated];
93 | });
94 | }
95 | }
96 |
97 | if ([keyPath isEqualToString:NSStringFromSelector(@selector(state))]) {
98 | if ([(NSURLSessionTask *)object state] == NSURLSessionTaskStateCompleted) {
99 | @try {
100 | [object removeObserver:self forKeyPath:NSStringFromSelector(@selector(state))];
101 |
102 | if (context == AFTaskCountOfBytesSentContext) {
103 | [object removeObserver:self forKeyPath:NSStringFromSelector(@selector(countOfBytesSent))];
104 | }
105 |
106 | if (context == AFTaskCountOfBytesReceivedContext) {
107 | [object removeObserver:self forKeyPath:NSStringFromSelector(@selector(countOfBytesReceived))];
108 | }
109 | }
110 | @catch (NSException * __unused exception) {}
111 | }
112 | }
113 | }
114 | }
115 |
116 | @end
117 |
118 | #endif
119 |
--------------------------------------------------------------------------------
/FCPPSDK/FCPPFaceSet.m:
--------------------------------------------------------------------------------
1 | //
2 | // FCPPFaceSetManager.m
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/6/21.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "FCPPFaceSet.h"
10 |
11 | @implementation FCPPFaceSet
12 |
13 | - (instancetype)initWithFaceSetToken:(NSString *)faceSetToken{
14 | if (self = [super init]) {
15 | self.faceset_token = faceSetToken;
16 | }
17 | return self;
18 | }
19 |
20 | - (instancetype)initWithOuterId:(NSString *)outerId{
21 | if (self = [super init]) {
22 | self.outer_id = outerId;
23 | }
24 | return self;
25 | }
26 |
27 | + (void)createFaceSetWithDisplayName:(NSString *)displayName outerId:(NSString *)outerId tgas:(NSArray *)tags faceTokens:(NSArray *)tokens userData:(NSString *)userData forceMerge:(BOOL)forceMerge completion:(void(^)(id info,NSError *error))completion{
28 | NSString *url = [NSString stringWithFormat:@"%@/%@/%@",FACE_WEB_BASE,FACESET,FACESET_CREATE];
29 | NSMutableDictionary *param = [NSMutableDictionary dictionary];
30 | if (displayName.length) {
31 | param[@"display_name"] = displayName;
32 | }
33 | if (outerId.length) {
34 | param[@"outer_id"] = outerId;
35 | }
36 | if (userData.length) {
37 | param[@"user_data"] = userData;
38 | }
39 |
40 | if (tags.count) {
41 | NSString *tagStr = [tags componentsJoinedByString:@","];
42 | param[@"tags"] = tagStr;
43 | }
44 |
45 | if (tokens) {
46 | NSString *tokenStr = [tokens componentsJoinedByString:@","];
47 | param[@"face_tokens"] = tokenStr;
48 | }
49 | NSNumber *force_merge = forceMerge ? @(1) : @(0);
50 | [param setObject:force_merge forKey:@"force_merge"];
51 | [FCPPApi POST:url param:param completion:completion];
52 | }
53 |
54 | - (void)addFaceTokens:(NSArray *)tokens completion:(void(^)(id info,NSError *error))completion{
55 | NSString *url = [NSString stringWithFormat:@"%@/%@/%@",FACE_WEB_BASE,FACESET,FACESET_ADDFACE];
56 | NSMutableDictionary *param = [NSMutableDictionary dictionary];
57 |
58 | if (tokens.count) {
59 | NSString *tokenStr = [tokens componentsJoinedByString:@","];
60 | param[@"face_tokens"] = tokenStr;
61 | }
62 |
63 | if (self.faceset_token) {
64 | param[@"faceset_token"] = self.faceset_token;
65 | }else if(self.outer_id){
66 | param[@"outer_id"] = self.outer_id;
67 | }
68 |
69 | [FCPPApi POST:url param:param completion:completion];
70 | }
71 |
72 | - (void)removeFaceToken:(NSArray *)tokens completion:(void(^)(id info,NSError *error))completion{
73 | NSString *url = [NSString stringWithFormat:@"%@/%@/%@",FACE_WEB_BASE,FACESET,FACESET_REMOVE_FACE];
74 | NSMutableDictionary *param = [NSMutableDictionary dictionary];
75 |
76 | if (tokens.count) {
77 | NSString *tokenStr = [tokens componentsJoinedByString:@","];
78 | param[@"face_tokens"] = tokenStr;
79 | }else{
80 | NSLog(@"token can not nil");
81 | }
82 |
83 | if (self.faceset_token) {
84 | param[@"faceset_token"] = self.faceset_token;
85 | }else if(self.outer_id){
86 | param[@"outer_id"] = self.outer_id;
87 | }
88 |
89 | [FCPPApi POST:url param:param completion:completion];
90 | }
91 |
92 | - (void)updateFaceSetWithDic:(NSDictionary *)dic completion:(void(^)(id info,NSError *error))completion{
93 | NSString *url = [NSString stringWithFormat:@"%@/%@/%@",FACE_WEB_BASE,FACESET,FACESET_UPDATE];
94 | NSMutableDictionary *param = [NSMutableDictionary dictionary];
95 |
96 | if (dic.allKeys.count) {
97 | [param addEntriesFromDictionary:dic];
98 | }
99 |
100 | if (self.faceset_token) {
101 | param[@"faceset_token"] = self.faceset_token;
102 | }else if(self.outer_id){
103 | param[@"outer_id"] = self.outer_id;
104 | }
105 |
106 | [FCPPApi POST:url param:param completion:completion];
107 | }
108 |
109 | - (void)deleteFaceSetCheckEmpty:(BOOL)checkEmpty completion:(void(^)(id info,NSError *error))completion{
110 | NSString *url = [NSString stringWithFormat:@"%@/%@/%@",FACE_WEB_BASE,FACESET,FACESET_DELETE];
111 | NSMutableDictionary *param = [NSMutableDictionary dictionary];
112 |
113 | NSNumber *check_empty = checkEmpty ? @(1) : @(0);
114 | [param setObject:check_empty forKey:@"check_empty"];
115 |
116 | if (self.faceset_token) {
117 | param[@"faceset_token"] = self.faceset_token;
118 | }else if(self.outer_id){
119 | param[@"outer_id"] = self.outer_id;
120 | }
121 |
122 | [FCPPApi POST:url param:param completion:completion];
123 | }
124 | - (void)getDetailCompletion:(void(^)(id info,NSError *error))completion{
125 | NSString *url = [NSString stringWithFormat:@"%@/%@/%@",FACE_WEB_BASE,FACESET,FACESET_GET_DETAIL];
126 | NSMutableDictionary *param = [NSMutableDictionary dictionary];
127 |
128 | if (self.faceset_token) {
129 | param[@"faceset_token"] = self.faceset_token;
130 | }else if(self.outer_id){
131 | param[@"outer_id"] = self.outer_id;
132 | }
133 |
134 | [FCPPApi POST:url param:param completion:completion];
135 | }
136 | + (void)getFaceSetsWithTags:(NSArray *)tags completion:(void(^)(id info,NSError *error))completion{
137 | NSString *url = [NSString stringWithFormat:@"%@/%@/%@",FACE_WEB_BASE,FACESET,FACESET_GET_FACESETS];
138 | NSMutableDictionary *param = [NSMutableDictionary dictionary];
139 | NSString *tagStr = [tags componentsJoinedByString:@","];
140 | if (tagStr.length) {
141 | [param setObject:tagStr forKey:@"tags"];
142 | }
143 |
144 | [FCPPApi POST:url param:param completion:completion];
145 | }
146 | @end
147 |
--------------------------------------------------------------------------------
/AFNetworking/UIKit+AFNetworking/AFNetworkActivityIndicatorManager.h:
--------------------------------------------------------------------------------
1 | // AFNetworkActivityIndicatorManager.h
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 |
24 | #import
25 |
26 | #if TARGET_OS_IOS
27 |
28 | #import
29 |
30 | NS_ASSUME_NONNULL_BEGIN
31 |
32 | /**
33 | `AFNetworkActivityIndicatorManager` manages the state of the network activity indicator in the status bar. When enabled, it will listen for notifications indicating that a session task has started or finished, and start or stop animating the indicator accordingly. The number of active requests is incremented and decremented much like a stack or a semaphore, and the activity indicator will animate so long as that number is greater than zero.
34 |
35 | You should enable the shared instance of `AFNetworkActivityIndicatorManager` when your application finishes launching. In `AppDelegate application:didFinishLaunchingWithOptions:` you can do so with the following code:
36 |
37 | [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
38 |
39 | By setting `enabled` to `YES` for `sharedManager`, the network activity indicator will show and hide automatically as requests start and finish. You should not ever need to call `incrementActivityCount` or `decrementActivityCount` yourself.
40 |
41 | See the Apple Human Interface Guidelines section about the Network Activity Indicator for more information:
42 | http://developer.apple.com/library/iOS/#documentation/UserExperience/Conceptual/MobileHIG/UIElementGuidelines/UIElementGuidelines.html#//apple_ref/doc/uid/TP40006556-CH13-SW44
43 | */
44 | NS_EXTENSION_UNAVAILABLE_IOS("Use view controller based solutions where appropriate instead.")
45 | @interface AFNetworkActivityIndicatorManager : NSObject
46 |
47 | /**
48 | A Boolean value indicating whether the manager is enabled.
49 |
50 | If YES, the manager will change status bar network activity indicator according to network operation notifications it receives. The default value is NO.
51 | */
52 | @property (nonatomic, assign, getter = isEnabled) BOOL enabled;
53 |
54 | /**
55 | A Boolean value indicating whether the network activity indicator manager is currently active.
56 | */
57 | @property (readonly, nonatomic, assign, getter=isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible;
58 |
59 | /**
60 | A time interval indicating the minimum duration of networking activity that should occur before the activity indicator is displayed. The default value 1 second. If the network activity indicator should be displayed immediately when network activity occurs, this value should be set to 0 seconds.
61 |
62 | Apple's HIG describes the following:
63 |
64 | > Display the network activity indicator to provide feedback when your app accesses the network for more than a couple of seconds. If the operation finishes sooner than that, you don’t have to show the network activity indicator, because the indicator is likely to disappear before users notice its presence.
65 |
66 | */
67 | @property (nonatomic, assign) NSTimeInterval activationDelay;
68 |
69 | /**
70 | A time interval indicating the duration of time of no networking activity required before the activity indicator is disabled. This allows for continuous display of the network activity indicator across multiple requests. The default value is 0.17 seconds.
71 | */
72 |
73 | @property (nonatomic, assign) NSTimeInterval completionDelay;
74 |
75 | /**
76 | Returns the shared network activity indicator manager object for the system.
77 |
78 | @return The systemwide network activity indicator manager.
79 | */
80 | + (instancetype)sharedManager;
81 |
82 | /**
83 | Increments the number of active network requests. If this number was zero before incrementing, this will start animating the status bar network activity indicator.
84 | */
85 | - (void)incrementActivityCount;
86 |
87 | /**
88 | Decrements the number of active network requests. If this number becomes zero after decrementing, this will stop animating the status bar network activity indicator.
89 | */
90 | - (void)decrementActivityCount;
91 |
92 | /**
93 | Set the a custom method to be executed when the network activity indicator manager should be hidden/shown. By default, this is null, and the UIApplication Network Activity Indicator will be managed automatically. If this block is set, it is the responsiblity of the caller to manager the network activity indicator going forward.
94 |
95 | @param block A block to be executed when the network activity indicator status changes.
96 | */
97 | - (void)setNetworkingActivityActionWithBlock:(nullable void (^)(BOOL networkActivityIndicatorVisible))block;
98 |
99 | @end
100 |
101 | NS_ASSUME_NONNULL_END
102 |
103 | #endif
104 |
--------------------------------------------------------------------------------
/AFNetworking/UIKit+AFNetworking/UIImageView+AFNetworking.h:
--------------------------------------------------------------------------------
1 | // UIImageView+AFNetworking.h
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 |
24 | #import
25 |
26 | #if TARGET_OS_IOS || TARGET_OS_TV
27 |
28 | #import
29 |
30 | NS_ASSUME_NONNULL_BEGIN
31 |
32 | @class AFImageDownloader;
33 |
34 | /**
35 | This category adds methods to the UIKit framework's `UIImageView` class. The methods in this category provide support for loading remote images asynchronously from a URL.
36 | */
37 | @interface UIImageView (AFNetworking)
38 |
39 | ///------------------------------------
40 | /// @name Accessing the Image Downloader
41 | ///------------------------------------
42 |
43 | /**
44 | Set the shared image downloader used to download images.
45 |
46 | @param imageDownloader The shared image downloader used to download images.
47 | */
48 | + (void)setSharedImageDownloader:(AFImageDownloader *)imageDownloader;
49 |
50 | /**
51 | The shared image downloader used to download images.
52 | */
53 | + (AFImageDownloader *)sharedImageDownloader;
54 |
55 | ///--------------------
56 | /// @name Setting Image
57 | ///--------------------
58 |
59 | /**
60 | Asynchronously downloads an image from the specified URL, and sets it once the request is finished. Any previous image request for the receiver will be cancelled.
61 |
62 | If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.
63 |
64 | By default, URL requests have a `Accept` header field value of "image / *", a cache policy of `NSURLCacheStorageAllowed` and a timeout interval of 30 seconds, and are set not handle cookies. To configure URL requests differently, use `setImageWithURLRequest:placeholderImage:success:failure:`
65 |
66 | @param url The URL used for the image request.
67 | */
68 | - (void)setImageWithURL:(NSURL *)url;
69 |
70 | /**
71 | Asynchronously downloads an image from the specified URL, and sets it once the request is finished. Any previous image request for the receiver will be cancelled.
72 |
73 | If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.
74 |
75 | By default, URL requests have a `Accept` header field value of "image / *", a cache policy of `NSURLCacheStorageAllowed` and a timeout interval of 30 seconds, and are set not handle cookies. To configure URL requests differently, use `setImageWithURLRequest:placeholderImage:success:failure:`
76 |
77 | @param url The URL used for the image request.
78 | @param placeholderImage The image to be set initially, until the image request finishes. If `nil`, the image view will not change its image until the image request finishes.
79 | */
80 | - (void)setImageWithURL:(NSURL *)url
81 | placeholderImage:(nullable UIImage *)placeholderImage;
82 |
83 | /**
84 | Asynchronously downloads an image from the specified URL request, and sets it once the request is finished. Any previous image request for the receiver will be cancelled.
85 |
86 | If the image is cached locally, the image is set immediately, otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the request is finished.
87 |
88 | If a success block is specified, it is the responsibility of the block to set the image of the image view before returning. If no success block is specified, the default behavior of setting the image with `self.image = image` is applied.
89 |
90 | @param urlRequest The URL request used for the image request.
91 | @param placeholderImage The image to be set initially, until the image request finishes. If `nil`, the image view will not change its image until the image request finishes.
92 | @param success A block to be executed when the image data task finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the image created from the response data of request. If the image was returned from cache, the response parameter will be `nil`.
93 | @param failure A block object to be executed when the image data task finishes unsuccessfully, or that finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the error object describing the network or parsing error that occurred.
94 | */
95 | - (void)setImageWithURLRequest:(NSURLRequest *)urlRequest
96 | placeholderImage:(nullable UIImage *)placeholderImage
97 | success:(nullable void (^)(NSURLRequest *request, NSHTTPURLResponse * _Nullable response, UIImage *image))success
98 | failure:(nullable void (^)(NSURLRequest *request, NSHTTPURLResponse * _Nullable response, NSError *error))failure;
99 |
100 | /**
101 | Cancels any executing image operation for the receiver, if one exists.
102 | */
103 | - (void)cancelImageDownloadTask;
104 |
105 | @end
106 |
107 | NS_ASSUME_NONNULL_END
108 |
109 | #endif
110 |
--------------------------------------------------------------------------------
/FCPPSDK/UIImage+FCExtension.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIImage+FCExtension.m
3 | // FaceSDKDemo
4 | //
5 | // Created by Yang Yunxing on 2017/7/14.
6 | // Copyright © 2017年 Yang Yunxing. All rights reserved.
7 | //
8 |
9 | #import "UIImage+FCExtension.h"
10 |
11 | #define Mask8(x) ( (x) & 0xFF )
12 | #define R(x) ( Mask8(x) )
13 | #define G(x) ( Mask8(x >> 8 ) )
14 | #define B(x) ( Mask8(x >> 16) )
15 | #define A(x) ( Mask8(x >> 24) )
16 | #define RGBAMake(r, g, b, a) ( Mask8(r) | Mask8(g) << 8 | Mask8(b) << 16 | Mask8(a) << 24 )
17 |
18 | @implementation UIImage (FCExtension)
19 |
20 | - (NSString *)base64String{
21 | return [self.imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
22 | }
23 |
24 | - (NSData *)imageData{
25 | NSData *data = UIImageJPEGRepresentation(self, 1.0);
26 | NSLog(@"图片大小: %.2f MB",data.length /1000.0 /1000.0);
27 | return data;
28 | }
29 |
30 | - (UIImage *)fixImageWithMaxSize:(CGSize)maxSize{
31 | //计算尺寸缩放比例
32 | CGSize size = self.size;
33 | CGFloat scaleW = size.width / maxSize.width;
34 | CGFloat scaleH = size.height / maxSize.height;
35 | CGFloat sizeScale = scaleW > scaleH ? scaleW : scaleH;
36 |
37 | //计算大小缩放比例
38 | CGFloat imageBytes = size.width * size.height *4.0;//图片大小
39 | CGFloat maxBytes = 2 * 1000.0 *1000.0; //最大2M
40 | CGFloat byteScale = sqrtf(imageBytes /maxBytes);
41 |
42 | //取最大缩放比
43 | CGFloat scale = MAX(sizeScale, byteScale);
44 |
45 | BOOL orientationUp = self.imageOrientation == UIImageOrientationUp;//方向OK
46 | BOOL validSize = scale <= 1.0;//尺寸合适
47 | if (orientationUp && validSize){
48 | return self;
49 | }
50 |
51 | CGSize newSize = CGSizeMake(size.width/scale, size.height/scale);
52 | UIGraphicsBeginImageContext(newSize);
53 | [self drawInRect:(CGRect){0,0,newSize}];
54 | UIImage *fixImage = UIGraphicsGetImageFromCurrentImageContext();
55 | UIGraphicsEndImageContext();
56 | return fixImage;
57 | }
58 |
59 | - (UIImage *)cropWithRect:(CGRect)rect{
60 | CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], rect);
61 | UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];
62 | CGImageRelease(imageRef);
63 | return croppedImage;
64 | }
65 |
66 | - (UIImage *) blendWithGrayImage:(UIImage *)grayImage backgroudColor:(long)hexColor{
67 |
68 | UInt32 * inputPixels;
69 |
70 | CGImageRef inputCGImage = [self CGImage];
71 | NSUInteger inputWidth = CGImageGetWidth(inputCGImage);
72 | NSUInteger inputHeight = CGImageGetHeight(inputCGImage);
73 |
74 | CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
75 |
76 | NSUInteger bytesPerPixel = 4;
77 | NSUInteger bitsPerComponent = 8;
78 |
79 | NSUInteger inputBytesPerRow = bytesPerPixel * inputWidth;
80 |
81 | inputPixels = (UInt32 *)calloc(inputHeight * inputWidth, sizeof(UInt32));
82 |
83 | CGContextRef context = CGBitmapContextCreate(inputPixels, inputWidth, inputHeight,
84 | bitsPerComponent, inputBytesPerRow, colorSpace,
85 | kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
86 |
87 | CGContextDrawImage(context, CGRectMake(0, 0, inputWidth, inputHeight), inputCGImage);
88 | CGImageRef ghostCGImage = [grayImage CGImage];
89 |
90 | // 2.1 Calculate the size & position of the ghost
91 | CGFloat ghostImageAspectRatio = grayImage.size.width / grayImage.size.height;
92 | NSInteger targetGhostWidth = inputWidth;
93 | CGSize ghostSize = CGSizeMake(targetGhostWidth, targetGhostWidth / ghostImageAspectRatio);
94 | CGPoint ghostOrigin = CGPointMake(0, 0);
95 |
96 | // 2.2 Scale & Get pixels of the ghost
97 | NSUInteger ghostBytesPerRow = bytesPerPixel * ghostSize.width;
98 |
99 | UInt32 * ghostPixels = (UInt32 *)calloc(ghostSize.width * ghostSize.height, sizeof(UInt32));
100 |
101 | CGContextRef ghostContext = CGBitmapContextCreate(ghostPixels, ghostSize.width, ghostSize.height,
102 | bitsPerComponent, ghostBytesPerRow, colorSpace,
103 | kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
104 |
105 | CGContextDrawImage(ghostContext, CGRectMake(0, 0, ghostSize.width, ghostSize.height),ghostCGImage);
106 |
107 | // 2.3 Blend each pixel
108 |
109 | //background color
110 | //0x开头的十六进制转换成的颜色
111 | CGFloat R_back = ((float)((hexColor & 0xFF0000) >> 16));
112 | CGFloat G_back = ((float)((hexColor & 0xFF00) >> 8));
113 | CGFloat B_back = ((float)(hexColor & 0xFF));
114 |
115 | NSUInteger offsetPixelCountForInput = ghostOrigin.y * inputWidth + ghostOrigin.x;
116 | for (NSUInteger j = 0; j < ghostSize.height; j++) {
117 | for (NSUInteger i = 0; i < ghostSize.width; i++) {
118 | UInt32 * inputPixel = inputPixels + j * inputWidth + i + offsetPixelCountForInput;
119 | UInt32 inputColor = *inputPixel;
120 |
121 | UInt32 * ghostPixel = ghostPixels + j * (int)ghostSize.width + i;
122 | UInt32 ghostColor = *ghostPixel;
123 |
124 | CGFloat confidence = (R(ghostColor)+G(ghostColor)+B(ghostColor)) / 3.0 / 255.0;
125 |
126 | //用置信度标识透明度
127 | CGFloat alpha = confidence;
128 | UInt32 newR = R(inputColor) *alpha + R_back *(1 - alpha);
129 | UInt32 newG = G(inputColor) *alpha + G_back *(1 - alpha);
130 | UInt32 newB = B(inputColor) *alpha + B_back *(1 - alpha);
131 |
132 | //Clamp, not really useful here :p
133 | newR = MAX(0,MIN(255, newR));
134 | newG = MAX(0,MIN(255, newG));
135 | newB = MAX(0,MIN(255, newB));
136 |
137 | *inputPixel = RGBAMake(newR, newG, newB, A(inputColor));
138 | }
139 | }
140 |
141 | // 4. Create a new UIImage
142 | CGImageRef newCGImage = CGBitmapContextCreateImage(context);
143 | UIImage *newImage = [UIImage imageWithCGImage:newCGImage];
144 |
145 | // 5. Cleanup!
146 | CGColorSpaceRelease(colorSpace);
147 | CGContextRelease(context);
148 | CGContextRelease(ghostContext);
149 | free(inputPixels);
150 | free(ghostPixels);
151 |
152 | return newImage;
153 | }
154 | @end
155 |
--------------------------------------------------------------------------------
/AFNetworking/UIKit+AFNetworking/AFAutoPurgingImageCache.h:
--------------------------------------------------------------------------------
1 | // AFAutoPurgingImageCache.h
2 | // Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
3 | //
4 | // Permission is hereby granted, free of charge, to any person obtaining a copy
5 | // of this software and associated documentation files (the "Software"), to deal
6 | // in the Software without restriction, including without limitation the rights
7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | // copies of the Software, and to permit persons to whom the Software is
9 | // furnished to do so, subject to the following conditions:
10 | //
11 | // The above copyright notice and this permission notice shall be included in
12 | // all copies or substantial portions of the Software.
13 | //
14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 | // THE SOFTWARE.
21 |
22 | #import
23 | #import
24 |
25 | #if TARGET_OS_IOS || TARGET_OS_TV
26 | #import
27 |
28 | NS_ASSUME_NONNULL_BEGIN
29 |
30 | /**
31 | The `AFImageCache` protocol defines a set of APIs for adding, removing and fetching images from a cache synchronously.
32 | */
33 | @protocol AFImageCache
34 |
35 | /**
36 | Adds the image to the cache with the given identifier.
37 |
38 | @param image The image to cache.
39 | @param identifier The unique identifier for the image in the cache.
40 | */
41 | - (void)addImage:(UIImage *)image withIdentifier:(NSString *)identifier;
42 |
43 | /**
44 | Removes the image from the cache matching the given identifier.
45 |
46 | @param identifier The unique identifier for the image in the cache.
47 |
48 | @return A BOOL indicating whether or not the image was removed from the cache.
49 | */
50 | - (BOOL)removeImageWithIdentifier:(NSString *)identifier;
51 |
52 | /**
53 | Removes all images from the cache.
54 |
55 | @return A BOOL indicating whether or not all images were removed from the cache.
56 | */
57 | - (BOOL)removeAllImages;
58 |
59 | /**
60 | Returns the image in the cache associated with the given identifier.
61 |
62 | @param identifier The unique identifier for the image in the cache.
63 |
64 | @return An image for the matching identifier, or nil.
65 | */
66 | - (nullable UIImage *)imageWithIdentifier:(NSString *)identifier;
67 | @end
68 |
69 |
70 | /**
71 | The `ImageRequestCache` protocol extends the `ImageCache` protocol by adding methods for adding, removing and fetching images from a cache given an `NSURLRequest` and additional identifier.
72 | */
73 | @protocol AFImageRequestCache
74 |
75 | /**
76 | Adds the image to the cache using an identifier created from the request and additional identifier.
77 |
78 | @param image The image to cache.
79 | @param request The unique URL request identifing the image asset.
80 | @param identifier The additional identifier to apply to the URL request to identify the image.
81 | */
82 | - (void)addImage:(UIImage *)image forRequest:(NSURLRequest *)request withAdditionalIdentifier:(nullable NSString *)identifier;
83 |
84 | /**
85 | Removes the image from the cache using an identifier created from the request and additional identifier.
86 |
87 | @param request The unique URL request identifing the image asset.
88 | @param identifier The additional identifier to apply to the URL request to identify the image.
89 |
90 | @return A BOOL indicating whether or not all images were removed from the cache.
91 | */
92 | - (BOOL)removeImageforRequest:(NSURLRequest *)request withAdditionalIdentifier:(nullable NSString *)identifier;
93 |
94 | /**
95 | Returns the image from the cache associated with an identifier created from the request and additional identifier.
96 |
97 | @param request The unique URL request identifing the image asset.
98 | @param identifier The additional identifier to apply to the URL request to identify the image.
99 |
100 | @return An image for the matching request and identifier, or nil.
101 | */
102 | - (nullable UIImage *)imageforRequest:(NSURLRequest *)request withAdditionalIdentifier:(nullable NSString *)identifier;
103 |
104 | @end
105 |
106 | /**
107 | The `AutoPurgingImageCache` in an in-memory image cache used to store images up to a given memory capacity. When the memory capacity is reached, the image cache is sorted by last access date, then the oldest image is continuously purged until the preferred memory usage after purge is met. Each time an image is accessed through the cache, the internal access date of the image is updated.
108 | */
109 | @interface AFAutoPurgingImageCache : NSObject
110 |
111 | /**
112 | The total memory capacity of the cache in bytes.
113 | */
114 | @property (nonatomic, assign) UInt64 memoryCapacity;
115 |
116 | /**
117 | The preferred memory usage after purge in bytes. During a purge, images will be purged until the memory capacity drops below this limit.
118 | */
119 | @property (nonatomic, assign) UInt64 preferredMemoryUsageAfterPurge;
120 |
121 | /**
122 | The current total memory usage in bytes of all images stored within the cache.
123 | */
124 | @property (nonatomic, assign, readonly) UInt64 memoryUsage;
125 |
126 | /**
127 | Initialies the `AutoPurgingImageCache` instance with default values for memory capacity and preferred memory usage after purge limit. `memoryCapcity` defaults to `100 MB`. `preferredMemoryUsageAfterPurge` defaults to `60 MB`.
128 |
129 | @return The new `AutoPurgingImageCache` instance.
130 | */
131 | - (instancetype)init;
132 |
133 | /**
134 | Initialies the `AutoPurgingImageCache` instance with the given memory capacity and preferred memory usage
135 | after purge limit.
136 |
137 | @param memoryCapacity The total memory capacity of the cache in bytes.
138 | @param preferredMemoryCapacity The preferred memory usage after purge in bytes.
139 |
140 | @return The new `AutoPurgingImageCache` instance.
141 | */
142 | - (instancetype)initWithMemoryCapacity:(UInt64)memoryCapacity preferredMemoryCapacity:(UInt64)preferredMemoryCapacity;
143 |
144 | @end
145 |
146 | NS_ASSUME_NONNULL_END
147 |
148 | #endif
149 |
150 |
--------------------------------------------------------------------------------