You will need to use the corners property from AVMetadataMachineReadableCodeObject to draw a perspective box around the detected code.
See my example at https://github.com/werner77/WECodeScanner
Question
I Have problem with detect where is qr code.
I need draw border around it.
I use AVMetadataObject bezierpath, but it dont work.
Please help me.
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputMetadataObjects:(NSArray *)metadataObjects
fromConnection:(AVCaptureConnection *)connection
{
for (AVMetadataObject *metadata in metadataObjects)
{
AnimationView *cv = [[AnimationView alloc]initWithFrame:self.livevideo.bounds]; //creat an instance of your custom view
[cv setBackgroundColor:[UIColor clearColor]];
NSLog(@"%f",metadata.accessibilityPath.accessibilityActivationPoint.x);
[location addSubview:cv];
if ([metadata.type isEqualToString:AVMetadataObjectTypeEAN13Code])
{
}
else if ([metadata.type isEqualToString:AVMetadataObjectTypeUPCECode])
{
}
else if ([metadata.type isEqualToString:AVMetadataObjectTypeEAN8Code])
{
}
else if ([metadata.type isEqualToString:AVMetadataObjectTypeQRCode])
{
}
}
}
Solution
You will need to use the corners property from AVMetadataMachineReadableCodeObject to draw a perspective box around the detected code.
See my example at https://github.com/werner77/WECodeScanner
OTHER TIPS
Use the transformedMetadataObject(for:)
method on AVCaptureVideoPreviewLayer
.
In the AVCaptureMetadataOutputObjectsDelegate
method below, the previewLayer
is an instance of AVCaptureVideoPreviewLayer
.
func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
if let metadataObject = metadataObjects.first, let transformedMetadataObject = previewLayer.transformedMetadataObject(for: metadataObject) {
print(transformedMetadataObject.bounds)
}
}