IOS AV Foundation qr code scan 02 Sweep code

Source: Internet
Author: User

Avfoundation supports the following one-and two-dimensional code scanning:

    • QR Code
    • Aztec
    • EAN13
    • EAN8
    • Upc-e
    • PDF417
    • Code 93
    • Code 39
    • Code 41 Mode

QR code is the two-dimensional code we are familiar with.

Open VIEWCONTROLLER.M and add the following instance variable:

Avcapturemetadataoutput *_metadataoutput;
When metadata is detected from a video frame, Avcapturemetadataoutput invokes the application's callback function. AV Foundation supports two types of metadata: machine-readable encoding and face recognition.

Add the following code to the end of setupcapturesession to implement the capture and processing of the metadata:

    _metadataoutput = [[Avcapturemetadataoutput alloc] init];    dispatch_queue_t metadataqueue = dispatch_queue_create ("Com.yaming.ColloQR.metadata", 0);    [_metadataoutput setmetadataobjectsdelegate:self queue:metadataqueue];        if ([_capturesession canaddoutput:_metadataoutput])    {        [_capturesession addoutput:_metadataoutput];    }
Here, we first create an instance of Avcapturemetadataoutput and then create a dispatch queue for it, which prevents the main thread from blocking when the callback function is called.

Next, declare this class to follow the Avcapturemetadataoutputobjectsdelegate agreement:

@interface Viewcontroller () <AVCaptureMetadataOutputObjectsDelegate>
To implement the Proxy method:

-(void) Captureoutput: (Avcaptureoutput *) captureoutput didoutputmetadataobjects: (Nsarray *) metadataobjects Fromconnection: (avcaptureconnection *) connection{    [Metadataobjects enumerateobjectsusingblock:^ ( Avmetadataobject *obj,                                                  nsuinteger idx,                                                  BOOL *stop)     {         NSLog (@ "Metadata:%@", obj);     }];}
Whenever the Avcapturemetadataoutput class detects new metadata, the Captureoutput method is called, and in the Captureoutput method, we print all the detected metadata.

To modify the Startrunning method, add the following code at the end:

    _metadataoutput.metadataobjecttypes = _metadataoutput.availablemetadataobjecttypes;
The purpose of this is to set the metadata type to be detected for all types.

Compile and run, scan the following two-D code to get the following output:



2015-03-21 14:51:42.289 colloqr[680:176124] Metadata: <avmetadatamachinereadablecodeobject:0x170221540, type= " Org.iso.QRCode ", bounds={0.4,0.2 0.1x0.3}>corners {0.4,0.5 0.5,0.5 0.5,0.2 0.4,0.2}, Time 31026866447458, StringVal UE "ios QR code scan"
This completes the function of QR code scanning using AV Foundation. As you can see from log, there are bounds and conrners information, and in the next section we will use this information to provide visual feedback to the user when the code is successful.

Reprint Please specify source: http://blog.csdn.net/yamingwu/article/details/44515625

IOS AV Foundation qr code scan 02 Sweep code

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.