-
-
Save SunXiaoShan/f894a4daedace6a987c93fd6cc639c7f to your computer and use it in GitHub Desktop.
FD
This file contains hidden or 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
- (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