
我目前正在编写应该能够查看文本图片的代码,然后从基于Android的设备的图片中提取文本.我在网上进行了一些研究,发现Google提供了自己的API,名为“Mobile Vision”(包含许多项目的包,即文本识别,面部识别等).然而,在他们的演示中,他们只展示实时文本识别.我想知道是否有人可以使用Mobile Vision API给我一个静止图像上的文本识别示例.欢迎任何帮助.谢谢.
解决方法:
Google Play服务移动视觉api文档介绍了如何执行此 *** 作,您可以使用TextRecognizer类检测Frames中的文本.一旦获得了位图图像,就可以将其转换为框架并对其进行处理.请参阅下面的示例.
// imageBitmap is the Bitmap image you're trying to process for textif(imageBitmap != null) { TextRecognizer textRecognizer = new TextRecognizer.Builder(this).build(); if(!textRecognizer.isOperational()) { // Note: The first time that an app using a Vision API is installed on a // device, GMS will download a native librarIEs to the device in order to do detection. // Usually this completes before the app is run for the first time. But if that // download has not yet completed, then the above call will not detect any text, // barcodes, or faces. // isOperational() can be used to check if the required native librarIEs are currently // available. The detectors will automatically become operational once the library // downloads complete on device. Log.w(LOG_TAG, "Detector dependencIEs are not yet available."); // Check for low storage. If there is low storage, the native library will not be // downloaded, so detection will not become operational. IntentFilter lowstorageFilter = new IntentFilter(Intent.ACTION_DEVICE_STORAGE_LOW); boolean hasLowStorage = registerReceiver(null, lowstorageFilter) != null; if (hasLowStorage) { Toast.makeText(this,"Low Storage", Toast.LENGTH_LONG).show(); Log.w(LOG_TAG, "Low Storage"); } } Frame imageFrame = new Frame.Builder() .setBitmap(imageBitmap) .build(); SparseArray<TextBlock> textBlocks = textRecognizer.detect(imageFrame); for (int i = 0; i < textBlocks.size(); i++) { TextBlock textBlock = textBlocks.get(textBlocks.keyAt(i)); Log.i(LOG_TAG, textBlock.getValue()); // Do something with value }}您还需要确保在模块的build.gradle中包含移动视觉依赖项
dependencIEs { compile 'com.Google.androID.gms:play-services-vision:9.4.0'} 并且还在应用程序的AndroID Manifest中包含以下内容
<Meta-data androID:name="com.Google.androID.gms.vision.DEPENDENCIES" androID:value="ocr" /> 总结 以上是内存溢出为你收集整理的android – 谷歌手机Vision Text API示例全部内容,希望文章能够帮你解决android – 谷歌手机Vision Text API示例所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)