iOS Development-Facial Distance Recognition Vision Eye Protection Mode Child Myopia Prevention Function
Preface-Based on Vision and CIDetector
In iOS development, there is a function that needs to keep children from viewing distance, eye protection mode.
For example
General idea
- Principle parameters of imaging through the small hole of the camera of the mobile phone
- Capture and turn the captured image of the face
- Use Vision for iOS10 and above, otherwise use CIDetector to identify distance
API
+ (BOOL)isSupported;
- (void)setCompleteBlock:(FDFaceDistanceBlock)block;
- (void)start;
- (void)stop;
- (void)pause;
- (void)resume;
use
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:self.label];
__weak typeof(self) weakSelf = self;
[FDFaceToCameraDistance startWithConfiguration:[self createFDConfig] detectBlock:^(BOOL success, NSUInteger distance) {
NSLog(@"face distance %ld", distance);
if(distance > 100) {
NSLog(@"has not get you face");
} else {
weakSelf.label.text = [NSString stringWithFormat:@"face distance is %ld", distance];
}
}];
}
- (FDConfiguration *)createFDConfig {
FDConfiguration *config = [[FDConfiguration alloc] init];
config.repeatCount = NSIntegerMax;
config.firstRepeatDelay = 5.0;
config.timeInterval = 2.0;
return config;
}