如何从UIImage中提取AVMetadataObject? [英] How can I extract an AVMetadataObject from a UIImage?
问题描述
我想使用iOS 7的新条码扫描功能和 UIImage
,而不是从设备的相机中实时捕捉。我已经通过 AVCaptureDeviceInput
对检测进行了正常工作。
I'd like to use iOS 7's new barcode scanning functionality with a UIImage
instead of live capture from one of the device's camera. I already have the detection working fine with an AVCaptureDeviceInput
.
我认为这样做的最好方法是创建一个 AVCaptureInput
的具体子类,它从 UIImage UIImage AVCaptureSession
提供媒体数据。但是,我找不到任何关于如何子类 AVCaptureInput
的文档或示例,所以我不知所措。
The best way I think to do this would be to create a concrete subclass of AVCaptureInput
that provides media data to an AVCaptureSession
from a UIImage
. However, I can't find any documentation or examples on how to subclass AVCaptureInput
, so I'm at a loss.
另一种方法是从现有的 AVCaptureDeviceInput
覆盖媒体流,但由于这些API是私有的,我想在App Store上发布我的应用,这不太理想。
An alternative would be to override the media stream from an existing AVCaptureDeviceInput
, but since those API's are private and I'd like to publish my app on the App Store, this isn't ideal.
最终,我可能最终会使用像ZXing或ZBar这样的第三方条形码库来做这件事,但这似乎是浪费能够在这里使用Apple的内置功能。</ p>
Ultimately, I'll likely end up doing this using a 3rd party barcode library like ZXing or ZBar, but it seems like a waste to not be able to use Apple's built-in functionality here.
推荐答案
生活很简单。
您可以使用CIDetector。
将图像转换为CIImage,由CIDetector解码。
life is easy. You can use CIDetector instead. Convert an image into CIImage to be decoded by CIDetector.
这篇关于如何从UIImage中提取AVMetadataObject?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!