Categories
Uncategorized

“Smart Intruder Detection: IoT-Enabled Face Recognition System”

With increasing concerns about home safety, many traditional security systems lack intelligent monitoring capabilities. This project addresses the need for real-time intruder detection by integrating face recognition with IoT technology, ensuring timely alerts while minimizing false alarms. By enhancing security measures, it aims to provide homeowners with peace of mind.

Things used in this project:

Hardware components :

  • Bolt Wifi Module X 1
  • PIR Sensor HC-SR501 X 1
  • Jumper wires
  • Webcam

Software and Online services :

  • Bolt Cloud
  • Twilio

Hardware Setup :

  • Step 1: Identify the PIR Sensor Pins: VCC for power input, OUT for digital output, and GND for ground.
  • Step 2: Connect the VCC of the PIR Sensor to the 5V Pin on the Bolt IoT Module. Connect the OUT Pin of the PIR Sensor to the GPIO 0 Pin on the Bolt IoT Module. Connect the GND of the PIR Sensor to the GND Pin on the Bolt IoT Module.
  • Step 3: Connect the Bolt IoT module to a power source via a micro-USB cable to power both the module and the PIR sensor.
  • Step 4: Connect the Bolt IoT module to your Wi-Fi network using the Bolt Cloud app.

Step 5: Set Up and Connect the Camera:

  • Connect a Camera (like a webcam) to the device where your Python script will run. This device will handle capturing and processing the video feed for face recognition.

Software Programming :

  • Step 1: Set up your development environment in your preferred IDE. Create a requirements.txt file with the following libraries and their versions. Install the necessary libraries by running the following command in your terminal : pip install -r requirements.txt
  • Step 2: Create a directory named photo in your project folder. Add images of known faces to this directory for face recognition
  • Step 3: Create a configuration file named conf.py to store your credentials for Bolt IoT and Twilio. Your conf.py file should look like this:
  • Step 4: Access the main code from GitHub repository, which includes the complete implementation for intruder detection and SMS alerts.

GitHub URL: https://gist.github.com/SNP58/23cc3a6d4a271289cd73a43eda58308b

  • Step 5: Test the system by running the code with known and unknown faces. Adjust the confidence threshold as needed to improve accuracy.
  • Step 6: Deploy the system in your desired location. Regularly monitor logs and SMS alerts to ensure the system is functioning correctly.

Code explanation:

Libraries and Setup:

  • Key libraries such as face_recognition (for facial detection), cv2 (OpenCV for handling image and video processing), numpy (for numerical operations), and Bolt IoT APIs for interacting with sensors and sending SMS are imported.
  • The system initializes with the Bolt IoT module, which is used to read sensor values (e.g., motion sensor) and trigger the camera to start capturing.

Loading and Encoding Faces:

  • Images from a directory called photo are loaded, and each image’s face is encoded using the face_recognition library. These face encodings serve as the reference for identifying people.
  • The findEncoding() function processes each image by converting it to RGB and generating an encoding (a unique numerical representation of the face). It skips images where no face is found.

Marking Recognized Faces:

  • The markNT() function logs the recognized faces into a CSV file. It also keeps track of when a face was last logged to avoid repetitive entries for the same face within a set time interval.
  • If a known face is detected, it is logged with the current timestamp. Unknown faces trigger an “Intruder Alert” SMS if seen multiple times consecutively.

Face Recognition Logic:

  • In the main loop, the system reads the sensor value from the Bolt IoT module. If the sensor detects activity, the camera is activated for 20 seconds.
  • During this time, the system captures video frames, detects faces in each frame, and encodes them.
  • Each face encoding is compared to the preloaded known faces using compare_faces(), and the closest match is determined using face_distance(). If a face matches a known individual and is within the set confidence threshold, it is recognized and labeled accordingly.

Logging Unknown Faces:

  • For faces that are not recognized, the system increases a counter (consecutive_unknown_count). If an unknown face persists for multiple consecutive frames, it is logged and an SMS alert is sent, notifying the user of potential intruders.

Displaying Results:

  • Bounding boxes and names (either the recognized person or ‘Unknown’) are drawn around detected faces on the video feed using cv2.rectangle() and cv2.putText(), making it easy to identify who was detected.

Handling the Video Feed:

  • The system continuously processes frames from the camera until the sensor stops detecting activity. Afterward, the camera and all OpenCV windows are safely closed.

Output Photos:

No Motion Detected

In this state, the motion sensor reads 0, indicating no activity. The camera remains off, and no face recognition is happening.

Motion Detected – Known Person

When motion is detected (1), the camera activates and recognizes a known person. No alerts are triggered, and the system logs the recognized individual.

Motion Detected – Unknown Person

Motion is detected, and the camera identifies an unknown person. This triggers an alert, possibly sending an SMS notification, and logs the unknown face in the system.

Intruder Detected Message

An intruder alert message is sent when an unknown face is detected for a certain number of frames, indicating a potential threat.

CSV Log Records

This shows the log of detected faces, including both known and unknown individuals, with timestamps for each recognition event.

Conclusion

This project demonstrates a smart intruder detection system that combines face recognition technology with IoT integration. Utilizing the Bolt IoT module and Twilio for SMS alerts, the system enhances home security by providing real-time notifications and minimizing false alarms. Overall, it effectively addresses security concerns, offering users peace of mind and showcasing the potential of modern technology in enhancing safety. Future improvements could focus on optimizing recognition accuracy and expanding functionality.