1

顔の領域をキャプチャしようとしています。

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


}
}
4

1 に答える 1