iOS 識別二維碼及描繪二維碼邊框,ios描繪邊框

來源:互聯網
上載者:User

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來擷取二維碼的座標,大小形狀。從而進行描繪。
描繪邊框主要代碼如下:

/*** 專門用於儲存描邊的圖層 ***/@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               

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.