url: https://travelnoire.com/best-carnival-celebrations-around-the-world/, pageTitle: Perayaan \u003cb\u003eKarnaval\u003c/b\u003e Terbaik di Seluruh Dunia - Travel Noire, fullMatchingImages: [{url: https://travelnoire.com/wp-content/uploads/2019/02/quinten-de-graaf-278848-unsplash.jpg}]
url: https://bespokebrazil.com/rio-carnival-2019/, pageTitle: Kunjungi \u003cb\u003eRio Carnival 2019\u003c/b\u003e dengan Pakar Brasil - Pesanan Khusus Brasil, PartialMatchingImages: [{ url: https://bespoke-brazil-2018-bespokebrazil.netdna-ssl.com/wp-content/uploads/2019/01/Carnival-1.jpg}]
Jika Anda belum membuat Google Cloud project, lakukan sekarang. Luaskan bagian ini untuk menampilkan petunjuk.
Login ke akun Google Cloud Anda. Jika Anda baru menggunakan
Google Cloud,
buat akun untuk mengevaluasi performa produk kami dalam
skenario dunia nyata. Pelanggan baru juga mendapatkan kredit gratis senilai $300 untuk
menjalankan, menguji, dan men-deploy workload.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Roles required to select or create a project
Select a project: Selecting a project doesn't require a specific
IAM role—you can select any project that you've been
granted a role on.
Create a project: To create a project, you need the Project Creator role
(roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
To enable APIs, you need the serviceusage.services.enable permission. If you
created the project, then you likely already have this permission through the
Owner role (roles/owner). Otherwise, you can get this permission through the
Service Usage Admin role (roles/serviceusage.serviceUsageAdmin).
Learn how to grant roles.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Roles required to select or create a project
Select a project: Selecting a project doesn't require a specific
IAM role—you can select any project that you've been
granted a role on.
Create a project: To create a project, you need the Project Creator role
(roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
To enable APIs, you need the serviceusage.services.enable permission. If you
created the project, then you likely already have this permission through the
Owner role (roles/owner). Otherwise, you can get this permission through the
Service Usage Admin role (roles/serviceusage.serviceUsageAdmin).
Learn how to grant roles.
RESULTS_INT: (Opsional) Nilai bilangan bulat dari hasil yang akan
ditampilkan. Jika Anda menghilangkan kolom "maxResults" dan nilainya, API akan menampilkan
nilai default 10 hasil. Kolom ini tidak berlaku untuk jenis fitur berikut:
TEXT_DETECTION, DOCUMENT_TEXT_DETECTION, atau CROP_HINTS.
PROJECT_ID: Project ID Google Cloud Anda.
Metode HTTP dan URL:
POST https://vision.googleapis.com/v1/images:annotate
// detectWeb gets image properties from the Vision API for an image at the given file path.funcdetectWeb(wio.Writer,filestring)error{ctx:=context.Background()client,err:=vision.NewImageAnnotatorClient(ctx)iferr!=nil{returnerr}f,err:=os.Open(file)iferr!=nil{returnerr}deferf.Close()image,err:=vision.NewImageFromReader(f)iferr!=nil{returnerr}web,err:=client.DetectWeb(ctx,image,nil)iferr!=nil{returnerr}fmt.Fprintln(w,"Web properties:")iflen(web.FullMatchingImages)!=0{fmt.Fprintln(w,"\tFull image matches:")for_,full:=rangeweb.FullMatchingImages{fmt.Fprintf(w,"\t\t%s\n",full.Url)}}iflen(web.PagesWithMatchingImages)!=0{fmt.Fprintln(w,"\tPages with this image:")for_,page:=rangeweb.PagesWithMatchingImages{fmt.Fprintf(w,"\t\t%s\n",page.Url)}}iflen(web.WebEntities)!=0{fmt.Fprintln(w,"\tEntities:")fmt.Fprintln(w,"\t\tEntity\t\tScore\tDescription")for_,entity:=rangeweb.WebEntities{fmt.Fprintf(w,"\t\t%-14s\t%-2.4f\t%s\n",entity.EntityId,entity.Score,entity.Description)}}iflen(web.BestGuessLabels)!=0{fmt.Fprintln(w,"\tBest guess labels:")for_,label:=rangeweb.BestGuessLabels{fmt.Fprintf(w,"\t\t%s\n",label.Label)}}returnnil}
importcom.google.cloud.vision.v1.AnnotateImageRequest;importcom.google.cloud.vision.v1.AnnotateImageResponse;importcom.google.cloud.vision.v1.BatchAnnotateImagesResponse;importcom.google.cloud.vision.v1.Feature;importcom.google.cloud.vision.v1.Feature.Type;importcom.google.cloud.vision.v1.Image;importcom.google.cloud.vision.v1.ImageAnnotatorClient;importcom.google.cloud.vision.v1.WebDetection;importcom.google.cloud.vision.v1.WebDetection.WebEntity;importcom.google.cloud.vision.v1.WebDetection.WebImage;importcom.google.cloud.vision.v1.WebDetection.WebLabel;importcom.google.cloud.vision.v1.WebDetection.WebPage;importcom.google.protobuf.ByteString;importjava.io.FileInputStream;importjava.io.IOException;importjava.util.ArrayList;importjava.util.List;publicclassDetectWebDetections{publicstaticvoiddetectWebDetections()throwsIOException{// TODO(developer): Replace these variables before running the sample.StringfilePath="path/to/your/image/file.jpg";detectWebDetections(filePath);}// Finds references to the specified image on the web.publicstaticvoiddetectWebDetections(StringfilePath)throwsIOException{List<AnnotateImageRequest>requests=newArrayList<>();ByteStringimgBytes=ByteString.readFrom(newFileInputStream(filePath));Imageimg=Image.newBuilder().setContent(imgBytes).build();Featurefeat=Feature.newBuilder().setType(Type.WEB_DETECTION).build();AnnotateImageRequestrequest=AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();requests.add(request);// Initialize client that will be used to send requests. This client only needs to be created// once, and can be reused for multiple requests. After completing all of your requests, call// the "close" method on the client to safely clean up any remaining background resources.try(ImageAnnotatorClientclient=ImageAnnotatorClient.create()){BatchAnnotateImagesResponseresponse=client.batchAnnotateImages(requests);List<AnnotateImageResponse>responses=response.getResponsesList();for(AnnotateImageResponseres:responses){if(res.hasError()){System.out.format("Error: %s%n",res.getError().getMessage());return;}// Search the web for usages of the image. You could use these signals later// for user input moderation or linking external references.// For a full list of available annotations, see http://g.co/cloud/vision/docsWebDetectionannotation=res.getWebDetection();System.out.println("Entity:Id:Score");System.out.println("===============");for(WebEntityentity:annotation.getWebEntitiesList()){System.out.println(entity.getDescription()+" : "+entity.getEntityId()+" : "+entity.getScore());}for(WebLabellabel:annotation.getBestGuessLabelsList()){System.out.format("%nBest guess label: %s",label.getLabel());}System.out.println("%nPages with matching images: Score%n==");for(WebPagepage:annotation.getPagesWithMatchingImagesList()){System.out.println(page.getUrl()+" : "+page.getScore());}System.out.println("%nPages with partially matching images: Score%n==");for(WebImageimage:annotation.getPartialMatchingImagesList()){System.out.println(image.getUrl()+" : "+image.getScore());}System.out.println("%nPages with fully matching images: Score%n==");for(WebImageimage:annotation.getFullMatchingImagesList()){System.out.println(image.getUrl()+" : "+image.getScore());}System.out.println("%nPages with visually similar images: Score%n==");for(WebImageimage:annotation.getVisuallySimilarImagesList()){System.out.println(image.getUrl()+" : "+image.getScore());}}}}}