IOS recognizes and depicts the QR code border, and ios depicts the border

Source: Internet
Author: User

IOS recognizes and depicts the QR code border, and ios depicts the border

OpenCV can be used to identify the QR code and describe its border,
How can I change to an apple AVFoundation for scanning and how can I draw the border of a QR code?
We know that the scanned result contains an array, while the array contains AVMetadataMachineReadableCodeObject, And the AVMetadataMachineReadableCodeObject contains a corners array, which records the coordinates of the QR code. The parsing given in this document is as follows:
/*!
@ Property corners
@ Abstract
The points defining the (X, Y) locations of the corners of the machine-readable code.

@ Discussion
The value of this property is an NSArray of NSDictionaries, each of which has been created from a CGPoint using CGPointCreateDictionaryRepresentation (), representing the coordinates of the corners of the object with respect to the image in which it resides. if the metadata originates from video, the points may be expressed as scalar values from 0. -1. the points in the corners differ from the bounds rectangle in that bounds is axis-aligned to orientation of the captured image, and the values of the corners reside within the bounds rectangle. the points are arranged in counter-clockwise order (clockwise if the code or image is mirrored), starting with the top-left of the code in its canonical orientation.
*/
After reading the official documents and related materials, we can easily think of using corners to obtain the coordinates and shapes of the QR code. To describe.
The main code for plotting a border is as follows:

/*** The layer used to save the stroke ***/@ property (nonatomic, strong) CALayer * containerLayer;-(void) drawLine :( AVMetadataMachineReadableCodeObject *) objc {NSArray * array = objc. corners; // 1. create a shape layer to save the drawn rectangle CAShapeLayer * layer = [[CAShapeLayer alloc] init]; // set the line width layer. lineWidth = 2; // set the stroke color layer. strokeColor = [UIColor greenColor]. CGColor; layer. fillColor = [UIColor clearColor]. CGColor; // 2. create UIBezierPath and draw the rectangle UIBezierPath * path = [[UIBezierPath alloc] init]; CGPoint point = CGPointZero; int index = 0; CFDictionaryRef dict = (_ bridge CFDictionaryRef) (array [index ++]); // converts a vertex to an immutable dictionary // converts a dictionary to a vertex. If a vertex exists, true is returned. Otherwise, false CGPointMakeWithDictionaryRepresentation (dict, & point); // set the starting point [path moveToPoint: point]; NSLog (@ "X: % f -- Y: % f", point. x, point. y); // 2.2 connect other line segments for (int I = 1; I

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.