url: https://travelnoire.com/best-carnival-celebrations-around-the-world/, pageTitle: Best \u003cb\u003eCarnival\u003c/b\u003e Celebrations Around The World - 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: Visit \u003cb\u003eRio Carnival 2019\u003c/b\u003e with the Brazil Specialists - Bespoke Brazil, partialMatchingImages: [{ url: https://bespoke-brazil-2018-bespokebrazil.netdna-ssl.com/wp-content/uploads/2019/01/Carnival-1.jpg}]
Configura tu proyecto de Google Cloud y la autenticación
Si no has creado un proyecto, hazlo ahora. Google Cloud Expande esta sección para obtener instrucciones.
Accede a tu cuenta de Google Cloud . Si eres nuevo en Google Cloud,
crea una cuenta para evaluar el rendimiento de nuestros productos en situaciones reales. Los clientes nuevos también obtienen $300 en créditos gratuitos para ejecutar, probar y, además, implementar cargas de trabajo.
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.
Para inicializar gcloud CLI, ejecuta el siguiente comando:
gcloudinit
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: Un valor de número entero de resultados que se mostrarán (opcional). Si omites el campo "maxResults" y su valor, la API muestra el valor predeterminado de 10 resultados. Este campo no se aplica a los siguientes tipos de funciones: TEXT_DETECTION, DOCUMENT_TEXT_DETECTION o CROP_HINTS.
PROJECT_ID: Es el ID del proyecto de Google Cloud .
Método HTTP y 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());}}}}}
// Imports the Google Cloud client libraryconstvision=require('@google-cloud/vision');// Creates a clientconstclient=newvision.ImageAnnotatorClient();/** * TODO(developer): Uncomment the following line before running the sample. */// const fileName = 'Local image file, e.g. /path/to/image.png';// Detect similar images on the web to a local fileconst[result]=awaitclient.webDetection(fileName);constwebDetection=result.webDetection;if(webDetection.fullMatchingImages.length){console.log(`Full matches found: ${webDetection.fullMatchingImages.length}`);webDetection.fullMatchingImages.forEach(image=>{console.log(` URL: ${image.url}`);console.log(` Score: ${image.score}`);});}if(webDetection.partialMatchingImages.length){console.log(`Partial matches found: ${webDetection.partialMatchingImages.length}`);webDetection.partialMatchingImages.forEach(image=>{console.log(` URL: ${image.url}`);console.log(` Score: ${image.score}`);});}if(webDetection.webEntities.length){console.log(`Web entities found: ${webDetection.webEntities.length}`);webDetection.webEntities.forEach(webEntity=>{console.log(` Description: ${webEntity.