AI-Driven CCTV Monitoring System

 AI-Driven CCTV Monitoring System 

1. Introduction

The AI-Driven CCTV Monitoring System uses computer vision and machine learning to monitor live CCTV footage and alert users about suspicious activities. This system improves security by detecting anomalies or predefined events in real-time and can be deployed in homes, offices, or public spaces.

2. Prerequisites

• Python: Install Python 3.x from the official Python website.
• Required Libraries:
  - opencv-python: Install using pip install opencv-python
  - tensorflow/keras: Install using pip install tensorflow
  - numpy: Install using pip install numpy
  - imutils: Install using pip install imutils
• Pre-trained model: A trained deep learning model to identify specific activities.
• CCTV or webcam feed for testing.

3. Project Setup

1. Create a Project Directory:

- Name your project folder, e.g., `AI_CCTV_Monitoring`.
- Inside this folder, create the Python script file (`cctv_monitoring.py`).

2. Install Required Libraries:

Ensure OpenCV, TensorFlow, and other dependencies are installed using `pip`.

4. Writing the Code

Below is an example code snippet for the AI-Driven CCTV Monitoring System:


import cv2
import numpy as np
from tensorflow.keras.models import load_model

# Load pre-trained model
model = load_model('activity_model.h5')

# Load label names
labels = ['Normal', 'Suspicious Activity']

# Function to preprocess frame
def preprocess_frame(frame):
    frame = cv2.resize(frame, (224, 224))
    frame = np.expand_dims(frame, axis=0)
    frame = frame / 255.0
    return frame

# Function to predict activity
def predict_activity(frame):
    processed_frame = preprocess_frame(frame)
    prediction = model.predict(processed_frame)
    return labels[np.argmax(prediction)]

# Main function for monitoring
def main():
    cap = cv2.VideoCapture(0)  # Replace 0 with the CCTV feed URL if applicable

    while True:
        ret, frame = cap.read()
        if not ret:
            break

        prediction = predict_activity(frame)
        cv2.putText(frame, f"Activity: {prediction}", (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
        cv2.imshow('AI CCTV Monitoring', frame)

        if prediction == "Suspicious Activity":
            print("Alert: Suspicious activity detected!")

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    cap.release()
    cv2.destroyAllWindows()

if __name__ == "__main__":
    main()
   

5. Key Components

• Video Stream Input: Captures video frames from a CCTV or webcam feed.
• Activity Detection: Uses a deep learning model to classify each frame.
• Real-Time Alerts: Prints alerts and overlays information on the video feed.

6. Testing

1. Ensure the trained model (`activity_model.h5`) is available in the project directory.

2. Run the script:

   python cctv_monitoring.py

3. Test the system with normal and simulated suspicious activities.

7. Enhancements

• Expand Activity Classes: Train the model with additional activity types.
• Integrate Notifications: Send alerts via email or SMS for real-time responses.
• Multi-Camera Support: Extend the system to handle multiple camera feeds.

8. Troubleshooting

• Detection Issues: Retrain the model with more diverse data.
• Performance Lag: Use hardware acceleration like GPUs or optimize model inference.
• Video Stream Errors: Verify the CCTV feed or webcam connection.

9. Conclusion

The AI-Driven CCTV Monitoring System enhances security by detecting and alerting users about suspicious activities in real-time. It is a powerful tool for automated surveillance and can be scaled for various environments.