Skip to content

Instantly share code, notes, and snippets.

@SunXiaoShan
Created March 22, 2018 03:06
Show Gist options
  • Save SunXiaoShan/f894a4daedace6a987c93fd6cc639c7f to your computer and use it in GitHub Desktop.
Save SunXiaoShan/f894a4daedace6a987c93fd6cc639c7f to your computer and use it in GitHub Desktop.
FD
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection {
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CFDictionaryRef attachments = CMCopyDictionaryOfAttachments(kCFAllocatorDefault, sampleBuffer, kCMAttachmentMode_ShouldPropagate);
CIImage *ciImage = [[CIImage alloc] initWithCVPixelBuffer:pixelBuffer
options:(__bridge NSDictionary *)attachments];
if (attachments) {
CFRelease(attachments);
}
// make sure your device orientation is not locked.
UIDeviceOrientation curDeviceOrientation = [[UIDevice currentDevice] orientation];
NSDictionary *imageOptions = nil;
imageOptions = [NSDictionary dictionaryWithObject:[self exifOrientation:curDeviceOrientation]
forKey:CIDetectorImageOrientation];
NSArray *features = [self._faceDetector featuresInImage:ciImage
options:imageOptions];
CMFormatDescriptionRef fdesc = CMSampleBufferGetFormatDescription(sampleBuffer);
CGRect cleanAperture = CMVideoFormatDescriptionGetCleanAperture(fdesc, false /*originIsTopLeft == false*/);
dispatch_async(dispatch_get_main_queue(), ^(void) {
[self drawFaces:features
forVideoBox:cleanAperture
orientation:curDeviceOrientation];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment