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