use of com.ibm.dtfj.image.j9.Image in project java-docs-samples by GoogleCloudPlatform.
the class Detect method detectLandmarksGcs.
/**
* Detects landmarks in the specified remote image on Google Cloud Storage.
*
* @param gcsPath The path to the remote file on Google Cloud Storage to perform landmark
* detection on.
* @param out A {@link PrintStream} to write detected landmarks to.
* @throws Exception on errors while closing the client.
* @throws IOException on Input/Output errors.
*/
public static void detectLandmarksGcs(String gcsPath, PrintStream out) throws Exception, IOException {
List<AnnotateImageRequest> requests = new ArrayList<>();
ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
Image img = Image.newBuilder().setSource(imgSource).build();
Feature feat = Feature.newBuilder().setType(Type.LANDMARK_DETECTION).build();
AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
requests.add(request);
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
List<AnnotateImageResponse> responses = response.getResponsesList();
for (AnnotateImageResponse res : responses) {
if (res.hasError()) {
out.printf("Error: %s\n", res.getError().getMessage());
return;
}
// For full list of available annotations, see http://g.co/cloud/vision/docs
for (EntityAnnotation annotation : res.getLandmarkAnnotationsList()) {
LocationInfo info = annotation.getLocationsList().listIterator().next();
out.printf("Landmark: %s\n %s\n", annotation.getDescription(), info.getLatLng());
}
}
}
}
use of com.ibm.dtfj.image.j9.Image in project java-docs-samples by GoogleCloudPlatform.
the class Detect method detectPropertiesGcs.
/**
* Detects image properties such as color frequency from the specified remote image on Google
* Cloud Storage.
*
* @param gcsPath The path to the remote file on Google Cloud Storage to detect properties on.
* @param out A {@link PrintStream} to write
* @throws Exception on errors while closing the client.
* @throws IOException on Input/Output errors.
*/
public static void detectPropertiesGcs(String gcsPath, PrintStream out) throws Exception, IOException {
List<AnnotateImageRequest> requests = new ArrayList<>();
ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
Image img = Image.newBuilder().setSource(imgSource).build();
Feature feat = Feature.newBuilder().setType(Type.IMAGE_PROPERTIES).build();
AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
requests.add(request);
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
List<AnnotateImageResponse> responses = response.getResponsesList();
for (AnnotateImageResponse res : responses) {
if (res.hasError()) {
out.printf("Error: %s\n", res.getError().getMessage());
return;
}
// For full list of available annotations, see http://g.co/cloud/vision/docs
DominantColorsAnnotation colors = res.getImagePropertiesAnnotation().getDominantColors();
for (ColorInfo color : colors.getColorsList()) {
out.printf("fraction: %f\nr: %f, g: %f, b: %f\n", color.getPixelFraction(), color.getColor().getRed(), color.getColor().getGreen(), color.getColor().getBlue());
}
}
}
}
use of com.ibm.dtfj.image.j9.Image in project java-docs-samples by GoogleCloudPlatform.
the class Detect method detectLogosGcs.
/**
* Detects logos in the specified remote image on Google Cloud Storage.
*
* @param gcsPath The path to the remote file on Google Cloud Storage to perform logo detection
* on.
* @param out A {@link PrintStream} to write detected logos to.
* @throws Exception on errors while closing the client.
* @throws IOException on Input/Output errors.
*/
public static void detectLogosGcs(String gcsPath, PrintStream out) throws Exception, IOException {
List<AnnotateImageRequest> requests = new ArrayList<>();
ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();
Image img = Image.newBuilder().setSource(imgSource).build();
Feature feat = Feature.newBuilder().setType(Type.LOGO_DETECTION).build();
AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
requests.add(request);
try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
List<AnnotateImageResponse> responses = response.getResponsesList();
for (AnnotateImageResponse res : responses) {
if (res.hasError()) {
out.printf("Error: %s\n", res.getError().getMessage());
return;
}
// For full list of available annotations, see http://g.co/cloud/vision/docs
for (EntityAnnotation annotation : res.getLogoAnnotationsList()) {
out.println(annotation.getDescription());
}
}
}
}
use of com.ibm.dtfj.image.j9.Image in project java-docs-samples by GoogleCloudPlatform.
the class QuickstartSample method main.
public static void main(String... args) throws Exception {
// Instantiates a client
try (ImageAnnotatorClient vision = ImageAnnotatorClient.create()) {
// The path to the image file to annotate
String fileName = "./resources/wakeupcat.jpg";
// Reads the image file into memory
Path path = Paths.get(fileName);
byte[] data = Files.readAllBytes(path);
ByteString imgBytes = ByteString.copyFrom(data);
// Builds the image annotation request
List<AnnotateImageRequest> requests = new ArrayList<>();
Image img = Image.newBuilder().setContent(imgBytes).build();
Feature feat = Feature.newBuilder().setType(Type.LABEL_DETECTION).build();
AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
requests.add(request);
// Performs label detection on the image file
BatchAnnotateImagesResponse response = vision.batchAnnotateImages(requests);
List<AnnotateImageResponse> responses = response.getResponsesList();
for (AnnotateImageResponse res : responses) {
if (res.hasError()) {
System.out.printf("Error: %s\n", res.getError().getMessage());
return;
}
for (EntityAnnotation annotation : res.getLabelAnnotationsList()) {
annotation.getAllFields().forEach((k, v) -> System.out.printf("%s : %s\n", k, v.toString()));
}
}
}
}
use of com.ibm.dtfj.image.j9.Image in project openj9 by eclipse.
the class XMLIndexReader method _createCoreImageAfterParseError.
/**
* This is like the setJ9DumpData method but is to be used when we fail to parse the file. It is meant to try to construct the
* Image object with what it was able to get
*
* @param e The cause of the error
*/
private void _createCoreImageAfterParseError(Exception e) {
Builder builder = null;
if (_stream == null) {
// extract directly from the file
builder = new Builder(_coreFile, _reader, 0, _fileResolvingAgent);
} else {
// extract using the data stream
builder = new Builder(_coreFile, _stream, 0, _fileResolvingAgent);
}
_coreFile.extract(builder);
String osType = builder.getOSType();
String cpuType = builder.getCPUType();
String cpuSubType = builder.getCPUSubType();
long creationTime = builder.getCreationTime();
_coreImage = new Image(osType, null, cpuType, cpuSubType, 0, 0, creationTime);
Iterator spaces = builder.getAddressSpaces();
while (spaces.hasNext()) {
ImageAddressSpace addressSpace = (ImageAddressSpace) spaces.next();
// Set all processes as having invalid runtimes
for (Iterator processes = addressSpace.getProcesses(); processes.hasNext(); ) {
ImageProcess process = (ImageProcess) processes.next();
process.runtimeExtractionFailed(e);
}
_coreImage.addAddressSpace(addressSpace);
}
}
Aggregations