【发布时间】:2018-03-10 10:23:13
【问题描述】:
我正在使用 Google 云视觉 OCR 来检测文本。显示的文本始终是 1. 检测到的文本,2. 每个检测到的单词。我只想显示检测到的文本。
我正在使用来自Google Cloud Platform Github 的代码,我在callCloudVision 方法中将类型设置为文本检测labelDetection.setType("TEXT_DETECTION");。
我还将convertResponseToString方法修改为:
private String convertResponseToString(BatchAnnotateImagesResponse response) {
String message = "";
List<EntityAnnotation> labels = response.getResponses().get(0).getTextAnnotations();
for (EntityAnnotation label : labels) {
if (labels != null) {
System.out.println(label.getDescription());
message += String.format(Locale.US, "%s", label.getDescription()) + "\n";
}
else
{
message += "nothing";
}
}
return message;
}
这是我的毕业典礼:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
defaultConfig {
applicationId "com.example.mhci"
minSdkVersion 24
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
javaCompileOptions {
annotationProcessorOptions {
includeCompileClasspath false
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/io.netty.versions.properties'
exclude 'META-INF/INDEX.LIST'
exclude 'META-INF/DEPENDENCIES'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:design:25.4.0'
compile 'com.google.api-client:google-api-client-android:1.20.0' exclude module: 'httpclient'
compile 'com.google.http-client:google-http-client-gson:1.20.0' exclude module: 'httpclient'
compile 'com.google.apis:google-api-services-vision:v1-rev2-1.21.0'
compile 'com.android.support:design:25.4.0'
compile ('com.google.apis:google-api-services-translate:v2-rev47-1.22.0') {
exclude group: 'com.google.guava'
}
compile ('com.google.cloud:google-cloud-translate:0.5.0') {
exclude group: 'io.grpc', module: 'grpc-all'
exclude group: 'com.google.protobuf', module: 'protobuf-java'
exclude group: 'com.google.api-client', module: 'google-api-client-appengine'
}
}
检测到的this image显示的文字是:
Hello world
Hello
world
但我希望它只显示Hello world
我该怎么做?
【问题讨论】:
-
你尝试过TextAnnotation
-
@krishankTripathi 你的意思是不要使用 EntityAnnotation,而是用 TextAnnotation 替换它?
-
是的,使用 TextAnnotation 并通过此链接 developers.google.com/resources/api-libraries/documentation/…
-
当您从该方法获取页面时,您可以检测单词块或使用块方法检测下面给出的 Page 方法中的作品块developers.google.com/resources/api-libraries/documentation/…
-
我使用的代码中没有 TextAnnotation。它没有外部库
标签: java android ocr google-cloud-vision