This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func detectFaceIn(imageBuffer: CVImageBuffer) { | |
let image = CIImage(cvImageBuffer: imageBuffer) | |
let accuracy = [CIDetectorAccuracy: CIDetectorAccuracyHigh] | |
let faceDetector = CIDetector(ofType: CIDetectorTypeFace, context: nil, options: accuracy) | |
let faces = faceDetector?.features(in: image) | |
let imageSize = CVImageBufferGetDisplaySize(imageBuffer) | |
var actualRect = CGRect() | |
for face in faces! { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@property (assign) BOOL prepared; | |
@implementation MLWrapper { | |
dlib::shape_predictor sp; | |
} | |
- (void)prepare { | |
NSString *modelFileName = [[NSBundle mainBundle] pathForResource:@"shape_predictor_68_face_landmarks" ofType:@"dat"]; | |
std::string modelFileNameCString = [modelFileName UTF8String]; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (NSMutableArray *)doWorkOnSampleBuffer:(UIImage *)image inRects:(NSArray<NSValue *> *)rects { | |
dlib::array2d<dlib::bgr_pixel> dlibImage; | |
// convert uiimage to dlib image | |
CGFloat width = image.size.width, height = image.size.height; | |
CGContextRef context; | |
size_t pixelBits = CGImageGetBitsPerPixel(image.CGImage); | |
size_t pixelBytes = pixelBits/8; |