Skip to content

Real-time YOLO-based camera monitor for classrooms; sends alert to on native app if empty.

Notifications You must be signed in to change notification settings

ikeshav26/auto_detection_

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

10 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Auto Detection System

A comprehensive classroom monitoring system that uses computer vision to detect when fans are left running in empty classrooms and sends real-time notifications to administrators and staff.

๐Ÿ“‹ Overview

This system consists of three main components:

  1. Sensor Service (Python): Computer vision service using YOLOv8 for person detection
  2. Server (Node.js): RESTful API backend with MongoDB database
  3. Client (React Native): Mobile application for receiving and managing notifications

๐Ÿ—๏ธ System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Sensor Service  โ”‚  HTTP   โ”‚     Server      โ”‚  HTTP   โ”‚  Mobile Client  โ”‚
โ”‚   (Python)      โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถโ”‚   (Node.js)     โ”‚โ—€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚  (React Native) โ”‚
โ”‚  - YOLOv8       โ”‚         โ”‚  - Express      โ”‚         โ”‚  - Expo         โ”‚
โ”‚  - OpenCV       โ”‚         โ”‚  - MongoDB      โ”‚         โ”‚  - Axios        โ”‚
โ”‚  - Camera       โ”‚         โ”‚  - JWT Auth     โ”‚         โ”‚  - AsyncStorage โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ”‚                             โ”‚                            โ”‚
       โ”‚ Detects people              โ”‚ Stores data               โ”‚ Displays
       โ”‚ Sends snapshots            โ”‚ Manages users             โ”‚ notifications
       โ”‚                             โ”‚                            โ”‚

โœจ Features

Sensor Service

  • Real-time person detection using YOLOv8
  • Configurable alert delays
  • Automatic snapshot capture
  • Visual monitoring dashboard
  • Alert logging

Server

  • User authentication with JWT
  • Role-based access control (Admin/Staff)
  • Notification management API
  • MongoDB database integration
  • CORS-enabled for cross-origin requests

Client App

  • Separate user and admin dashboards
  • Real-time notification display
  • Snapshot image viewing
  • Mark as read/unread functionality
  • Delete notifications (admin only)
  • Auto-refresh every 10 seconds
  • Pull-to-refresh support

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.8+ (for sensor service)
  • Node.js 16+ (for server)
  • MongoDB 4.4+ (for database)
  • Expo CLI (for mobile client)
  • Webcam (for sensor service)

Installation

  1. Clone the repository:

    git clone https://github.com/ikeshav26/auto_detection_.git
    cd auto_detection_
  2. Setup Server:

    cd server
    npm install
    
    # Create .env file
    echo PORT=4000 > .env
    echo MONGODB_URI=mongodb://localhost:27017/auto_detection >> .env
    echo JWT_SECRET=your-secret-key >> .env
    
    npm run dev
  3. Setup Sensor Service:

    cd ../sensor_service
    pip install -r requirements.txt
    
    # Edit config.py if needed
    python main.py
  4. Setup Client:

    cd ../client
    npm install
    
    # Edit constants/config.js to set server URL
    npm start

๐Ÿ“ Project Structure

auto_detection_/
โ”œโ”€โ”€ client/                    # React Native mobile app
โ”‚   โ”œโ”€โ”€ app/                   # App screens (admin, auth, user)
โ”‚   โ”œโ”€โ”€ components/            # Reusable components
โ”‚   โ”œโ”€โ”€ constants/             # Configuration files
โ”‚   โ”œโ”€โ”€ context/               # React context
โ”‚   โ””โ”€โ”€ README.md
โ”œโ”€โ”€ server/                    # Node.js backend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ config/           # Database configuration
โ”‚   โ”‚   โ”œโ”€โ”€ models/           # MongoDB models
โ”‚   โ”‚   โ”œโ”€โ”€ controller/       # Business logic
โ”‚   โ”‚   โ”œโ”€โ”€ routes/           # API routes
โ”‚   โ”‚   โ””โ”€โ”€ middlewares/      # Auth middleware
โ”‚   โ”œโ”€โ”€ index.js              # Server entry point
โ”‚   โ””โ”€โ”€ README.md
โ”œโ”€โ”€ sensor_service/            # Python vision service
โ”‚   โ”œโ”€โ”€ main.py               # Main detection script
โ”‚   โ”œโ”€โ”€ config.py             # Configuration
โ”‚   โ”œโ”€โ”€ telegram_alert.py     # Notification sender
โ”‚   โ”œโ”€โ”€ logs/                 # Alert logs
โ”‚   โ”œโ”€โ”€ snapshots/            # Captured images
โ”‚   โ””โ”€โ”€ README.md
โ””โ”€โ”€ README.md                  # This file

๐Ÿ”ง Configuration

Server (.env)

PORT=4000
MONGODB_URI=mongodb://localhost:27017/auto_detection
JWT_SECRET=your-super-secret-key
NODE_ENV=development

Sensor Service (config.py)

SERVER_URL = "http://localhost:4000/api/notifications/create"
ALERT_DELAY = 600  # 10 minutes
FAN_STATUS = True
SNAPSHOT_DIR = "snapshots"
LOG_FILE = "logs/logfile.log"

Client (constants/config.js)

export const API_URI = "http://localhost:4000/api"

๐Ÿ“ก API Endpoints

Authentication

  • POST /api/user/signup - Register new user
  • POST /api/user/login - User login
  • POST /api/admin/register - Register user (admin only)

Notifications

  • POST /api/notifications/create - Create notification
  • GET /api/notifications - Get all notifications
  • GET /api/notifications/unread - Get unread notifications
  • PATCH /api/notifications/:id/read - Mark as read
  • PATCH /api/notifications/read-all - Mark all as read
  • DELETE /api/notifications/:id - Delete notification
  • DELETE /api/notifications - Delete all notifications

๐Ÿ”„ Workflow

  1. Detection: Sensor service monitors classroom via webcam
  2. Analysis: YOLOv8 detects number of people in frame
  3. Alert Trigger: If room empty + fan ON for configured time
  4. Notification: Snapshot sent to server with metadata
  5. Storage: Server stores in MongoDB
  6. Display: Client polls server and displays notifications
  7. Action: User marks as read or admin deletes

๐Ÿ› ๏ธ Development

Running in Development

# Terminal 1 - Start MongoDB
mongod

# Terminal 2 - Start Server
cd server
npm run dev

# Terminal 3 - Start Sensor Service
cd sensor_service
python main.py

# Terminal 4 - Start Client
cd client
npm start

Testing

Test Server:

curl http://localhost:4000/
# Expected: Hello, World!

Test Sensor Service:

  • Ensure camera is connected
  • Press 'q' to quit
  • Check logs/logfile.log for events

Test Client:

  • Scan QR code with Expo Go app
  • Login with test credentials
  • Navigate to notifications screen

๐Ÿ› Troubleshooting

Common Issues

MongoDB Connection Failed:

# Start MongoDB service
# Windows: mongod
# macOS: brew services start mongodb-community
# Linux: sudo systemctl start mongod

Camera Not Detected:

  • Check camera permissions
  • Try different camera index in main.py
  • Ensure no other app is using camera

Client Can't Connect to Server:

  • Check server is running on port 4000
  • Update API_URI in client config
  • For physical devices, use computer's IP instead of localhost
  • Check firewall settings

Notifications Not Appearing:

  • Verify server is running
  • Check MongoDB is connected
  • Ensure sensor service is sending to correct URL
  • Check network connectivity

๐Ÿ“Š Monitoring

View Logs

# Server logs
cd server
tail -f logs/server.log  # if logging configured

# Sensor service logs
cd sensor_service
cat logs/logfile.log

View Snapshots

cd sensor_service/snapshots
ls -lt  # View latest snapshots

๐Ÿš€ Deployment

Server Deployment (Heroku/Railway)

  1. Set environment variables
  2. Connect to MongoDB Atlas
  3. Deploy from Git repository

Client Deployment

Build for production:

cd client
# Android
expo build:android

# iOS
expo build:ios

# Or use EAS Build
eas build --platform all

Sensor Service Deployment

Run as system service on local machine or edge device.

๐Ÿ” Security

  • JWT authentication for API access
  • Password hashing with bcrypt
  • Role-based access control
  • CORS configuration for production
  • Environment variables for secrets

๐Ÿ“ License

This project is licensed under the MIT License.

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ‘ฅ Authors

๐Ÿ†˜ Support

For support, email or open an issue in the repository.

๐Ÿ”ฎ Future Enhancements

  • WebSocket for real-time notifications
  • Push notifications on mobile
  • Cloud storage for snapshots (AWS S3)
  • IoT integration for actual fan control
  • Analytics dashboard
  • Email notifications
  • Multiple camera support
  • Dark mode in client app
  • Notification search and filters
  • Export reports

๐Ÿ“š Documentation

๐Ÿ™ Acknowledgments

  • YOLOv8 by Ultralytics
  • Expo for React Native framework
  • OpenCV community
  • MongoDB and Express.js teams

About

Real-time YOLO-based camera monitor for classrooms; sends alert to on native app if empty.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages