iOS 7 What’s New in AV Foundation之二维码扫描(中)
来源:互联网 发布:户型改造软件 编辑:程序博客网 时间:2024/05/23 20:06
接上文
英语不是很好有些专业的东西还是不给翻译了 自己百度吧
没有太多难懂的东西 慢慢来
对了 声明一下 这两篇的内容都是官方文档上弄来的 鸟悄的啊 我也是花钱买的 我是觉得写得真心好才共享给大家的
Detecting machine readable codes
In addition to processing and displaying video, AV Foundation detects and decodesa comprehensive list of 1-D and 2-D barcodes:
1. QR code2. Aztec
3. EAN134. EAN8
5. UPC-E
6. PDF417
7. Code 93
8. Code 39
9. Code 39 mod 43
You have probably seen some of these codes in action, even though you may nothave known their names. EAN13 is a common standard in Europe for markingitems, whereas UPC-E is favored in the United States. PDF417 is used by some mailservices and is also the standard for airline boarding passes.
However, the QR code is probably pretty familiar to mobile users; that’s the type ofcode you’ll read in your app.
OpenViewController.mand add the following instance variable to theimplementation block:
AVCaptureMetadataOutput*_metadataOutput;
AVCaptureMetadataOutputprovides a callback to the application when metadata isdetected in a video frame. AV Foundation supports two types of metadata: machinereadable codes and face detection.
You need a way to capture and process that metadata. Add the following code tothe end ofsetupCaptureSessioninViewController.m:
_metadataOutput= [[AVCaptureMetadataOutputalloc]init];
dispatch_queue_tmetadataQueue =dispatch_queue_create("com.razeware.ColloQR.metadata",0);
[_metadataOutputsetMetadataObjectsDelegate:selfqueue:metadataQueue];
if([_captureSessioncanAddOutput:_metadataOutput]) {[_captureSessionaddOutput:_metadataOutput];
}
Here you initialize the output with a delegate and then add it to the session. Just asyou did with the inputs, you need to query canAddOutput:first to see if it’s okay toadd an output to your session.
AV Foundation is designed for high throughput and low latency; therefore anyprocessing and analysis tasks should be moved off of the main thread if at allpossible.
Similar to the delegate object,AVCaptureMetadataOutputrequires that you providea dispatch queue to make delegate callbacks. This frees the media subsystem tocontinue processing frames from the camera. If callbacks were executed in asynchronous manner, a long-running delegate callback would block frameprocessing until it was complete.
This might not be an issue in a simple one-input one-output system. However,asynchronous processing of callbacks is key in a multi-output system so that long-running callbacks on one output don’t cause frame drops in other outputs.
InViewController.m, modify the class continuation category declaration as shownbelow:
@interfaceViewController()<AVCaptureMetadataOutputObjectsDelegate>
Next, add the following method toViewController.mto implement the delegatedeclared:
- (void)captureOutput:(AVCaptureOutput*)captureOutputdidOutputMetadataObjects:(NSArray*)metadataObjects
fromConnection:(AVCaptureConnection*)connection
{
[metadataObjects enumerateObjectsUsingBlock:^(AVMetadataObject*obj,NSUIntegeridx,BOOL*stop){
NSLog(@"Metadata: %@", obj);}];
}
The metadata output calls the above method every time it detects new metadata.At this point, the code simply logs each piece of metadata as it’s detected. This issufficient for testing purposes; you’ll flesh out the rest of this implementation later.
There’s one last tweak before you can build and run. Add the following line tostartRunninginViewController.m,immediately underneath the line[_captureSession startRunning];:
_metadataOutput.metadataObjectTypes=_metadataOutput.availableMetadataObjectTypes;
This sets the types of metadata in which your app is interested; in this case you’lldetect all available types of metadata.
Build and run your app; pass your camera over the following QR code while keepingan eye on the Xcode console:
Once your device processes the QR code above, you should see the following outputdisplayed:
2013-07-03 21:57:03.758 ColloQR[1262:1303] Metadata:<AVMetadataMachineReadableCodeObject: 0x15e515d0> type"org.iso.QRCode", bounds { 0.2,0.1 0.5x0.8 }, corners { 0.2,0.90.2,0.1 0.7,0.1 0.7,0.9 }, time 31399588077583, stringValue "W00t! AQR code!"
There you are — your first scanned QR code. Feel free to try this out on any otherQR codes nearby, or perform a quick Internet search.
Look closely at the output above and you’ll see the metadata includes moreinformation than just the contents of the code instringValue, including thebounds and corners of the QR image.
You’re not done yet! Many code readers provide visual feedback to the user toindicate if the code is properly positioned and capable of being read; next you’ll usethe bounds and corner metadata to draw an overlay on the camera view to achievethis.
- iOS 7 What’s New in AV Foundation之二维码扫描(中)
- iOS 7 What’s New in AV Foundation之二维码扫描(上)
- iOS 7 What’s New in AV Foundation之二维码扫描(下)
- iOS7中Objective-C和Foundation的新特性(What’s New in Objective-C and Foundation in iOS 7)
- iOS7中Objective-C和Foundation的新特性(What’s New in Objective-C and Foundation in iOS 7)
- iOS AV Foundation 二维码扫描 01 使用摄像头
- iOS AV Foundation 二维码扫描 02 扫码
- iOS AV Foundation 二维码扫描 05 缩放摄像头
- iOS AV Foundation 二维码扫描 03 为扫描到的二维码添加可视化效果
- What's New in iOS
- iOS AV Foundation 二维码扫描 04 使用合成语音朗读二维码内容
- iOS AV Foundation 二维码扫描 04 使用合成语音朗读二维码内容
- What’s New in iOS 4.3
- what's new in iOS草稿
- What's New in Dxperience 7.3.7
- What’s new in Windows 7
- What’s New in WebSphere Portal 7
- iOS 各版本中的新特性(What's New in iOS)- 目录翻译完成
- metapost的一个问题
- AlertDialog显示错误 Unable to add window token null is not for an application
- LM324差分放大
- 浅谈C++中的内存管理
- GridView那点事之【隐藏某列字段】
- iOS 7 What’s New in AV Foundation之二维码扫描(中)
- 读取硬盘ID
- python 安装redis
- python insert 和分片赋值
- hud1198 Farm Irrigation
- 【进村记】我们来说说某宝
- 隐藏基类成员 浅谈
- 2.MIL开发基础概念和步骤
- rt5350 学习笔记