Reference for ultralytics/solutions/security_alarm.py
Note
This file is available at https://github.com/ultralytics/ultralytics/blob/main/ultralytics/solutions/security_alarm.py. If you spot a problem please help fix it by contributing a Pull Request 🛠️. Thank you 🙏!
ultralytics.solutions.security_alarm.SecurityAlarm
SecurityAlarm(**kwargs: Any)
Bases: BaseSolution
A class to manage security alarm functionalities for real-time monitoring.
This class extends the BaseSolution class and provides features to monitor objects in a frame, send email notifications when specific thresholds are exceeded for total detections, and annotate the output frame for visualization.
Attributes:
| Name | Type | Description |
|---|---|---|
email_sent |
bool
|
Flag to track if an email has already been sent for the current event. |
records |
int
|
Threshold for the number of detected objects to trigger an alert. |
server |
SMTP
|
SMTP server connection for sending email alerts. |
to_email |
str
|
Recipient's email address for alerts. |
from_email |
str
|
Sender's email address for alerts. |
Methods:
| Name | Description |
|---|---|
authenticate |
Set up email server authentication for sending alerts. |
send_email |
Send an email notification with details and an image attachment. |
process |
Monitor the frame, process detections, and trigger alerts if thresholds are crossed. |
Examples:
>>> security = SecurityAlarm()
>>> security.authenticate("abc@gmail.com", "1111222233334444", "xyz@gmail.com")
>>> frame = cv2.imread("frame.jpg")
>>> results = security.process(frame)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Additional keyword arguments passed to the parent class. |
{}
|
Source code in ultralytics/solutions/security_alarm.py
36 37 38 39 40 41 42 43 44 45 46 47 | |
authenticate
authenticate(from_email: str, password: str, to_email: str) -> None
Authenticate the email server for sending alert notifications.
This method initializes a secure connection with the SMTP server and logs in using the provided credentials.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_email
|
str
|
Sender's email address. |
required |
password
|
str
|
Password for the sender's email account. |
required |
to_email
|
str
|
Recipient's email address. |
required |
Examples:
>>> alarm = SecurityAlarm()
>>> alarm.authenticate("sender@example.com", "password123", "recipient@example.com")
Source code in ultralytics/solutions/security_alarm.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
process
process(im0) -> SolutionResults
Monitor the frame, process object detections, and trigger alerts if thresholds are exceeded.
This method processes the input frame, extracts detections, annotates the frame with bounding boxes, and sends an email notification if the number of detected objects surpasses the specified threshold and an alert has not already been sent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
im0
|
ndarray
|
The input image or frame to be processed and annotated. |
required |
Returns:
| Type | Description |
|---|---|
SolutionResults
|
Contains processed image |
Examples:
>>> alarm = SecurityAlarm()
>>> frame = cv2.imread("path/to/image.jpg")
>>> results = alarm.process(frame)
Source code in ultralytics/solutions/security_alarm.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
send_email
send_email(im0, records: int = 5) -> None
Send an email notification with an image attachment indicating the number of objects detected.
This method encodes the input image, composes the email message with details about the detection, and sends it to the specified recipient.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
im0
|
ndarray
|
The input image or frame to be attached to the email. |
required |
records
|
int
|
The number of detected objects to be included in the email message. |
5
|
Examples:
>>> alarm = SecurityAlarm()
>>> frame = cv2.imread("path/to/image.jpg")
>>> alarm.send_email(frame, records=10)
Source code in ultralytics/solutions/security_alarm.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |