×
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 to implement drawing object borders around animals in images and videos and labelling these borders with particular animal names?

by Mirek Hermut / Sunday, 12 May 2024 / Published in Artificial Intelligence, EITC/AI/GVAPI Google Vision API, Understanding shapes and objects, Drawing object borders using pillow python library

The task of detecting animals in images and videos, drawing borders around them, and labeling these borders with the names of the animals involves a combination of techniques from the fields of computer vision and machine learning. This process can be broken down into several key steps: utilizing the Google Vision API for object detection, processing images in Python using the Pillow library, and applying appropriate labeling techniques. Here, we will walk through each of these steps in detail, providing a comprehensive guide on how to implement this functionality effectively.

Step 1: Setting Up the Environment

Before starting, ensure that you have Python installed on your machine. Python libraries such as Pillow (PIL Fork) and Google Client Library will be required. You can install these using pip:

bash
pip install pillow google-cloud-vision

You will also need to set up a Google Cloud account and enable the Vision API, creating credentials (API key or service account) to authenticate your requests.

Step 2: Using Google Vision API for Animal Detection

Google Vision API provides powerful pre-trained models for detecting objects in images. For our purpose, we'll focus on detecting animals within images. Here's how you can set up and make a request to the Vision API to detect objects:

1. Import the libraries and initialize the client:

python
    from google.cloud import vision
    client = vision.ImageAnnotatorClient()
    

2. Load your image into the Vision API:

You can load an image from a local file or from an URI:

python
    def load_image(image_path):
        with open(image_path, 'rb') as image_file:
            content = image_file.read()
        image = vision.Image(content=content)
        return image
    

3. Request the API to detect objects:

python
    def detect_animals(image):
        objects = client.object_localization(image=image).localized_object_annotations
        return objects
    

4. Filter for animal detections:

The Vision API recognizes various object types, so you'll need to filter out non-animal objects:

{{EJS12}}

Step 3: Drawing Borders and Labeling Using Pillow

Once you have the animal objects detected and filtered, the next step is to draw borders around these objects and label them. Pillow, which is an updated fork of PIL, offers comprehensive capabilities for image processing. 1. Drawing the object borders:
python
    from PIL import Image, ImageDraw, ImageFont

    def draw_borders(image_path, objects):
        image = Image.open(image_path)
        draw = ImageDraw.Draw(image)

        # Loop through each object and draw a rectangle
        for obj in objects:
            box = [(vertex.x, vertex.y) for vertex in obj.bounding_poly.normalized_vertices]
            draw.rectangle(box, outline='red', width=3)
        
        return image
    

2. Labeling the borders:

To label the borders with the animal names, you can use Pillow to draw text:

{{EJS14}}

Step 4: Integrating the Components

Now, integrate all the components into a single function that processes an image, detects and filters animals, and then draws labeled borders around them:
python
def process_image(image_path):
    image = load_image(image_path)
    detected_objects = detect_animals(image)
    animal_objects = filter_animals(detected_objects)
    image_with_borders = draw_borders(image_path, animal_objects)
    final_image = label_objects(image_with_borders, animal_objects)
    final_image.show()

This function can be called with the path to an image, and it will display the image with detected animals highlighted and labeled.

Practical Considerations and Limitations

While the outlined approach is robust for basic use cases, several considerations should be kept in mind:
- Accuracy of Detection: The accuracy of animal detection depends heavily on the quality of the image and the capabilities of the Google Vision API's pre-trained model.
- Performance: Processing high-resolution images or a large volume of images can be computationally intensive and may require optimization or cloud-based processing.
- Cost: Google Vision API charges based on the number of requests. Frequent or large-scale use may incur significant costs.

This guide provides a foundational approach to detecting animals in images and videos, drawing borders around them, and labeling these borders with the names of the animals using Python, Google Vision API, and Pillow. By following the steps outlined, one can build a functional prototype for animal detection and labeling in multimedia content.

Other recent questions and answers regarding Drawing object borders using pillow python library:

  • Can Google Vision API be applied to detecting and labelling objects with pillow Python library in videos rather than in images?
  • How can the display text be added to the image when drawing object borders using the "draw_vertices" function?
  • What are the parameters of the "draw.line" method in the provided code, and how are they used to draw lines between vertices values?
  • How can the pillow library be used to draw object borders in Python?
  • What is the purpose of the "draw_vertices" function in the provided code?
  • How can the Google Vision API help in understanding shapes and objects in an image?

More questions and answers:

  • Field: Artificial Intelligence
  • Programme: EITC/AI/GVAPI Google Vision API (go to the certification programme)
  • Lesson: Understanding shapes and objects (go to related lesson)
  • Topic: Drawing object borders using pillow python library (go to related topic)
Tagged under: Artificial Intelligence, Computer Vision, Google Cloud, Image Processing, Machine Learning, Python
Home » Artificial Intelligence / Drawing object borders using pillow python library / EITC/AI/GVAPI Google Vision API / Understanding shapes and objects » How to implement drawing object borders around animals in images and videos and labelling these borders with particular animal names?

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