Reputation: 1
Issue is unstable (size jump between two sizes at every update) size returned by transformedMetadataObjectForMetadataObject only if i use it to resize previewLayer.
for(AVMetadataObject *metadataObject in metadataObjects) {
if([metadataObject.type isEqualToString:AVMetadataObjectTypeFace]) {
// Take an image of the face and pass to CoreImage for detection
AVMetadataObject *metadataObjectR=[previewLayer transformedMetadataObjectForMetadataObject:metadataObject];
previewLayer.bounds = CGRectMake(previewLayer.bounds.origin.x,previewLayer.bounds.origin.y, metadataObjectR.bounds.size.width,metadataObjectR.bounds.size.height);
Code for creating previewLayer (previewViewLayer is CALayer)
[captureSession addInput:vInput];
[captureSession setSessionPreset:AVCaptureSessionPresetPhoto];
previewViewLayer = [self.view layer];
[previewViewLayer setBackgroundColor:(__bridge CGColorRef _Nullable)([UIColor blackColor])];
previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:captureSession];
[previewLayer setFrame:[previewViewLayer bounds]];
[previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[previewViewLayer addSublayer:previewLayer];
Upvotes: 0
Views: 356
Reputation: 84
I don't know what are you want to do.The function transformedMetadataObjectForMetadataObject,return the metaDataObject which in the previewLayer coordinates,so the bounds of it is the metaDataObject`s frame.But you use this frame to set the previewLayer's bounds.The previewLayer's frame should not change,because it is use to preview the camera.You should use the new metaDataObject's bounds to change the frame of the layer indicate the face.
Upvotes: 0