use of com.woorea.openstack.glance.model.v2.Image in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ImageIT method setupBeforeEach.
@BeforeEach
public void setupBeforeEach() throws ClientException {
imageTests = new ImageTests();
imageTests.setup(adminClient, contextPath, label, Commons.RT_IMAGE_V1, rootPage, defaultPageTemplate, clientlibs, new Image());
}
use of com.woorea.openstack.glance.model.v2.Image in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class ImageIT method setupBeforeEach.
@BeforeEach
public void setupBeforeEach() throws ClientException {
imageTests = new ImageTests();
imageTests.setup(adminClient, contextPath, label, Commons.RT_IMAGE_V2, rootPage, defaultPageTemplate, clientlibs, new Image());
}
use of com.woorea.openstack.glance.model.v2.Image in project google-cloud-java by GoogleCloudPlatform.
the class AnnotateImage method main.
public static void main(String... args) throws Exception {
// Instantiates a client
ImageAnnotatorClient vision = ImageAnnotatorClient.create();
// The path to the image file to annotate
// for example "./resources/wakeupcat.jpg";
String fileName = "your/image/path.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()) {
for (Map.Entry<FieldDescriptor, Object> entry : annotation.getAllFields().entrySet()) {
System.out.printf("%s : %s\n", entry.getKey(), entry.getValue());
}
}
}
}
use of com.woorea.openstack.glance.model.v2.Image in project Douya by DreaminginCodeZH.
the class BroadcastLayout method bindBroadcast.
public void bindBroadcast(final Broadcast broadcast) {
final Context context = getContext();
if (broadcast.isInterest) {
mAvatarImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.recommendation_avatar_icon_grey600_40dp));
mAvatarImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
UriHandler.open(DoubanUtils.getInterestTypeUrl(broadcast.interestType), context);
}
});
} else {
ImageUtils.loadAvatar(mAvatarImage, broadcast.author.avatar);
mAvatarImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
context.startActivity(ProfileActivity.makeIntent(broadcast.author, context));
}
});
}
mNameText.setText(broadcast.getAuthorName());
mTimeActionText.setDoubanTimeAndAction(broadcast.createdAt, broadcast.action);
boolean isRebind = mBoundBroadcastId != null && mBoundBroadcastId == broadcast.id;
// HACK: Attachment and text should not change on rebind.
if (!isRebind) {
Attachment attachment = broadcast.attachment;
if (attachment != null) {
mAttachmentLayout.setVisibility(VISIBLE);
mAttachmentTitleText.setText(attachment.title);
mAttachmentDescriptionText.setText(attachment.description);
if (!TextUtils.isEmpty(attachment.image)) {
mAttachmentImage.setVisibility(VISIBLE);
ImageUtils.loadImage(mAttachmentImage, attachment.image);
} else {
mAttachmentImage.setVisibility(GONE);
}
final String attachmentUrl = attachment.href;
if (!TextUtils.isEmpty(attachmentUrl)) {
mAttachmentLayout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
UriHandler.open(attachmentUrl, context);
}
});
} else {
mAttachmentLayout.setOnClickListener(null);
}
} else {
mAttachmentLayout.setVisibility(GONE);
}
final ArrayList<Image> images = broadcast.images.size() > 0 ? broadcast.images : Photo.toImageList(broadcast.photos);
int numImages = images.size();
if (numImages == 1) {
final Image image = images.get(0);
mSingleImageLayout.setVisibility(VISIBLE);
mSingleImageLayout.loadImage(image);
mSingleImageLayout.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
context.startActivity(GalleryActivity.makeIntent(image, context));
}
});
} else {
mSingleImageLayout.setVisibility(GONE);
}
if (numImages > 1) {
mImageListLayout.setVisibility(VISIBLE);
mImageListDescriptionText.setText(context.getString(R.string.broadcast_image_list_count_format, numImages));
mImageListAdapter.replace(images);
mImageListAdapter.setOnImageClickListener(new HorizontalImageAdapter.OnImageClickListener() {
@Override
public void onImageClick(int position) {
context.startActivity(GalleryActivity.makeImageListIntent(images, position, context));
}
});
} else {
mImageListLayout.setVisibility(GONE);
}
boolean textSpaceVisible = (attachment != null || numImages > 0) && !TextUtils.isEmpty(broadcast.text);
ViewUtils.setVisibleOrGone(mTextSpace, textSpaceVisible);
mTextText.setText(broadcast.getTextWithEntities(context));
}
mLikeButton.setText(broadcast.getLikeCountString());
LikeBroadcastManager likeBroadcastManager = LikeBroadcastManager.getInstance();
if (likeBroadcastManager.isWriting(broadcast.id)) {
mLikeButton.setActivated(likeBroadcastManager.isWritingLike(broadcast.id));
mLikeButton.setEnabled(false);
} else {
mLikeButton.setActivated(broadcast.isLiked);
mLikeButton.setEnabled(true);
}
mLikeButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (mListener != null) {
mListener.onLikeClicked();
}
}
});
RebroadcastBroadcastManager rebroadcastBroadcastManager = RebroadcastBroadcastManager.getInstance();
if (rebroadcastBroadcastManager.isWriting(broadcast.id)) {
mRebroadcastButton.setActivated(rebroadcastBroadcastManager.isWritingRebroadcast(broadcast.id));
mRebroadcastButton.setEnabled(false);
} else {
mRebroadcastButton.setActivated(broadcast.isRebroadcasted());
mRebroadcastButton.setEnabled(true);
}
mRebroadcastButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (mListener != null) {
mListener.onRebroadcastClicked();
}
}
});
mCommentButton.setText(broadcast.getCommentCountString());
mCommentButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if (mListener != null) {
mListener.onCommentClicked();
}
}
});
mBoundBroadcastId = broadcast.id;
}
use of com.woorea.openstack.glance.model.v2.Image in project spring-cloud-gcp by spring-cloud.
the class VisionController method uploadImage.
/**
* This method downloads an image from a URL and sends its contents to the Vision API for label detection.
*
* @param imageUrl the URL of the image
* @return a string with the list of labels and percentage of certainty
* @throws Exception if the Vision API call produces an error
*/
@GetMapping("/vision")
public String uploadImage(String imageUrl) throws Exception {
// Copies the content of the image to memory.
byte[] imageBytes = StreamUtils.copyToByteArray(this.resourceLoader.getResource(imageUrl).getInputStream());
BatchAnnotateImagesResponse responses;
Image image = Image.newBuilder().setContent(ByteString.copyFrom(imageBytes)).build();
// Sets the type of request to label detection, to detect broad sets of categories in an image.
Feature feature = Feature.newBuilder().setType(Feature.Type.LABEL_DETECTION).build();
AnnotateImageRequest request = AnnotateImageRequest.newBuilder().setImage(image).addFeatures(feature).build();
responses = this.imageAnnotatorClient.batchAnnotateImages(Collections.singletonList(request));
StringBuilder responseBuilder = new StringBuilder("<table border=\"1\">");
responseBuilder.append("<tr><th>description</th><th>score</th></tr>");
// We're only expecting one response.
if (responses.getResponsesCount() == 1) {
AnnotateImageResponse response = responses.getResponses(0);
if (response.hasError()) {
throw new Exception(response.getError().getMessage());
}
for (EntityAnnotation annotation : response.getLabelAnnotationsList()) {
responseBuilder.append("<tr><td>").append(annotation.getDescription()).append("</td><td>").append(annotation.getScore()).append("</td></tr>");
}
}
responseBuilder.append("</table>");
responseBuilder.append("<p><img src='" + imageUrl + "'/></p>");
return responseBuilder.toString();
}
Aggregations