IOS开发入门之iOS 识别二维码及描绘二维码边框
凌雪 2018-10-10 来源 :网络 阅读 1094 评论 0

摘要:本文将带你了解IOS开发入门iOS 识别二维码及描绘二维码边框,希望本文对大家学IOS有所帮助。

本文将带你了解IOS开发入门iOS 识别二维码及描绘二维码边框,希望本文对大家学IOS有所帮助。


         

用OpenCV可以实现,识别二维码,并将其边框描绘出来,
如何换成苹果AVFoundation来扫描,如何描绘出二维码的边框呢?
我们知道,扫描结果AVCaptureMetadataOutputObjectsDelegate是返回了数组,而数组里面是一个个的AVMetadataMachineReadableCodeObject,而AVMetadataMachineReadableCodeObject中有个corners数组,记录二维码的坐标,文档给出的解析如下:
/*!
@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.
*/
查阅了官方文档和相关资料,我们很容易联想到,通过corners来获取二维码的坐标,大小形状。从而进行描绘。
描绘边框主要代码如下:

?

本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之IOS频道

/*** 专门用于保存描边的图层 ***/

@property (nonatomic,strong) CALayer   *containerLayer;

 

-   (void)drawLine:(AVMetadataMachineReadableCodeObject   *)objc

{

 

    NSArray *array =   objc.corners;

 

    // 1.创建形状图层,   用于保存绘制的矩形

    CAShapeLayer *layer = [[CAShapeLayer alloc]   init];

 

    // 设置线宽

    layer.lineWidth = 2;

    // 设置描边颜色

    layer.strokeColor = [UIColor   greenColor].CGColor;

    layer.fillColor = [UIColor   clearColor].CGColor;

 

    // 2.创建UIBezierPath, 绘制矩形

    UIBezierPath *path = [[UIBezierPath alloc]   init];

    CGPoint point = CGPointZero;

    int index = 0;

 

    CFDictionaryRef dict = (__bridge   CFDictionaryRef)(array[index++]);

    // 把点转换为不可变字典

    // 把字典转换为点,存在point里,成功返回true   其他false

    CGPointMakeWithDictionaryRepresentation(dict,   &point);

 

    // 设置起点

    [path   moveToPoint:point];

    NSLog(@"X:%f -- Y:%f",point.x,point.y);

 

    // 2.2连接其它线段

    for (int i   = 1;   i

                     

    </array.count;>



本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之IOS频道!


本文由 @凌雪 发布于职坐标。未经许可,禁止转载。
喜欢 | 0 不喜欢 | 0
看完这篇文章有何感觉?已经有0人表态,0%的人喜欢 快给朋友分享吧~
评论(0)
后参与评论

您输入的评论内容中包含违禁敏感词

我知道了

助您圆梦职场 匹配合适岗位
验证码手机号,获得海同独家IT培训资料
选择就业方向:
人工智能物联网
大数据开发/分析
人工智能Python
Java全栈开发
WEB前端+H5

请输入正确的手机号码

请输入正确的验证码

获取验证码

您今天的短信下发次数太多了,明天再试试吧!

提交

我们会在第一时间安排职业规划师联系您!

您也可以联系我们的职业规划师咨询:

小职老师的微信号:z_zhizuobiao
小职老师的微信号:z_zhizuobiao

版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
 沪公网安备 31011502005948号    

©2015 www.zhizuobiao.com All Rights Reserved

208小时内训课程