AI-Powered Surveillance Camera System
by Orange Digital Center in Circuits > Wireless
41 Views, 0 Favorites, 0 Comments
AI-Powered Surveillance Camera System


This project was developed within the Orange Digital Center Morocco , a space dedicated to fostering innovation, creativity, and rapid prototyping. At the FabLab, individuals and teams have access to state-of-the-art tools, including 3D printers, laser cutters, and a variety of electronic and mechanical resources. The center provides a collaborative environment where innovators, entrepreneurs, and students can transform their ideas into tangible products. By focusing on sustainable and impactful solutions .
This project utilizes a Raspberry Pi along with a camera module to create an AI-powered surveillance system capable of real-time face recognition, object detection, and tracking. The system also features an attendance tracker and the ability to monitor people as they enter and exit a monitored space.
Features:
- Real-time video feed with streaming capabilities.
- Face recognition for attendance tracking.
- Object detection and people tracking.
- Data storage in a local database (SQLite).
- Web interface for live video streaming and data visualization.
Supplies

.png)
Materials Needed :
- Raspberry Pi 4 (or any Raspberry Pi with camera module support)
- Raspberry pi camera module V2
- MicroSD card (8GB or higher) for the Raspberry Pi OS
- External storage (optional, for saving data)
Setting Up Raspberry Pi 4

In this step, we will set up the Raspberry Pi, install the necessary software, for your AI-Powered Surveillance System.
Preparing the Raspberry Pi
Before we begin, make sure you have the following materials:
Raspberry Pi 4 model B (Recommended)
Raspberry Pi Camera Module (or any compatible camera module)
MicroSD card (at least 32GB) with Raspberry Pi OS installed
Power supply for Raspberry Pi
HDMI cable and monitor (for initial setup)
Keyboard and mouse (for setup)
Note : To format the SDCard if needed :
Win + R, ‘cmd’ then OK
Download the Raspberry Pi OS 64bit (Legacy) bullseye from the official website.
Use a tool like Raspberry Pi Imager or balenaEtcher to flash the image to your microSD card.
Once the image is flashed, insert the SD card into the Raspberry Pi and power it up.
Follow the on-screen instructions to set up the language, timezone, Wi-Fi connection and enable the ssh protocole.
This is a complete guide to install the raspberry pi OS :
Connecting and Configuring the Camera

Connecting the Camera Module
In this step, we will set up and configure the camera module for your AI-Powered Surveillance System using vnc viewer or just a monitor to connect to the raspberry pi's interface.
This is the complete guide of how to use vnc viewer :
https://www.youtube.com/watch?v=carRkTXv_8c
Connect the Camera to the Raspberry Pi:
Locate the Camera Serial Interface (CSI) port on the Raspberry Pi. It's usually near the edge of the board.
Carefully insert the ribbon cable from the camera into the CSI port, ensuring the blue side of the ribbon faces the Ethernet port.
Enable Camera Support:
Once Raspberry Pi OS is running, open a terminal window and enter the following command to enable camera support:
- In the configuration menu, navigate to Interface Options, then select Camera and enable it.
- Reboot your Raspberry Pi to apply the changes.
Test the Camera:
After rebooting, test the camera by running the following command in the terminal:
- This will capture a still image and save it as test.jpg in your current directory. If the camera is working, you should see the image saved.
Setting Up Python Environment
1.3 Setting Up the Python Environment
For your AI-powered surveillance system, you will need to install a few libraries and packages. These include OpenCV for video processing, Flask for the web application, and SQLAlchemy for database management.
Install Python 3.8
This project was implemented using Python 3.8. Ensure that the correct version of Python is installed.
Update the system packages:
Install Python 3.8 (if not already installed):
Set Python 3.8 as the default version:
Verify the Python version:
Create a Virtual Environment (Optional but Recommended)
For a clean environment, it’s recommended to use a virtual environment.
Install the venv module if it's not already installed:
Create a virtual environment (replace env_name with the name you want for the environment):
Activate the virtual environment:
Update Package Managers
Once the virtual environment is active, update the package managers (pip, setuptools, and wheel):
Update pip to the latest version:
Update setuptools and wheel:
Install Dependencies
Install the required Python packages for your project. These packages include Flask, SQLAlchemy, face-recognition, and others necessary for object detection, face recognition, and video processing.
Install the dependencies:
This will install the following dependencies:
- Flask: A lightweight WSGI web application framework.
- Flask-SQLAlchemy: An extension for Flask that adds support for SQLAlchemy (used for database management).
- face-recognition: A library for facial recognition.
- ultralytics: For advanced object detection.
- supervision: A package for task management.
- imutils: A collection of utility functions for computer vision.
Face Recognition System Overview
This module allows capturing face images, training a recognition model, and identifying faces in video frames. It also tracks attendance and manages unknown faces.
What It Does ?
- Detects faces in real-time video feed.
- Recognizes known faces for logs attendance (next step).
- Manages unknown faces, assigning temporary IDs.
How It Works ?
- Database: Uses SQLite to store face encodings, names, and attendance data.
- Face Detection: Identifies faces, compares them to the trained database, and records the attendance.
Example Usage:
Note : This is the link to the github repository where you can find the complete code : https://github.com/marwanazd/SmartSurveillanceSystem/tree/main/modules
Attendance Monitoring Module Overview
What It Does ?
- Records attendance using face recognition.
- Retrieves attendance records (e.g., today, week, all time).
- Exports records to CSV, Excel, or JSON.
- Stores data in a SQLite database.
How It Works ?
- Database: Uses SQLAlchemy to manage attendance data (name, timestamp, face image).
- Recording: Ensures no duplicate attendance for the same person on the same day.
- Retrieving: Filters records by time period or custom date range.
- Exporting: Saves records in your chosen format and stores them in the uploads folder.
Example Usage
Initialize:
Record Attendance:
Get Records:
Export Records:
Note : This is the link to the github repository where you can find the complete code : https://github.com/marwanazd/SmartSurveillanceSystem/tree/main/modules
Social Distancing and People Movement Monitoring System
What It Does ?
This script provides a framework for tracking people in a monitored space, measuring social distancing, and counting how many people enter or exit the space. It uses YOLOv8 for object detection, ByteTrack for multi-object tracking, and Supervision for bounding box and label annotations. The system records person movements and interactions with defined boundaries (e.g., doors, lines) to monitor people flow.
How It's Built ?
- YOLO model: Utilized for object detection (people in this case). This model is loaded using the ultralytics package, and the detections are processed and tracked.
- ByteTrack: Used for tracking objects across frames. This ensures consistent IDs for people moving through the frame.
- Supervision: A package that helps with visualizing detections and tracking information, including bounding boxes and labels on frames.
- SQLAlchemy: Used for database management to store tracking information.
- OpenCV: Used for drawing bounding boxes, center points, lines, and labels on frames, as well as capturing and saving images of detected persons.
Example Usage:
Note : This is the link to the github repository where you can find the complete code : https://github.com/marwanazd/SmartSurveillanceSystem/tree/main/modules
Security Object Detection System
What It Does ?
This Security Object Detection System is designed to identify and track non-desired items within a monitored space, such as in a laboratory or workplace. The system uses a pre-trained YOLO (You Only Look Once) model to detect various objects (like food, smoke, violence, coffee cups, soda cans, bicycles, etc.) from a video feed captured via a camera module connected to a Raspberry Pi. Detected objects are processed and stored in an SQL database, including an image of the detected object encoded in base64 format, along with the timestamp of the detection.
How It's Built ?
Object Detection:
- The system uses a YOLO model to detect objects from video frames.
- The model provides bounding box coordinates and class IDs for each detected object.
- It excludes the detection of 'person' objects (to focus on non-desired items).
- Detected objects are captured in their bounding box and stored as base64-encoded images for efficient database storage.
Database Integration:
- The system uses SQLAlchemy to manage a database, where it stores details about each detected object (including the object’s class ID, label, timestamp, and image encodes it into base64).
- Detected objects are stored in an SQLite database, providing a historical record of all the objects detected by the system.
Real-Time and Historical Usage:
The system can detect objects in real-time via video feed.
It also allows querying historical data from the database, allowing the user to review previous detections.
Example Usage
Model Setup and Initialization:
Detecting Non-Desired Objects:
Saving Detected Objects to Database:
Note : This is the link to the github repository where you can find the complete code : https://github.com/marwanazd/SmartSurveillanceSystem/tree/main/modules
Web Interface


This web app is a robust surveillance solution that uses the Raspberry Pi, camera module, and several advanced computer vision models to monitor and track activities in a space. It provides real-time video streaming, attendance tracking, object detection, and people counting with a user-friendly web interface for managing and viewing the data. The use of Flask ensures that the system can be easily accessed via a web browser, and the multi-threading setup ensures smooth video processing without interruption.
Dashboard (Home Page)
The Home page of the AI-Powered Surveillance System dashboard provides an intuitive interface for monitoring real-time data. It features a live camera feed along with key metadata like frame rate, resolution, and uptime. The dashboard also displays important statistics such as the number of people detected, event logs, and storage usage, offering a comprehensive overview of the FabLab’s activity. With automatic updates and a clean, responsive layout, the page ensures easy access to crucial information for security and system management.
Attendace Dashboard
This page serves as the main dashboard for managing and viewing attendance records. Users can filter records by specific time periods such as today, yesterday, or a custom date range. The page allows for easy downloading of records in multiple formats (CSV, XLSX, JSON) and provides a simple form for adding new people by uploading their images for face recognition. Attendance data is displayed in a dynamic table that updates every 5 seconds, showing the ID, name, timestamp, and face image of each person detected.
Settings Page
This will allow users to configure options for different modules like Object Detection, Face Recognition, Distance Monitoring, and Attendance System.
Note : This is the link to the github repository where you can the templates code :
https://github.com/marwanazd/SmartSurveillanceSystem/tree/main/templates
Surveillance Camera 3D Model










To ensure a smooth printing experience, I'll be clear and concise with these steps. I've placed images at the top bar. The instructions and filenames are listed in the same order here. While printing in this sequence is not required, I printed the V1_AV_CAM_Bottom.stl first, followed by the V1_AV_CAM_Mount.stl, which helped me place the electronics early on. Most parts don’t require support, but they’re easy to clean if you follow the guidelines below. Thanks for following my Instructable!
Lens_Mount.stl
Print with 20% infill and the holder with 50%.
Assembling the 3D Printed Parts














Assembling the camera is straightforward, with most steps being self-explanatory from the pictures and rendering. Here are a few tips:
After printing, you may need to ream out the screw holes using a 1/8 inch or 2.5mm drill bit. You may also need to remove material from supports and trim the brim. Clean the edges with a needle file, as needed.
- First, mount the Raspberry Pi and attach the camera to it.
- Secure the camera in the mount by placing the board in the back. A small amount of hot glue in each corner will help hold it in place. The two screw holes at the front of the mount fit into the sides of the camera mount.
- Once the electronics are in place, insert the 38mm acrylic lens in front of the camera mount, and secure the lens with four M3 screws.
- Route the power cord through the bottom channel of the Raspberry Pi mount and plug it into the Raspberry Pi (without powering it on yet).
- Leave the top and back off for now, as you'll need to flash the image and set up the Raspberry Pi.
- Attach the base mount to the bottom of the camera with four M3 screws, then attach the mount post with the M4 screw.
- Finally, attach the wall mount to the base post using an M3 x 20mm screw to complete the camera assembly.
After this, you'll mount the camera once the software is ready.
Executing the Surveillance System Code

In this step, we will deploy and run the AI-powered surveillance system software on our Raspberry Pi with the camera module. The program is designed to detect objects, track movement, and analyze video feeds for security purposes. Once the setup is complete, your system will begin monitoring the environment autonomously, processing video in real-time and storing results in a database.
Commands to clone code from github :
Commands to run the script :