×
1 Choose EITC/EITCA Certificates
2 Learn and take online exams
3 Get your IT skills certified

Confirm your IT skills and competencies under the European IT Certification framework from anywhere in the world fully online.

EITCA Academy

Digital skills attestation standard by the European IT Certification Institute aiming to support Digital Society development

LOG IN TO YOUR ACCOUNT

CREATE AN ACCOUNT FORGOT YOUR PASSWORD?

FORGOT YOUR PASSWORD?

AAH, WAIT, I REMEMBER NOW!

CREATE AN ACCOUNT

ALREADY HAVE AN ACCOUNT?
EUROPEAN INFORMATION TECHNOLOGIES CERTIFICATION ACADEMY - ATTESTING YOUR PROFESSIONAL DIGITAL SKILLS
  • SIGN UP
  • LOGIN
  • INFO

EITCA Academy

EITCA Academy

The European Information Technologies Certification Institute - EITCI ASBL

Certification Provider

EITCI Institute ASBL

Brussels, European Union

Governing European IT Certification (EITC) framework in support of the IT professionalism and Digital Society

  • CERTIFICATES
    • EITCA ACADEMIES
      • EITCA ACADEMIES CATALOGUE<
      • EITCA/CG COMPUTER GRAPHICS
      • EITCA/IS INFORMATION SECURITY
      • EITCA/BI BUSINESS INFORMATION
      • EITCA/KC KEY COMPETENCIES
      • EITCA/EG E-GOVERNMENT
      • EITCA/WD WEB DEVELOPMENT
      • EITCA/AI ARTIFICIAL INTELLIGENCE
    • EITC CERTIFICATES
      • EITC CERTIFICATES CATALOGUE<
      • COMPUTER GRAPHICS CERTIFICATES
      • WEB DESIGN CERTIFICATES
      • 3D DESIGN CERTIFICATES
      • OFFICE IT CERTIFICATES
      • BITCOIN BLOCKCHAIN CERTIFICATE
      • WORDPRESS CERTIFICATE
      • CLOUD PLATFORM CERTIFICATENEW
    • EITC CERTIFICATES
      • INTERNET CERTIFICATES
      • CRYPTOGRAPHY CERTIFICATES
      • BUSINESS IT CERTIFICATES
      • TELEWORK CERTIFICATES
      • PROGRAMMING CERTIFICATES
      • DIGITAL PORTRAIT CERTIFICATE
      • WEB DEVELOPMENT CERTIFICATES
      • DEEP LEARNING CERTIFICATESNEW
    • CERTIFICATES FOR
      • EU PUBLIC ADMINISTRATION
      • TEACHERS AND EDUCATORS
      • IT SECURITY PROFESSIONALS
      • GRAPHICS DESIGNERS & ARTISTS
      • BUSINESSMEN AND MANAGERS
      • BLOCKCHAIN DEVELOPERS
      • WEB DEVELOPERS
      • CLOUD AI EXPERTSNEW
  • FEATURED
  • SUBSIDY
  • HOW IT WORKS
  •   IT ID
  • ABOUT
  • CONTACT
  • MY ORDER
    Your current order is empty.
EITCIINSTITUTE
CERTIFIED

How can we visually identify and highlight the detected objects in an image using the pillow library?

by EITCA Academy / Saturday, 30 December 2023 / Published in Artificial Intelligence, EITC/AI/GVAPI Google Vision API, Advanced images understanding, Objects detection, Examination review

To visually identify and highlight detected objects in an image using the Pillow library, we can follow a step-by-step process. The Pillow library is a powerful Python imaging library that provides a wide range of image processing capabilities. By combining the capabilities of the Pillow library with the object detection functionality of the Google Vision API, we can achieve this task efficiently.

Here are the steps to visually identify and highlight detected objects in an image using the Pillow library:

1. Install the necessary libraries: Begin by installing the required libraries. Install Pillow using the command `pip install pillow`. Additionally, you will need to set up the Google Vision API and install the Google Cloud client library for Python.

2. Authenticate with the Google Vision API: To use the Google Vision API, you need to authenticate your application. Follow the documentation provided by Google to obtain the necessary credentials.

3. Load and analyze the image: Use the Pillow library to load the image you want to analyze. You can use the `Image.open()` method to open the image file. Once the image is loaded, convert it to a format compatible with the Google Vision API, such as JPEG or PNG.

4. Send the image to the Google Vision API: Use the Google Cloud client library for Python to send the image to the Google Vision API for object detection. This can be done by creating a request object with the image data and calling the appropriate method, such as `image_annotator_client.object_localization().annotate_image()`.

5. Retrieve the object detection results: Extract the object detection results from the response received from the Google Vision API. The response will contain information about the detected objects, such as their bounding boxes, labels, and confidence scores.

6. Draw bounding boxes on the image: Use the Pillow library to draw bounding boxes around the detected objects on the image. You can use the `ImageDraw.Draw()` method to create a drawing object, and then use the `draw.rectangle()` method to draw the bounding boxes.

7. Add labels and scores to the image: To enhance the visualization, you can add labels and confidence scores to the image. Use the `draw.text()` method from the Pillow library to overlay the labels and scores on the image.

8. Save and display the annotated image: Save the annotated image using the `Image.save()` method from the Pillow library. You can choose the desired format, such as JPEG or PNG. Optionally, display the annotated image using the `Image.show()` method.

By following these steps, you can visually identify and highlight the detected objects in an image using the Pillow library. The combination of the powerful image processing capabilities of Pillow and the object detection functionality of the Google Vision API allows for efficient and accurate analysis of images.

Example:

python
from PIL import Image, ImageDraw
from google.cloud import vision

# Load and analyze the image
image_path = 'path/to/your/image.jpg'
image = Image.open(image_path)
image_data = image.tobytes()

# Authenticate with the Google Vision API
client = vision.ImageAnnotatorClient.from_service_account_json('path/to/your/credentials.json')

# Send the image to the Google Vision API for object detection
response = client.object_localization(image=vision.Image(content=image_data))
objects = response.localized_object_annotations

# Draw bounding boxes on the image
draw = ImageDraw.Draw(image)
for obj in objects:
    bbox = obj.bounding_poly.normalized_vertices
    draw.rectangle([(bbox[0].x * image.width, bbox[0].y * image.height),
                    (bbox[2].x * image.width, bbox[2].y * image.height)],
                   outline='red', width=3)

    # Add labels and scores to the image
    label = obj.name
    score = obj.score
    draw.text((bbox[0].x * image.width, bbox[0].y * image.height - 15),
              f'{label} ({score:.2f})', fill='red')

# Save and display the annotated image
annotated_image_path = 'path/to/save/annotated_image.jpg'
image.save(annotated_image_path)
image.show()

In this example, we first load and analyze the image using the Pillow library. Then, we authenticate with the Google Vision API and send the image for object detection. We retrieve the object detection results and use the Pillow library to draw bounding boxes around the detected objects on the image. Additionally, we add labels and confidence scores to the image. Finally, we save and display the annotated image.

Other recent questions and answers regarding Advanced images understanding:

  • What are some predefined categories for object recognition in Google Vision API?
  • What is the recommended approach for using the safe search detection feature in combination with other moderation techniques?
  • How can we access and display the likelihood values for each category in the safe search annotation?
  • How can we obtain the safe search annotation using the Google Vision API in Python?
  • What are the five categories included in the safe search detection feature?
  • How does the Google Vision API's safe search feature detect explicit content within images?
  • How can we organize the extracted object information in a tabular format using the pandas data frame?
  • How can we extract all the object annotations from the API's response?
  • What libraries and programming language are used to demonstrate the functionality of the Google Vision API?
  • How does the Google Vision API perform object detection and localization in images?

View more questions and answers in Advanced images understanding

More questions and answers:

  • Field: Artificial Intelligence
  • Programme: EITC/AI/GVAPI Google Vision API (go to the certification programme)
  • Lesson: Advanced images understanding (go to related lesson)
  • Topic: Objects detection (go to related topic)
  • Examination review
Tagged under: Artificial Intelligence, Google Vision API, Image Processing, Object Detection, Pillow Library, Python
Home » Advanced images understanding / Artificial Intelligence / EITC/AI/GVAPI Google Vision API / Examination review / Objects detection » How can we visually identify and highlight the detected objects in an image using the pillow library?

Certification Center

USER MENU

  • My Account

CERTIFICATE CATEGORY

  • EITC Certification (105)
  • EITCA Certification (9)

What are you looking for?

  • Introduction
  • How it works?
  • EITCA Academies
  • EITCI DSJC Subsidy
  • Full EITC catalogue
  • Your order
  • Featured
  •   IT ID
  • EITCA reviews (Medium publ.)
  • About
  • Contact

EITCA Academy is a part of the European IT Certification framework

The European IT Certification framework has been established in 2008 as a Europe based and vendor independent standard in widely accessible online certification of digital skills and competencies in many areas of professional digital specializations. The EITC framework is governed by the European IT Certification Institute (EITCI), a non-profit certification authority supporting information society growth and bridging the digital skills gap in the EU.

Eligibility for EITCA Academy 80% EITCI DSJC Subsidy support

80% of EITCA Academy fees subsidized in enrolment by

    EITCA Academy Secretary Office

    European IT Certification Institute ASBL
    Brussels, Belgium, European Union

    EITC / EITCA Certification Framework Operator
    Governing European IT Certification Standard
    Access contact form or call +32 25887351

    Follow EITCI on X
    Visit EITCA Academy on Facebook
    Engage with EITCA Academy on LinkedIn
    Check out EITCI and EITCA videos on YouTube

    Funded by the European Union

    Funded by the European Regional Development Fund (ERDF) and the European Social Fund (ESF) in series of projects since 2007, currently governed by the European IT Certification Institute (EITCI) since 2008

    Information Security Policy | DSRRM and GDPR Policy | Data Protection Policy | Record of Processing Activities | HSE Policy | Anti-Corruption Policy | Modern Slavery Policy

    Automatically translate to your language

    Terms and Conditions | Privacy Policy
    EITCA Academy
    • EITCA Academy on social media
    EITCA Academy


    © 2008-2025  European IT Certification Institute
    Brussels, Belgium, European Union

    TOP
    Chat with Support
    Chat with Support
    Questions, doubts, issues? We are here to help you!
    End chat
    Connecting...
    Do you have any questions?
    Do you have any questions?
    :
    :
    :
    Send
    Do you have any questions?
    :
    :
    Start Chat
    The chat session has ended. Thank you!
    Please rate the support you've received.
    Good Bad