18.3 C
London
Friday, September 20, 2024

Real-Time Zone Monitoring with Computer Vision: Automated Surveillance and Alert Systems

Here is the rewritten article:

Introduction

In today’s fast-paced industrial environments, ensuring the safety of employees is of utmost importance. With the increasing use of moving equipment, it’s crucial to implement effective safety measures to prevent accidents. One potential solution is computer vision, which can help monitor and track people entering restricted zones. In this article, we’ll explore how to create a real-time person detection model and add zone monitoring capabilities to the system.

Track People Entering Restricted Zones with Computer Vision

In work environments where employees are around moving equipment – from vehicles to automated systems – it is essential that all safety rules and regulations are followed.

One potential use of computer vision is to identify when people enter a restricted zone, which could be used to monitor entry into a zone and count the number of people present to ensure the zone does not get too crowded.

In this tutorial, we will cover how to create your own real-time person detection model as well as add zone monitoring abilities to the system.

To build this application, we will follow these steps:

  • Train a person detection model
  • Install and import libraries
  • Define a zone of interest from a reference image
  • Define color annotators
  • Write logic to monitor when people are in a zone
  • Test our program

Create a Model

To get started, create a free Roboflow account. Then, click “Create Project” to create a new project. Set a name for your project and choose the “Object Detection” project type:

Next, add your images. The images I used are downloadable through this link. Make sure to download the dataset and have the files saved somewhere.

Add the downloaded images to your dataset and continue:

Then, add the classes you want your model to detect. For our use case, we only need one class: person.

Install and Import Libraries

First, install the required libraries. To do this, we need to run the following code:

!pip install supervision inference

Next, create a new Python file and import the following libraries into your script:

import supervision as sv
import cv2
from typing import Union, List, Optional
from inference.core.interfaces.camera.entities import VideoFrame
from inference import InferencePipeline
import numpy as np

Create Zone From Image

To track when people enter and exit a zone, we need to define exactly what zone we want to track. Using Polygon Zone, we can drag and drop an image and create our preferred zone.

Open Polygon Zone, drag the image you want to use into the editor, then click to draw a polygon around the area you want to track:

Copy the NumPy points into your program:

zone = np.array(
    [
        [426, 228],
        [358, 393],
        [367, 434],
        [392, 464],
        [427, 486],
        [479, 492],
        [533, 504],
        [895, 511],
        [872, 243],
        [429, 226],
    ]
)

Create Zone Logic

We are now ready to define logic that tracks when people enter and exit a zone. For this, we will use the PolygonZone functionality in supervision, an open source Python package with utilities for working with computer vision models.

Here is the code we need:

def zone_logic(zone, detections, frame):
    polyzone = sv.PolygonZone(
        polygon=zone,
    )

    zone_annotated = sv.PolygonZoneAnnotator(
        zone=polyzone,
        color=sv.Color.RED,
        thickness=5,
    )
    people_in_box = 0
    zone_presence = polyzone.trigger(detections)
    zone_present_idxs = [idx for idx, present in enumerate(zone_presence) if present]

    for detection in zone_present_idxs:
        people_in_box += 1

    annotated_frame = zone_annotated.annotate(
        scene=frame, label=f"People inside Zone: {people_in_box}"
    )

Conclusion

In this guide, we learned how to create a real-time person detection model as well as leverage the model for zone monitoring tasks. Using Roboflow, we were able to create our own successful model and deploy it using an Inference Pipeline.

Frequently Asked Questions

Q1: What is the purpose of computer vision in industrial environments?

Computer vision is used to analyze and understand visual data in industrial environments, enabling improved safety, efficiency, and productivity. In this case, it helps track people entering restricted zones.

Q2: How do we define a zone of interest in computer vision?

We use a reference image and define the zone by drawing a polygon around the area we want to track using a tool like Polygon Zone.

Q3: What are the benefits of using real-time person detection models in industrial environments?

Real-time person detection models enable us to monitor and track people entering restricted zones, reducing the risk of accidents and improving overall safety.

Q4: How do we integrate the real-time person detection model with the Inference Pipeline?

We use the Inference Pipeline to deploy our model and integrate it with the computer vision system, enabling real-time detection and tracking of people.

Q5: What is the importance of zone monitoring in industrial environments?

Zone monitoring is crucial in industrial environments to ensure the safety of employees and prevent accidents. By tracking people entering restricted zones, we can prevent unauthorized access and minimize the risk of accidents.

Latest news
Related news
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x