我正在尝试捕捉面部区域。
这是我在didOutputMetadataObjects 中所做的:获取 AVMetadataFaceObject 并在didOutputSampleBuffer中处理它
didOutputMetadataObjects正确显示标记,我考虑偏航,滚动轴
什么可能是最好的方法,我只得到面部区域,同时我看到一个面部标记?
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection
{
for(AVMetadataObject *metaObject in metadataObjects){
if([metaObject isKindOfClass:[AVMetadataFaceObject class ]] && metaObject.type == AVMetadataObjectTypeFace){
AVMetadataFaceObject * adjustedMeta = (AVMetadataFaceObject*)[self.videoLayer transformedMetadataObjectForMetadataObject:metaObject];
self.metaFaceObject= adjustedMeta;
//Draw the face marker here
}
}
}
AVCaptureVideoDataOutputSampleBufferDelegate
-(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection{
CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
if(pixelBuffer ){
CFDictionaryRef attachments = CMCopyDictionaryOfAttachments( kCFAllocatorDefault, sampleBuffer, kCMAttachmentMode_ShouldPropagate );
CIImage *ciImage = [[CIImage alloc] initWithCVPixelBuffer:pixelBuffer options:(__bridge NSDictionary<NSString *,id> * _Nullable)(attachments)];
ciImage = [ciImage imageByCroppingToRect:self.metaFaceObject.bounds];
//This Image is upside down. Second thing the it does not have the face.
UIImage *image=[UIImage imageWithCIImage:ciImage];
}
}