Detectar varios objetos en archivos de Cloud Storage (beta)
Organízate con las colecciones
Guarda y clasifica el contenido según tus preferencias.
Realiza la detección de objetos en varios objetos de una imagen de un archivo almacenado en Cloud Storage (para el lanzamiento de la versión beta).
Código de ejemplo
A menos que se indique lo contrario, el contenido de esta página está sujeto a la licencia Reconocimiento 4.0 de Creative Commons y las muestras de código están sujetas a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio web de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
[[["Es fácil de entender","easyToUnderstand","thumb-up"],["Me ofreció una solución al problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Es difícil de entender","hardToUnderstand","thumb-down"],["La información o el código de muestra no son correctos","incorrectInformationOrSampleCode","thumb-down"],["Me faltan las muestras o la información que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],[],[],[],null,["# Detect multiple objects in a Cloud Storage file (beta)\n\nPerform object detection for multiple objects in an image on a file stored in Cloud Storage (for beta launch).\n\nCode sample\n-----------\n\n### Java\n\n\nBefore trying this sample, follow the Java setup instructions in the\n[Vision quickstart using\nclient libraries](/vision/docs/quickstart-client-libraries).\n\n\nFor more information, see the\n[Vision Java API\nreference documentation](/java/docs/reference/google-cloud-vision/latest/overview).\n\n\nTo authenticate to Vision, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n /**\n * Detects localized objects in a remote image on Google Cloud Storage.\n *\n * @param gcsPath The path to the remote file on Google Cloud Storage to detect localized objects\n * on.\n * @param out A {@link PrintStream} to write detected objects to.\n * @throws Exception on errors while closing the client.\n * @throws IOException on Input/Output errors.\n */\n public static void detectLocalizedObjectsGcs(String gcsPath, PrintStream out)\n throws Exception, IOException {\n List\u003cAnnotateImageRequest\u003e requests = new ArrayList\u003c\u003e();\n\n ImageSource imgSource = ImageSource.newBuilder().setGcsImageUri(gcsPath).build();\n Image img = Image.newBuilder().setSource(imgSource).build();\n\n AnnotateImageRequest request =\n AnnotateImageRequest.newBuilder()\n .addFeatures(Feature.newBuilder().setType(Type.OBJECT_LOCALIZATION))\n .setImage(img)\n .build();\n requests.add(request);\n\n // Perform the request\n try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {\n BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);\n List\u003cAnnotateImageResponse\u003e responses = response.getResponsesList();\n client.close();\n // Display the results\n for (AnnotateImageResponse res : responses) {\n for (LocalizedObjectAnnotation entity : res.getLocalizedObjectAnnotationsList()) {\n out.format(\"Object name: %s\\n\", entity.getName());\n out.format(\"Confidence: %s\\n\", entity.getScore());\n out.format(\"Normalized Vertices:\\n\");\n entity\n .getBoundingPoly()\n .getNormalizedVerticesList()\n .forEach(vertex -\u003e out.format(\"- (%s, %s)\\n\", vertex.getX(), vertex.getY()));\n }\n }\n }\n }\n\n### Python\n\n\nBefore trying this sample, follow the Python setup instructions in the\n[Vision quickstart using\nclient libraries](/vision/docs/quickstart-client-libraries).\n\n\nFor more information, see the\n[Vision Python API\nreference documentation](/python/docs/reference/vision/latest).\n\n\nTo authenticate to Vision, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n def localize_objects_uri(uri):\n \"\"\"Localize objects in the image on Google Cloud Storage\n\n Args:\n uri: The path to the file in Google Cloud Storage (gs://...)\n \"\"\"\n from google.cloud import vision_v1p3beta1 as vision\n\n client = vision.ImageAnnotatorClient()\n\n image = vision.Image()\n image.source.image_uri = uri\n\n objects = client.object_localization(image=image).localized_object_annotations\n\n print(f\"Number of objects found: {len(objects)}\")\n for object_ in objects:\n print(f\"\\n{object_.name} (confidence: {object_.score})\")\n print(\"Normalized bounding polygon vertices: \")\n for vertex in object_.bounding_poly.normalized_vertices:\n print(f\" - ({vertex.x}, {vertex.y})\")\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=vision)."]]