PROJECT REPORT
ON
WEB CAM ALERT AND EMAIL
NOTIFICATION
Submitted in partial fulfillment of the requirements
For the award of the degree of
BACHELOR OF TECHNOLOGY
IN
ARTIFICIAL INTELLIGENCE & MACHINE
LEARNING
Submitted By
KASAK SHASHWAT
(07615611623) (06815611623)
Under the guidance of
Rishabh Jain, Assistant Professor, AIML Department
Department of Artificial Intelligence & Machine Learning
Dr. Akhilesh Das Gupta Institute of Professional Studies
(Guru Gobind Singh Indraprastha University, Dwarka, Delhi.)
New Delhi -110053.
CERTIFICATE
We hereby certify that the work being presented in the project report entitled " Webcam
Alert and Email Notification System " is in partial fulfillment of the requirements for
the award of the degree of Bachelor of Technology in Artificial Intelligence &
Machine Learning from Dr. Akhilesh Das Gupta Institute of Professional Studies,
New Delhi. This is an authentic record of our own work carried out under the guidance of
Mr. Rishabh Jain, Supervisor in the Artificial Intelligence & Machine Learning
Department. The matter presented in this project has not been submitted by us for the
award of any other degree elsewhere.
Kasak Saxena Shashwat Bansal
(07615611623) (06815611623)
This is to certify that the above statement made by the candidates is correct to the best of
my knowledge. They are permitted to appear in the Project External Examination.
Mr. Rishabh Jain
Supervisor
Mr. Haider Abbas Prof. (Dr.) Ankit Verma
Project Incharge, AIML Head, AIML
i
ACKNOWLEDGEMENT
I/We would like to acknowledge the contributions of the following persons, without
whose help and guidance this report would not have been completed.
I/We acknowledge the counsel and support of our project guide Mr. Rishabh Jain,
Assistant Professor, AIML Department, with respect and gratitude, whose expertise,
guidance, support, encouragement, and enthusiasm has made this report possible. Their
feedback vastly improved the quality of this report and provided an enthralling
experience. I/We are indeed proud and fortunate to be supervised by him.
We are thankful to Prof. (Dr.) Ankit Verma, Head, AIML Department, Dr. Akhilesh
Das Gupta Institute of Professional Studies, New Delhi for his constant
encouragement, valuable suggestions and moral support and blessings.
I/We are immensely thankful to our esteemed Prof. (Dr.) Niranjan Bhattacharyya,
Director, Dr. Akhilesh Das Gupta Institute of Professional Studies, New Delhi for his
never-ending motivation and support.
I/We shall ever remain indebted to Mr. Haider Abbas, AIML Department and faculty
and staff members of Dr. Akhilesh Das Gupta Institute of Professional Studies, New
Delhi.
Finally, yet importantly, I/We would like to express our heartfelt thanks to God, our
beloved parents for their blessings, our friends/classmates for their help and wishes for
the successful completion of this project.
Kasak Saxena Shashwat Bansal
(07615611623) (06815611623)
ABSTRACT
The Webcam Alert and Email Notification System is an innovative surveillance solution
designed to enhance security by leveraging real-time monitoring and automated alert
mechanisms. This system utilizes a standard webcam integrated with computer vision
algorithms to detect motion or unauthorized activity within a defined area. Upon
detection, the system triggers an immediate alert and captures images or short video clips
of the event. These files are then transmitted through an automated email notification to
predefined recipients, ensuring that the user is informed instantly, regardless of their
location.
The primary goal of the project is to provide an affordable, scalable, and user-friendly
alternative to traditional security systems. The system is implemented using Python and
OpenCV for motion detection, along with SMTP libraries for handling email
transmission. The design emphasizes minimal hardware requirements, requiring only a
webcam and an internet-connected device, making it suitable for residential as well as
small-scale commercial applications.
Key features of the system include real-time detection, minimal false-positive alerts,
timestamped image capturing, and secure email delivery. The modular structure of the
software allows for easy customization, such as adding face recognition, sound alerts, or
cloud storage integration.
Overall, the Webcam Alert and Email Notification System presents a practical approach
to modern security challenges by combining simplicity, automation, and remote
accessibility. It holds significant potential for deployment in areas requiring cost-
effective and efficient surveillance solutions.
iii
ii
TABLE OF CONTENTS
Certificate i
Acknowledgement ii
Abstract iii
Table of Contents iv
List of Figure vi
List of Tables vii
CHAPTER 1: INTRODUCTION AND LITERATURE REVIEW 1
1.1 Introduction
1.2 Basic Terms and Concepts
1.2.1 Motion Detection
1.2.2 Thresholding and Dilation
1.2.3 Contour Detection
1.3 Literature Overview
1.4 Motivation
1.5 Organization of Project Report
CHAPTER 2: METHODOLOGY ADOPTED 3
2.1 Overall Workflow of the System
2.1.1 Flowchart / Block Diagram
2.2 Tools and Technologies Used
2.3 Algorithmic Approach
CHAPTER 3: DESIGNING AND RESULT ANALYSIS 5
3.1 System Design
3.1.1 Block Diagram / Flowchart
3.1.2 Tools & Libraries Used
3.1.3 System Architecture
3.2 Implementation Details
3.3 Results and Observations
CHAPTER 4: MERITS, DEMERITS AND APPLICATIONS 8
4.1 Merits
4.2 Demerits
4.3 Applications
CHAPTER 5: CONCLUSIONS AND FUTURE SCOPE 10
5.1 Conclusion
5.2 Future Scope
RESEARCH PAPER 12
REFERENCES 13
iv
APPENDIX 14
List of Figures
Figure No. Title of Figure Page No.
1 Process Of “Motion 3
Detection System”
2 Working of Program 5
3 System Structure 6
v
List Of Tables
Table No. Title of Table Page No.
1 Tools and 4
Technologies Used
2 Results and 7
Observations
vi
vi
CHAPTER 1: INTRODUCTION AND LITERATURE
REVIEW
1.1 Introduction
Security and surveillance have become critical aspects of modern systems. Traditional
surveillance setups require constant manual monitoring, which is not only inefficient but
also prone to human error. With the advancement in computer vision and artificial
intelligence, it has become possible to design automated surveillance systems that detect
motion, capture evidence, and alert the concerned user instantly.
This project presents a real-time motion detection system using a webcam and OpenCV
in Python. It captures frames when movement is detected, saves the image, and sends it
via email automatically using multithreading to ensure performance and responsiveness.
1.2 Basic Terms and Concepts
This project is based on the integration of the following core components:
[1] OpenCV (Open Source Computer Vision Library): Used for real-time
computer vision tasks like video capture, grayscale conversion, image
differencing, thresholding, and contour detection.
Multithreading in Python: Allows multiple threads (email sending, folder
cleaning) to run concurrently for a responsive system.
Email Automation (smtplib and EmailMessage): Sends captured motion
frames as email attachments automatically.
Image Processing: Gaussian blur, thresholding, dilation, and contour detection
are applied to detect motion.
1.2.1 Motion Detection
Motion detection refers to the capability of a surveillance system to identify movement in
a scene using frame-by-frame comparison techniques.
1.2.2 Thresholding and Dilation
1
Thresholding simplifies images into binary format, while dilation connects broken
regions to form meaningful contours.
1.2.3 Contour Detection
Contours are used to detect the shape and size of moving objects, allowing the system to
focus only on significant changes (filtered by area).
1.3 Literature Overview
Several research efforts and open-source communities have explored motion detection:
Existing systems often use PIR sensors or high-end IP cameras.
Traditional CCTV lacks real-time alert mechanisms.
[5] OpenCV provides powerful tools for frame comparison and processing.
[7] Literature reveals the advantage of software-based surveillance due to
flexibility, cost-effectiveness, and ease of integration with alert systems.
[6] Projects like Raspberry Pi–based surveillance systems show hardware
compactness, but our approach emphasizes software simplicity and PC webcam
use.
1.4 Motivation
Need for automated, real-time security systems without expensive hardware.
Desire to reduce manual monitoring by building an intelligent, self-alerting
system.
Enhance awareness and reaction time during unauthorized intrusions.
Utilize existing open-source libraries to create an accessible and educational
project for AI/ML students.
To promote DIY and smart surveillance solutions that are easy to set up and use.
To enhance personal and property safety through timely detection and communication.
CHAPTER 2: METHODOLOGY ADOPTED
2
2.1 Overall Workflow of the System
[2] The motion detection and alert system follows a systematic flow from video capture
to motion detection and finally sending an email alert. The workflow involves several
stages, each responsible for a key task:
[10] Capture video frames using webcam.
Apply preprocessing (grayscale conversion and Gaussian blur).
Detect motion by comparing frame differences.
Draw contours around moving objects.
Capture image when motion is detected.
Send alert email using SMTP with the image attached.
2.1.1 Flowchart / Block Diagram
Fig.1 Process of “Motion Detection System”
2.2 Tools and Technologies Used
Technology Purpose
Python Programming language3 used
OpenCV For video processing and motion detection
Threading To perform email-sending tasks without freezing the video feed
SMTP (smtplib) Sending alert emails automatically
datetime To timestamp saved images
NumPy Image array manipulation
Email.mime Attaching captured image to the email
Table 1
2.3 Algorithmic Approach
The algorithm follows these steps:
1. Initialization:
Open video stream using OpenCV’s VideoCapture.
Initialize variables for the first frame and threading.
2. Preprocessing:
Convert each frame to grayscale.
Apply Gaussian Blur to reduce noise.
3. Motion Detection:
Subtract current frame from the baseline.
Apply thresholding and dilation to highlight motion.
Detect contours to localize motion.
4. [8] Trigger Alert:
If motion area exceeds a certain threshold, capture image.
Start a separate thread to send an email with the image.
4
CHAPTER 3: DESIGNING AND RESULT ANALYSIS
3.1 System Design
This flowchart illustrates the process of detecting motion using webcam input. Captured
frames are preprocessed (grayscale, blur), followed by thresholding and dilation.
Contours are detected to identify motion. If motion is found, the frame is saved and an
email alert is sent using multithreading. The system continuously loops for real-time
monitoring.
3.1.1 Block Diagram / Flowchart
5
3.1.2 Tools & Libraries Used
OpenCV – For computer vision operations like video capture, frame
processing, and motion detection.
[3] smtplib, EmailMessage, imghdr – For sending automated emails with
attachments.
Threading – To handle email sending and folder cleaning without
interrupting video capture.
Python – Main programming language.
Matplotlib (for flowchart) – Optional, for visualizing g.
[9] GitHub: version control
3.1.3 System Architecture
Frame Motion Image Email Alert
Webcam
Processing Detetction Capture System
Fig. 3 System Architecture
3.2 Implementation Details
Discuss each function/module:
Frame capture and preprocessing.
Motion detection using cv2.absdiff().
Frame saving.
Sending emails using smtplib.
Cleaning folder using os.remove() and glob.
6
3.3 Results and Observations
Mention how the system performed in different light conditions.
Note false positives/negatives.
Talk about the speed and efficiency.
Add screenshots of:
Terminal output logs.
GUI window showing motion detection.
Received email with image attachment.
Table 2
7
CHAPTER 4: MERITS, DEMERITS AND APPLICATIONS
4.1 Merits
Real-time Monitoring:
The system captures video and processes frames in real time, ensuring timely detection of
motion events.
Automation and Alerts:
Automatically sends an email with an attached image when motion is detected, reducing
the need for constant manual monitoring.
Simple Hardware Requirements:
Only a basic webcam is needed, making it cost-effective and easy to set up.
Multithreading:
Uses Python's threading to ensure email sending and image cleanup don’t block the video
stream.
Noise Filtering:
Ignores small movements (like shadows or light changes) by using a contour area
threshold.
Data Cleanup:
Automatically deletes saved images after the alert, ensuring storage isn't overwhelmed.
4.2 Demerits
Limited in Low Light: Detection accuracy may decrease significantly in dark
environments.
8
Single Camera Dependency: Works only with one camera; multiple angles require
modifications.
False Positives: Sudden light changes or reflections may trigger unwanted alerts.
No Object Classification: It detects motion but cannot differentiate between
humans, animals, or objects.
Dependent on Internet: Email alerting system won’t function without an active
internet connection.
4.3 Applications
Home Security: Can be used as a surveillance system to alert users about
intrusions when they are away.
Office/Shop Monitoring: Ideal for monitoring small commercial spaces during
non-working hours.
Student Projects & Learning: Perfect for understanding real-time computer
vision concepts and basic IoT integration.
Warehouse Surveillance: Helps in ensuring no unauthorized access happens in
storage facilities.
Attendance Trigger Systems: With modifications, it can be used to detect
motion at classroom entrances and log images.
9
CHAPTER 5: CONCLUSIONS AND FUTURE SCOPE
5.1 Conclusion
The motion detection project using OpenCV and real-time email alerting provides a
practical implementation of computer vision and multithreaded automation. Through
continuous webcam monitoring, the system successfully identifies motion by comparing
live video frames to a baseline and highlights the changes. When significant movement is
detected, a snapshot is taken and sent via email to the user for prompt awareness.
This project showcases how simple tools such as Python, OpenCV, and basic hardware
like a webcam can be combined to form an effective surveillance system. Its
implementation is modular, reliable, and aligns with fundamental AI-ML and automation
principles. Moreover, the integration of multithreading ensures a non-blocking, smooth
experience without interrupting real-time detection.
5.2 Future Scope
[4] Integration with Cloud Storage
Instead of just sending emails, detected images and logs can be stored on cloud platforms
like Firebase or AWS S3 for better record-keeping and analysis.
Mobile Notification System
Replace or supplement email alerts with real-time push notifications using services like
Firebase Cloud Messaging.
Object Recognition Enhancement
Future versions can include object classification using pre-trained deep learning models
to differentiate between humans, animals, and objects.
Night Vision or Infrared Support
10
Adding infrared camera compatibility can make the system useful in low-light or
nighttime conditions.
Web Dashboard Interface
Create a live monitoring interface using Django or Flask to visualize live feeds and
recorded motion events with timestamps.
Multiple Camera Support
Extend the codebase to support multiple webcams or IP cameras for broader coverage in
large spaces.
Elderly Care Monitoring:
Used to monitor movement in the homes of elderly individuals, ensuring safety and
sending alerts if unusual inactivity or falls are detected.
Smart Lighting Systems:
Integrated with smart homes to automatically switch lights on or off based on detected
motion, saving energy.
Pet Monitoring:
Allows pet owners to track pet activity or receive alerts when pets enter restricted areas.
Parking Lot Monitoring:
Detects vehicle or human movement in parking lots for improved security or vehicle
counting systems.
Traffic Monitoring:
Can be used to detect vehicle movement on roads and highways for data collection or
traffic flow management.
RESEARCH PAPER
11
12
REFERENCES
[1] Bradski, G. (2000). The OpenCV Library. Dr. Dobb's Journal of Software Tools.
[2] Rosebrock, A. (2015). Motion Detection with OpenCV. PyImageSearch.
https://pyimagesearch.com/2015/05/25/basic-motion-detection-and-tracking-with-
python-and-opencv/
[3] Python Software Foundation. (2023). smtplib – SMTP protocol client.
https://docs.python.org/3/library/smtplib.html
[4] Richardson, L. (2012). RESTful Web APIs. O’Reilly Media, Inc.
[5] OpenCV Documentation. (2024). Open Source Computer Vision Library.
https://docs.opencv.org/
[6] MIT Media Lab. (2019). Smart Surveillance Systems: Ethical and Technical
Considerations.
[7] Sharma, A., & Kumar, R. (2020). Real-Time Security Alert Systems using IoT and
Computer Vision. International Journal of Computer Applications, 176(34), 18–23.
[8] Albahar, M. A. (2021). Email Notification Systems: Design and Implementation in
Security Solutions. Journal of Information Systems Engineering, 12(2), 45–50.
[9] GitHub. (n.d.). Webcam Motion Detector Projects Repository.
https://github.com/topics/motion-detection
[10] Rouse, M. (2021). What is a Webcam? TechTarget.
https://www.techtarget.com/whatis/definition/webcam
13
APPENDIX
This appendix contains the full source code for the Motion Detection System with Email
Alert. It uses OpenCV for real-time motion detection and multithreading for sending alert
emails and cleaning saved image files.
1: main.py - Motion Detection and Email Trigger
import cv2
import time
import glob
import os
from email_sender import send_email
from threading import Thread
video = cv2.VideoCapture(0)
time.sleep(1)
first_frame = None
status_list = []
count = 1
def clean_folder():
print("cleaning folder started")
images = glob.glob("images/*.png")
if not images:
print("No .png files found in the folder")
else:
print(f"Found {len(images)} to delete.")
14
for image in images:
try:
time.sleep(0.02)
os.remove(image)
print(f"Deleted: {image}")
except Exception as e:
print(f"Error deleting {image} : {e}")
while True:
status = 0
check, frame = video.read()
if not check:
continue
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
gray_frame_gau = cv2.GaussianBlur(gray_frame, (21, 21), 0)
if first_frame is None or count % 100 == 0:
first_frame = gray_frame_gau
continue
delta_frame = cv2.absdiff(first_frame, gray_frame_gau)
thresh_frame = cv2.threshold(delta_frame, 60, 255, cv2.THRESH_BINARY)[1]
dil_frame = cv2.dilate(thresh_frame, None, iterations=2)
15
cv2.imshow("Motion Detection", dil_frame)
contours, _ = cv2.findContours(dil_frame, cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)
for contour in contours:
if cv2.contourArea(contour) < 3000:
continue
x, y, w, h = cv2.boundingRect(contour)
rectangle = cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 3)
status = 1
resized_frame = cv2.resize(frame, (640, 480))
cv2.imwrite(f"images/{count}.png", resized_frame)
count += 1
all_images = glob.glob("images/*.png")
image_with_object = None
if all_images:
index = int(len(all_images) / 2)
image_with_object = all_images[index]
status_list.append(status)
status_list = status_list[-2:]
print(status_list)
16
if len(status_list) >= 2 and status_list[0] == 1 and status_list[1] == 0:
if image_with_object:
email_thread = Thread(target=send_email, args=(image_with_object,))
email_thread.daemon = True
email_thread.start()
clean_thread = Thread(target=clean_folder)
clean_thread.daemon = True
clean_thread.start()
cv2.imshow("Video", frame)
key = cv2.waitKey(1)
if key == ord("q"):
break
video.release()
cv2.destroyAllWindows()
2: email_sender.py – Email Sending Function
import smtplib #provide tools to send emails using SIMPLE MAIL TRANSFER
#PROTOCOL(SMTP)
import mimetypes
from email.message import EmailMessage # provides esy way to contruct email messages
including attachments
17
PASSWORD="wcmg ckqp ovwx pcnf"
SENDER="kasaksaxena6@gmail.com"
RECIEVER="kassu6019@gmail.com"
def send_email(image_path):
print("email has sent")
email_message=EmailMessage()
email_message["Subject"]="New customer showed up!"
email_message.set_content("Hey, we just saw a new customer!")
# Determine The Mime Type and Subtype
mime_type,= mimetypes.guess_type(image_path)
if mime_type is None:
mime_type="application/octet-stream"
maintype,subtype=mime_type.split("/")
with open(image_path,"rb") as file :
content=file.read()
#maintype="image"- species that this is image attachment
#subtype=imghdr.what(None,content)- automatically detects img format
email_message.add_attachment(content,maintype=maintype,subtype=subtype)
gmail=smtplib.SMTP("smtp.gmail.com",587)
gmail.ehlo() # send EHLO(Extended Hello) Command to server
18
gmail.starttls()# upgrade the connection to a secure encrypted TLS connection
gmail.login(SENDER,PASSWORD)
gmail.sendmail(SENDER,RECIEVER,email_message.as_string())
gmail.quit()
print(" email end")
if _name=="main_":
send_email(image_path="images/19.png")
19