ΠŸΠ΅Ρ€Π΅ΠΉΡ‚ΠΈ ΠΊ содСрТимому

Security Alarm System Project Using Ultralytics YOLO11

БистСма ΠΎΡ…Ρ€Π°Π½Π½ΠΎΠΉ сигнализации

The Security Alarm System Project utilizing Ultralytics YOLO11 integrates advanced computer vision capabilities to enhance security measures. YOLO11, developed by Ultralytics, provides real-time object detection, allowing the system to identify and respond to potential security threats promptly. This project offers several advantages:

  • Real-time Detection: YOLO11's efficiency enables the Security Alarm System to detect and respond to security incidents in real-time, minimizing response time.
  • Accuracy: YOLO11 is known for its accuracy in object detection, reducing false positives and enhancing the reliability of the security alarm system.
  • ВозмоТности ΠΈΠ½Ρ‚Π΅Π³Ρ€Π°Ρ†ΠΈΠΈ: ΠŸΡ€ΠΎΠ΅ΠΊΡ‚ ΠΌΠΎΠΆΠ΅Ρ‚ Π±Ρ‹Ρ‚ΡŒ Π»Π΅Π³ΠΊΠΎ ΠΈΠ½Ρ‚Π΅Π³Ρ€ΠΈΡ€ΠΎΠ²Π°Π½ Π² ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰ΡƒΡŽ инфраструктуру бСзопасности, обСспСчивая ΠΌΠΎΠ΄Π΅Ρ€Π½ΠΈΠ·ΠΈΡ€ΠΎΠ²Π°Π½Π½Ρ‹ΠΉ ΡƒΡ€ΠΎΠ²Π΅Π½ΡŒ ΠΈΠ½Ρ‚Π΅Π»Π»Π΅ΠΊΡ‚ΡƒΠ°Π»ΡŒΠ½ΠΎΠ³ΠΎ наблюдСния.



Π‘ΠΌΠΎΡ‚Ρ€ΠΈ: Security Alarm System Project with Ultralytics YOLO11 ΠžΠ±Π½Π°Ρ€ΡƒΠΆΠ΅Π½ΠΈΠ΅ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ΠΎΠ²

Код

НастройтС ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€Ρ‹ сообщСния

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΠ΅

ГСнСрация ΠΏΠ°Ρ€ΠΎΠ»Π΅ΠΉ для ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠΉ Π½Π΅ΠΎΠ±Ρ…ΠΎΠ΄ΠΈΠΌΠ°

  • ΠŸΠ΅Ρ€Π΅ΠΉΠ΄ΠΈ Π² Ρ€Π°Π·Π΄Π΅Π» App Password Generator, ΡƒΠΊΠ°ΠΆΠΈ Π½Π°Π·Π²Π°Π½ΠΈΠ΅ прилоТСния, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ "security project", ΠΈ ΠΏΠΎΠ»ΡƒΡ‡ΠΈ 16-Π·Π½Π°Ρ‡Π½Ρ‹ΠΉ ΠΏΠ°Ρ€ΠΎΠ»ΡŒ. Π‘ΠΊΠΎΠΏΠΈΡ€ΡƒΠΉ этот ΠΏΠ°Ρ€ΠΎΠ»ΡŒ ΠΈ Π²ΡΡ‚Π°Π²ΡŒ Π΅Π³ΠΎ Π² ΡƒΠΊΠ°Π·Π°Π½Π½ΠΎΠ΅ ΠΏΠΎΠ»Π΅ для Π²Π²ΠΎΠ΄Π° пароля, ΠΊΠ°ΠΊ ΡƒΠΊΠ°Π·Π°Π½ΠΎ Π² инструкции.
password = ""
from_email = ""  # must match the email used to generate the password
to_email = ""  # receiver email

Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ сСрвСра ΠΈ аутСнтификация

import smtplib

server = smtplib.SMTP("smtp.gmail.com: 587")
server.starttls()
server.login(from_email, password)

Ѐункция ΠΎΡ‚ΠΏΡ€Π°Π²ΠΊΠΈ элСктронной ΠΏΠΎΡ‡Ρ‚Ρ‹

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText


def send_email(to_email, from_email, object_detected=1):
    """Sends an email notification indicating the number of objects detected; defaults to 1 object."""
    message = MIMEMultipart()
    message["From"] = from_email
    message["To"] = to_email
    message["Subject"] = "Security Alert"
    # Add in the message body
    message_body = f"ALERT - {object_detected} objects has been detected!!"

    message.attach(MIMEText(message_body, "plain"))
    server.sendmail(from_email, to_email, message.as_string())

ΠžΠ±Π½Π°Ρ€ΡƒΠΆΠ΅Π½ΠΈΠ΅ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ΠΎΠ² ΠΈ ΠΎΡ‚ΠΏΡ€Π°Π²ΠΊΠ° ΠΎΠΏΠΎΠ²Π΅Ρ‰Π΅Π½ΠΈΠΉ

from time import time

import cv2
import torch

from ultralytics import YOLO
from ultralytics.utils.plotting import Annotator, colors


class ObjectDetection:
    def __init__(self, capture_index):
        """Initializes an ObjectDetection instance with a given camera index."""
        self.capture_index = capture_index
        self.email_sent = False

        # model information
        self.model = YOLO("yolo11n.pt")

        # visual information
        self.annotator = None
        self.start_time = 0
        self.end_time = 0

        # device information
        self.device = "cuda" if torch.cuda.is_available() else "cpu"

    def predict(self, im0):
        """Run prediction using a YOLO model for the input image `im0`."""
        results = self.model(im0)
        return results

    def display_fps(self, im0):
        """Displays the FPS on an image `im0` by calculating and overlaying as white text on a black rectangle."""
        self.end_time = time()
        fps = 1 / round(self.end_time - self.start_time, 2)
        text = f"FPS: {int(fps)}"
        text_size = cv2.getTextSize(text, cv2.FONT_HERSHEY_SIMPLEX, 1.0, 2)[0]
        gap = 10
        cv2.rectangle(
            im0,
            (20 - gap, 70 - text_size[1] - gap),
            (20 + text_size[0] + gap, 70 + gap),
            (255, 255, 255),
            -1,
        )
        cv2.putText(im0, text, (20, 70), cv2.FONT_HERSHEY_SIMPLEX, 1.0, (0, 0, 0), 2)

    def plot_bboxes(self, results, im0):
        """Plots bounding boxes on an image given detection results; returns annotated image and class IDs."""
        class_ids = []
        self.annotator = Annotator(im0, 3, results[0].names)
        boxes = results[0].boxes.xyxy.cpu()
        clss = results[0].boxes.cls.cpu().tolist()
        names = results[0].names
        for box, cls in zip(boxes, clss):
            class_ids.append(cls)
            self.annotator.box_label(box, label=names[int(cls)], color=colors(int(cls), True))
        return im0, class_ids

    def __call__(self):
        """Run object detection on video frames from a camera stream, plotting and showing the results."""
        cap = cv2.VideoCapture(self.capture_index)
        assert cap.isOpened()
        cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
        cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
        frame_count = 0
        while True:
            self.start_time = time()
            ret, im0 = cap.read()
            assert ret
            results = self.predict(im0)
            im0, class_ids = self.plot_bboxes(results, im0)

            if len(class_ids) > 0:  # Only send email If not sent before
                if not self.email_sent:
                    send_email(to_email, from_email, len(class_ids))
                    self.email_sent = True
            else:
                self.email_sent = False

            self.display_fps(im0)
            cv2.imshow("YOLO11 Detection", im0)
            frame_count += 1
            if cv2.waitKey(5) & 0xFF == 27:
                break
        cap.release()
        cv2.destroyAllWindows()
        server.quit()

Π’Ρ‹Π·ΠΎΠ²ΠΈ класс "ΠžΠ±Π½Π°Ρ€ΡƒΠΆΠ΅Π½ΠΈΠ΅ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ΠΎΠ²" ΠΈ Π²Ρ‹ΠΏΠΎΠ»Π½ΠΈ ΡƒΠΌΠΎΠ·Π°ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅

detector = ObjectDetection(capture_index=0)
detector()

Π’ΠΎΡ‚ ΠΈ всС! Когда Ρ‚Ρ‹ Π²Ρ‹ΠΏΠΎΠ»Π½ΠΈΡˆΡŒ ΠΊΠΎΠ΄, Ρ‚ΠΎ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡˆΡŒ ΠΎΠ΄Π½ΠΎ ΡƒΠ²Π΅Π΄ΠΎΠΌΠ»Π΅Π½ΠΈΠ΅ Π½Π° свой email, Ссли Π±ΡƒΠ΄Π΅Ρ‚ ΠΎΠ±Π½Π°Ρ€ΡƒΠΆΠ΅Π½ ΠΊΠ°ΠΊΠΎΠΉ-Π»ΠΈΠ±ΠΎ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚. Π£Π²Π΅Π΄ΠΎΠΌΠ»Π΅Π½ΠΈΠ΅ отправляСтся сразу, Π° Π½Π΅ ΠΌΠ½ΠΎΠ³ΠΎΠΊΡ€Π°Ρ‚Π½ΠΎ. Однако Π½Π΅ стСсняйся Π½Π°ΡΡ‚Ρ€Π°ΠΈΠ²Π°Ρ‚ΡŒ ΠΊΠΎΠ΄ Π² соотвСтствии с трСбованиями Ρ‚Π²ΠΎΠ΅Π³ΠΎ ΠΏΡ€ΠΎΠ΅ΠΊΡ‚Π°.

ΠžΠ±Ρ€Π°Π·Π΅Ρ† ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½Π½ΠΎΠ³ΠΎ элСктронного письма

ΠžΠ±Ρ€Π°Π·Π΅Ρ† ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½Π½ΠΎΠ³ΠΎ элСктронного письма

Π’ΠžΠŸΠ ΠžΠ‘Π« И ΠžΠ’Π’Π•Π’Π«

How does Ultralytics YOLO11 improve the accuracy of a security alarm system?

Ultralytics YOLO11 enhances security alarm systems by delivering high-accuracy, real-time object detection. Its advanced algorithms significantly reduce false positives, ensuring that the system only responds to genuine threats. This increased reliability can be seamlessly integrated with existing security infrastructure, upgrading the overall surveillance quality.

Can I integrate Ultralytics YOLO11 with my existing security infrastructure?

Yes, Ultralytics YOLO11 can be seamlessly integrated with your existing security infrastructure. The system supports various modes and provides flexibility for customization, allowing you to enhance your existing setup with advanced object detection capabilities. For detailed instructions on integrating YOLO11 in your projects, visit the integration section.

What are the storage requirements for running Ultralytics YOLO11?

Running Ultralytics YOLO11 on a standard setup typically requires around 5GB of free disk space. This includes space for storing the YOLO11 model and any additional dependencies. For cloud-based solutions, Ultralytics HUB offers efficient project management and dataset handling, which can optimize storage needs. Learn more about the Pro Plan for enhanced features including extended storage.

What makes Ultralytics YOLO11 different from other object detection models like Faster R-CNN or SSD?

Ultralytics YOLO11 provides an edge over models like Faster R-CNN or SSD with its real-time detection capabilities and higher accuracy. Its unique architecture allows it to process images much faster without compromising on precision, making it ideal for time-sensitive applications like security alarm systems. For a comprehensive comparison of object detection models, you can explore our guide.

How can I reduce the frequency of false positives in my security system using Ultralytics YOLO11?

To reduce false positives, ensure your Ultralytics YOLO11 model is adequately trained with a diverse and well-annotated dataset. Fine-tuning hyperparameters and regularly updating the model with new data can significantly improve detection accuracy. Detailed hyperparameter tuning techniques can be found in our hyperparameter tuning guide.


πŸ“… Created 10 months ago ✏️ Updated 4 days ago

ΠšΠΎΠΌΠΌΠ΅Π½Ρ‚Π°Ρ€ΠΈΠΈ