iOS Development-Facial Distance Recognition Vision Eye Protection Mode Child Myopia Prevention Function

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

Insert picture description here

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;
}

Demo

Demo site

Guess you like

Origin blog.csdn.net/weixin_41732253/article/details/109710811