我正在尝试创建一个应用程序,使用 MLKit 的文本检测功能来检测设备相机拍摄的照片中的文本。下面是我的 photoOutput 方法中的代码,以及它调用的方法的代码:
func photoOutput(_ output: AVCapturePhotoOutput,
didFinishProcessingPhoto photo: AVCapturePhoto,
error: Error?) {
print("worked")
PHPhotoLibrary.shared().performChanges( {
let creationRequest = PHAssetCreationRequest.forAsset()
creationRequest.addResource(with: PHAssetResourceType.photo, data: photo.fileDataRepresentation()!, options: nil)
}, completionHandler: nil)
let cgImage = photo.cgImageRepresentation()!.takeRetainedValue()
print(cgImage)
let orientation = photo.metadata[kCGImagePropertyOrientation as String] as! NSNumber
let uiOrientation = UIImage.Orientation(rawValue: orientation.intValue)!
let image = UIImage(cgImage: cgImage, scale: 1, orientation: uiOrientation)
self.runTextRecognition(with: image)
}
func runTextRecognition(with image: UIImage) {
let visionImage = VisionImage(image: image)
textRecognizer.process(visionImage) { features, error in
self.processResult(from: features, error: error)
}
}
func processResult(from text: VisionText?, error: Error?) {
guard error == nil, let text = text else {
print("oops")
return
}
print(text.text)
}
每当我运行应用程序并拍照时,一切都运行良好,直到行 textRecognizer.process(visionImage)。控制台消息是 -[Not A Type _cfTypeID]: message sent to deallocated instance 0x106623e20.
如有任何帮助或建议,我们将不胜感激!如果我应该包含更多信息,请告诉我。
最佳答案
没关系,我解决了这个问题!我应该一直使用 .takeUnretainedValue() 而不是 .takeRetainedValue(),因为 ARC 在我使用它之前为我释放了 CGImage 对象。
关于ios - MLKit文本检测异常-[Not A Type _cfTypeID] : message sent to deallocated instance 0x106623e20,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53111232/
我一直在尝试使用cocoapod将MLKit集成到CardIO中。我修复了cocoapod的所有警告,并且成功构建了CardIO。但是,当我将CardIO链接到我的应用程序并构建时,会出现此错误。我在互联网上搜索并尝试了人们建议的不同类型的方法,但仍然无济于事。在集成/链接过程中是否有任何我可能遗漏的步骤或设置?Undefinedsymbolsforarchitecturearmv7:"_OBJC_CLASS_$_FIRVisionImage",referencedfrom:objc-class-refinlibCardIO.a(CardIOView.o)"_OBJC_CLASS_$_
我正在使用代码为图像提供不同的效果,例如对比度、色调、饱和度等;并使用苹果glImageProcessing代码,我从我的View跳转到glimgeProcessing,并将生成的图像保存到appDelegateuiimage属性中文件。从EagleView返回后,我使用viewDidAppear函数将我的ImageView更改为更新的图像"-[NotAType_cfTypeID]:messagesenttodeallocatedinstance"我的代码是NSLog(@"appimafeis%@",app.image);[imageViewsetImage:app.image];我的
我正在尝试创建一个应用程序,使用MLKit的文本检测功能来检测设备相机拍摄的照片中的文本。下面是我的photoOutput方法中的代码,以及它调用的方法的代码:funcphotoOutput(_output:AVCapturePhotoOutput,didFinishProcessingPhotophoto:AVCapturePhoto,error:Error?){print("worked")PHPhotoLibrary.shared().performChanges({letcreationRequest=PHAssetCreationRequest.forAsset()creat
我已经按照文档集成了FirebaseMLKitSDK,使用backcamera照片可以正确检测到文本。当我使用前置摄像头拍摄的照片时,文本检测错误,结果不佳。@IBActionfuncfindTextDidTouch(_sender:UIButton){runTextRecognition(with:imageView.image!)}funcrunCloudTextRecognition(withimage:UIImage){letvisionImage=VisionImage(image:image)cloudTextDetector.detect(in:visionImage){
我正在尝试使用FirebaseMLKit对我的图像进行OCR,但失败并返回错误Textdetectionfailedwitherror:Failedtoruntextdetectorbecauseselfisnil.///Detectstextsonthespecifiedimageanddrawsaframeforthem.funcdetectTexts(){letimage=#imageLiteral(resourceName:"testocr")//Createatextdetector.lettextDetector=vision.textDetector()//Checkco
因此,我正在尝试使用MLKit扫描条码,但是self.barcodeDetector?.detect的完成block中的条码变量中没有条码。UIImage(命名为:“barcode.jpg”)存在并正确加载(并且有条形码)。那么我做错了什么/我错过了什么?privatevarbarcodeDetector:VisionBarcodeDetector?privatelazyvarvision=Vision.vision()overridefuncviewDidLoad(){super.viewDidLoad()guardletbarcodeImage=self.imageView.ima
前言小编前面几期文章分别给大家介绍了使用HMSMLKitSDK实现微笑抓拍、证件照DIY、拍照翻译的功能开发(链接见文章末尾),本次小编给大家带来的是使用HMS 机器学习服务(MLKit)银行卡识别SDK,一键实现银行卡识别与绑定功能。银行卡识别的应用场景介绍开发步骤前,我们先来谈谈银行卡识别的具体应用场景,银行APP、移动支付、缴费类APP、电商类APP或者其它带支付功能的APP在使用过程中往往会遇到如下常见的几个应用场景:绑卡支付常用于支付类APP,或者带支付功能的APP,用来绑定信用卡、银联借记卡,提供在线支付功能转账汇款常用于银行或者支付类APP,用来给本行或者他行用户进行转账。实名认
前言小编前面几期文章分别给大家介绍了使用HMSMLKitSDK实现微笑抓拍、证件照DIY、拍照翻译的功能开发(链接见文章末尾),本次小编给大家带来的是使用HMS 机器学习服务(MLKit)银行卡识别SDK,一键实现银行卡识别与绑定功能。银行卡识别的应用场景介绍开发步骤前,我们先来谈谈银行卡识别的具体应用场景,银行APP、移动支付、缴费类APP、电商类APP或者其它带支付功能的APP在使用过程中往往会遇到如下常见的几个应用场景:绑卡支付常用于支付类APP,或者带支付功能的APP,用来绑定信用卡、银联借记卡,提供在线支付功能转账汇款常用于银行或者支付类APP,用来给本行或者他行用户进行转账。实名认