本文整理汇总了Java中com.google.api.services.vision.v1.model.EntityAnnotation类的典型用法代码示例。如果您正苦于以下问题:Java EntityAnnotation类的具体用法?Java EntityAnnotation怎么用?Java EntityAnnotation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EntityAnnotation类属于com.google.api.services.vision.v1.model包,在下文中一共展示了EntityAnnotation类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: convertResponseToStringLabel
import com.google.api.services.vision.v1.model.EntityAnnotation; //导入依赖的package包/类
private String convertResponseToStringLabel(BatchAnnotateImagesResponse response) {
String message = "I found these things!!!!!!!!:\n\n";
java.util.List<EntityAnnotation> annotations = response.getResponses().get(0).getLabelAnnotations();
if (annotations != null) {
System.out.println("Entity:Score");
System.out.println("===============");
for (EntityAnnotation entity : annotations) {
message += String.format(Locale.KOREAN, "%.3f: %s", entity.getScore(), entity.getDescription());
message += "\n";
System.out.println(entity.getDescription() + " : " + entity.getScore());
}
} else {
message += "nothing";
}
return message;
}
开发者ID:jmpaaak,项目名称:EyeShopping,代码行数:19,代码来源:MainActivity.java
示例2: handleResponse
import com.google.api.services.vision.v1.model.EntityAnnotation; //导入依赖的package包/类
private GoogleVisionApiResponse handleResponse(BatchAnnotateImagesResponse batchResponse) {
GoogleVisionApiResponse result = new GoogleVisionApiResponse();
for (int i = 0; i < requestFiles.size(); i++) {
GoogleVisionApiRequestFile file = requestFiles.get(i);
AnnotateImageResponse annotateImageResponse = batchResponse.getResponses().get(i);
List<EntityAnnotation> entityAnnotations =
MoreObjects.firstNonNull(
annotateImageResponse.getTextAnnotations(),
ImmutableList.<EntityAnnotation>of());
entityAnnotations.stream()
.findFirst()
.ifPresent(a -> {
result.addDescription(file.getFileId(), a.getDescription());
});
}
return result;
}
开发者ID:otsecbsol,项目名称:linkbinder,代码行数:19,代码来源:GoogleVisionApiClient.java
示例3: main
import com.google.api.services.vision.v1.model.EntityAnnotation; //导入依赖的package包/类
/**
* Annotates an image using the Vision API.
*/
public static void main(String[] args) throws IOException, GeneralSecurityException {
if (args.length != 1) {
System.err.println("Usage:");
System.err.printf("\tjava %s gs://<bucket_name>/<object_name>\n",
DetectLandmark.class.getCanonicalName());
System.exit(1);
} else if (!args[0].toLowerCase().startsWith("gs://")) {
System.err.println("Google Cloud Storage url must start with 'gs://'.");
System.exit(1);
}
DetectLandmark app = new DetectLandmark(getVisionService());
List<EntityAnnotation> landmarks = app.identifyLandmark(args[0], MAX_RESULTS);
System.out.printf("Found %d landmark%s\n", landmarks.size(), landmarks.size() == 1 ? "" : "s");
for (EntityAnnotation annotation : landmarks) {
System.out.printf("\t%s\n", annotation.getDescription());
}
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:22,代码来源:DetectLandmark.java
示例4: printLabels_manyLabels_printsLabels
import com.google.api.services.vision.v1.model.EntityAnnotation; //导入依赖的package包/类
@Test public void printLabels_manyLabels_printsLabels() throws Exception {
// Arrange
ByteArrayOutputStream bout = new ByteArrayOutputStream();
PrintStream out = new PrintStream(bout);
ImmutableList<EntityAnnotation> labels =
ImmutableList.of(
new EntityAnnotation().setDescription("dog").setScore(0.7564f),
new EntityAnnotation().setDescription("husky").setScore(0.67891f),
new EntityAnnotation().setDescription("poodle").setScore(0.1233f));
// Act
LabelApp.printLabels(out, Paths.get("path/to/some/image.jpg"), labels);
// Assert
String got = bout.toString();
assertThat(got).contains("dog (score: 0.756)");
assertThat(got).contains("husky (score: 0.679)");
assertThat(got).contains("poodle (score: 0.123)");
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:20,代码来源:LabelAppTest.java
示例5: labelImage
import com.google.api.services.vision.v1.model.EntityAnnotation; //导入依赖的package包/类
/**
* Gets up to {@code maxResults} labels for an image stored at {@code path}.
* @param path p
* @param maxResults m
* @return list of entity annotations
* @throws IOException e
*/
public List<EntityAnnotation> labelImage(Path path, int maxResults) throws IOException {
// [START construct_request]
byte[] data = Files.readAllBytes(path);
AnnotateImageRequest request = new AnnotateImageRequest().setImage(new Image().encodeContent(data))
.setFeatures(ImmutableList.of(new Feature().setType("LABEL_DETECTION").setMaxResults(maxResults)));
Vision.Images.Annotate annotate = vision.images().annotate(new BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request)));
// Due to a bug: requests to Vision API containing large images fail
// when GZipped.
// annotate.setDisableGZipContent(true);
// [END construct_request]
// [START parse_response]
BatchAnnotateImagesResponse batchResponse = annotate.execute();
assert batchResponse.getResponses().size() == 1;
AnnotateImageResponse response = batchResponse.getResponses().get(0);
if (response.getLabelAnnotations() == null) {
throw new IOException(response.getError() != null ? response.getError().getMessage() : "Unknown error getting image annotations");
}
return response.getLabelAnnotations();
// [END parse_response]
}
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:30,代码来源:GoogleCloud.java
示例6: convertResponseToMap
import com.google.api.services.vision.v1.model.EntityAnnotation; //导入依赖的package包/类
/**
* Process an encoded image and return a collection of vision
* annotations describing features of the image data.
*
* @return collection of annotation descriptions and scores.
*/
private static Map<String, Float> convertResponseToMap(BatchAnnotateImagesResponse response) {
// Convert response into a readable collection of annotations
Map<String, Float> annotations = new HashMap<>();
List<EntityAnnotation> labels = response.getResponses().get(0).getLabelAnnotations();
if (labels != null) {
for (EntityAnnotation label : labels) {
annotations.put(label.getDescription(), label.getScore());
}
}
Log.d(TAG, "Cloud Vision request completed:" + annotations);
return annotations;
}
开发者ID:androidthings,项目名称:doorbell,代码行数:21,代码来源:CloudVisionUtils.java
示例7: convertResponseToList
import com.google.api.services.vision.v1.model.EntityAnnotation; //导入依赖的package包/类
private List<String> convertResponseToList(BatchAnnotateImagesResponse response) {
List<String> res = new ArrayList<>();
List<EntityAnnotation> labels = response.getResponses().get(0).getLabelAnnotations();
if (labels != null) {
for (EntityAnnotation label : labels) {
res.add(label.getDescription());
}
}
return res;
}
开发者ID:lisiyuan656,项目名称:dieta,代码行数:11,代码来源:NewFoodFragment.java
示例8: identifyLandmark
import com.google.api.services.vision.v1.model.EntityAnnotation; //导入依赖的package包/类
/**
* Gets up to {@code maxResults} landmarks for an image stored at {@code uri}.
*/
public List<EntityAnnotation> identifyLandmark(String uri, int maxResults) throws IOException {
AnnotateImageRequest request =
new AnnotateImageRequest()
.setImage(new Image().setSource(
new ImageSource().setGcsImageUri(uri)))
.setFeatures(ImmutableList.of(
new Feature()
.setType("LANDMARK_DETECTION")
.setMaxResults(maxResults)));
Vision.Images.Annotate annotate =
vision.images()
.annotate(new BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request)));
// Due to a bug: requests to Vision API containing large images fail when GZipped.
annotate.setDisableGZipContent(true);
BatchAnnotateImagesResponse batchResponse = annotate.execute();
assert batchResponse.getResponses().size() == 1;
AnnotateImageResponse response = batchResponse.getResponses().get(0);
if (response.getLandmarkAnnotations() == null) {
throw new IOException(
response.getError() != null
? response.getError().getMessage()
: "Unknown error getting image annotations");
}
return response.getLandmarkAnnotations();
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:30,代码来源:DetectLandmark.java
示例9: identifyLandmark_withLandmark_returnsKnownLandmark
import com.google.api.services.vision.v1.model.EntityAnnotation; //导入依赖的package包/类
@Test public void identifyLandmark_withLandmark_returnsKnownLandmark() throws Exception {
List<EntityAnnotation> landmarks = appUnderTest.identifyLandmark(LANDMARK_URI, MAX_RESULTS);
assertThat(landmarks).named("water.jpg landmarks").isNotEmpty();
assertThat(landmarks.get(0).getDescription())
.named("water.jpg landmark #0 description")
.isEqualTo("Taitung, Famous Places \"up the water flow\" marker");
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:9,代码来源:DetectLandmarkIT.java
示例10: extractDescriptions
import com.google.api.services.vision.v1.model.EntityAnnotation; //导入依赖的package包/类
/**
* Extracts as a combinded string, all the descriptions from text annotations on an {@code image}.
*/
public Word extractDescriptions(ImageText image) {
String document = "";
for (EntityAnnotation text : image.textAnnotations()) {
document += text.getDescription();
}
if (document.equals("")) {
System.out.printf("%s had no discernible text.\n", image.path());
}
// Output a progress indicator.
System.out.print('.');
System.out.flush();
return Word.builder().path(image.path()).word(document).build();
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:17,代码来源:TextApp.java
示例11: printLabels
import com.google.api.services.vision.v1.model.EntityAnnotation; //导入依赖的package包/类
/**
* Prints the labels received from the Vision API.
*/
public static void printLabels(PrintStream out, Path imagePath, List<EntityAnnotation> labels) {
out.printf("Labels for image %s:\n", imagePath);
for (EntityAnnotation label : labels) {
out.printf(
"\t%s (score: %.3f)\n",
label.getDescription(),
label.getScore());
}
if (labels.isEmpty()) {
out.println("\tNo labels found.");
}
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:16,代码来源:LabelApp.java
示例12: labelImage
import com.google.api.services.vision.v1.model.EntityAnnotation; //导入依赖的package包/类
/**
* Gets up to {@code maxResults} labels for an image stored at {@code path}.
*/
public List<EntityAnnotation> labelImage(Path path, int maxResults) throws IOException {
// [START construct_request]
byte[] data = Files.readAllBytes(path);
AnnotateImageRequest request =
new AnnotateImageRequest()
.setImage(new Image().encodeContent(data))
.setFeatures(ImmutableList.of(
new Feature()
.setType("LABEL_DETECTION")
.setMaxResults(maxResults)));
Vision.Images.Annotate annotate =
vision.images()
.annotate(new BatchAnnotateImagesRequest().setRequests(ImmutableList.of(request)));
// Due to a bug: requests to Vision API containing large images fail when GZipped.
annotate.setDisableGZipContent(true);
// [END construct_request]
// [START parse_response]
BatchAnnotateImagesResponse batchResponse = annotate.execute();
assert batchResponse.getResponses().size() == 1;
AnnotateImageResponse response = batchResponse.getResponses().get(0);
if (response.getLabelAnnotations() == null) {
throw new IOException(
response.getError() != null
? response.getError().getMessage()
: "Unknown error getting image annotations");
}
return response.getLabelAnnotations();
// [END parse_response]
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:35,代码来源:LabelApp.java
示例13: labelImage_cat_returnsCatDescription
import com.google.api.services.vision.v1.model.EntityAnnotation; //导入依赖的package包/类
@Test public void labelImage_cat_returnsCatDescription() throws Exception {
List<EntityAnnotation> labels =
appUnderTest.labelImage(Paths.get("data/cat.jpg"), MAX_LABELS);
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
for (EntityAnnotation label : labels) {
builder.add(label.getDescription());
}
ImmutableSet<String> descriptions = builder.build();
assertThat(descriptions).named("cat.jpg labels").contains("cat");
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:13,代码来源:LabelAppIT.java
示例14: printLabels_emptyList_printsNoLabelsFound
import com.google.api.services.vision.v1.model.EntityAnnotation; //导入依赖的package包/类
@Test public void printLabels_emptyList_printsNoLabelsFound() throws Exception {
// Arrange
ByteArrayOutputStream bout = new ByteArrayOutputStream();
PrintStream out = new PrintStream(bout);
// Act
LabelApp.printLabels(
out, Paths.get("path/to/some/image.jpg"), ImmutableList.<EntityAnnotation>of());
// Assert
assertThat(bout.toString()).contains("No labels found.");
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:13,代码来源:LabelAppTest.java
示例15: printLabels
import com.google.api.services.vision.v1.model.EntityAnnotation; //导入依赖的package包/类
/**
* Prints the labels received from the Vision API.
* @param out o
* @param imagePath i
* @param labels l
*/
public void printLabels(PrintStream out, Path imagePath, List<EntityAnnotation> labels) {
out.printf("Labels for image %s:\n", imagePath);
for (EntityAnnotation label : labels) {
out.printf("\t%s (score: %.3f)\n", label.getDescription(), label.getScore());
}
if (labels.isEmpty()) {
out.println("\tNo labels found.");
}
}
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:16,代码来源:GoogleCloud.java
示例16: testTextDetection
import com.google.api.services.vision.v1.model.EntityAnnotation; //导入依赖的package包/类
@Test
public void testTextDetection() throws Exception {
// 認証情報
GoogleCredential credential = GoogleCredential.fromStream(
Files.newInputStream(Paths.get("/tmp/google-cloud-api-service-account.json")))
.createScoped(VisionScopes.all());
// GoogleCredential credential = GoogleCredential.getApplicationDefault().createScoped(VisionScopes.all());
// Google Cloud Vision APIクライアント
Vision vision = new Vision.Builder(GoogleNetHttpTransport.newTrustedTransport(), JacksonFactory.getDefaultInstance(), credential)
.setApplicationName("GoogleVisionApiClient/1.0")
.build();
// 解析対象画像ファイルごとに処理を行う
ImmutableList<String> imageFiles = ImmutableList.<String>of(
"/tmp/sample1.jpg",
"/tmp/sample2.jpg",
"/tmp/sample3.jpg",
"/tmp/sample4.jpg"
);
ImmutableList.Builder<AnnotateImageRequest> requests = ImmutableList.builder();
imageFiles.forEach(f -> {
byte[] data = new byte[0];
try {
data = Files.readAllBytes(Paths.get(f));
requests.add(
new AnnotateImageRequest()
.setImage(new Image().encodeContent(data))
.setFeatures(ImmutableList.of(
new Feature()
.setType("TEXT_DETECTION")
.setMaxResults(1)
))
);
} catch (IOException e) {
e.printStackTrace();
}
});
// 実行
Vision.Images.Annotate annotate =
vision.images().annotate(new BatchAnnotateImagesRequest().setRequests(requests.build()));
annotate.setDisableGZipContent(true);
BatchAnnotateImagesResponse batchResponse = annotate.execute();
batchResponse.getResponses().forEach(response -> {
List<EntityAnnotation> entityAnnotations =
MoreObjects.firstNonNull(response.getTextAnnotations(), ImmutableList.<EntityAnnotation>of());
entityAnnotations.stream()
.findFirst()
.ifPresent(a -> {
System.out.println(a.getDescription());
System.out.println("----------------------------------------------------");
});
});
}
开发者ID:otsecbsol,项目名称:linkbinder,代码行数:58,代码来源:GoogleVisionApiClientTest.java
示例17: convertResponseToString
import com.google.api.services.vision.v1.model.EntityAnnotation; //导入依赖的package包/类
private String convertResponseToString(BatchAnnotateImagesResponse response) {
StringBuilder message = new StringBuilder("Results:\n\n");
message.append("Labels:\n");
List<EntityAnnotation> labels = response.getResponses().get(0).getLabelAnnotations();
if (labels != null) {
for (EntityAnnotation label : labels) {
message.append(String.format(Locale.getDefault(), "%.3f: %s",
label.getScore(), label.getDescription()));
message.append("\n");
}
} else {
message.append("nothing\n");
}
message.append("Texts:\n");
List<EntityAnnotation> texts = response.getResponses().get(0)
.getTextAnnotations();
if (texts != null) {
for (EntityAnnotation text : texts) {
message.append(String.format(Locale.getDefault(), "%s: %s",
text.getLocale(), text.getDescription()));
message.append("\n");
}
} else {
message.append("nothing\n");
}
message.append("Landmarks:\n");
List<EntityAnnotation> landmarks = response.getResponses().get(0)
.getLandmarkAnnotations();
if (landmarks != null) {
for (EntityAnnotation landmark : landmarks) {
message.append(String.format(Locale.getDefault(), "%.3f: %s",
landmark.getScore(), landmark.getDescription()));
message.append("\n");
}
} else {
message.append("nothing\n");
}
return message.toString();
}
开发者ID:Truiton,项目名称:CloudVisionAPI,代码行数:43,代码来源:MainActivity.java
示例18: textAnnotations
import com.google.api.services.vision.v1.model.EntityAnnotation; //导入依赖的package包/类
public List<EntityAnnotation> textAnnotations() {
return this.ts;
}
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:4,代码来源:ImageText.java
注:本文中的com.google.api.services.vision.v1.model.EntityAnnotation类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论