weapon-detection / README.md
ishworrsubedii's picture
Update README.md
c94e8f4 verified

A newer version of the Streamlit SDK is available: 1.41.1

Upgrade
metadata
license: apache-2.0
title: Weapon Detection
sdk: streamlit
emoji: 🐒
colorFrom: green
colorTo: green

weapon-detection-alert-location-share

This project focuses on enhancing the security of different places, like public areas and banks, by implementing a robust gun detection and alert system. The system is designed to capture images from an IP camera strategically placed. within the bank's premises. When a captured image contains an identifiable gun, the system takes appropriate actions, such as playing alerts or sharing the location of the detected weapons, including knife and guns.

  1. Image Capture:

    Utilizes an IP camera to continuously capture images in real-time within the camera range. Images are processed and analyzed for potential gun presence.

  2. Gun Detection:

    Employs advanced computer vision algorithms for accurate gun detection in captured images. The system recognizes various types of firearms and distinguishes them from other objects.

  3. Alert Systems:

    When a gun is detected, the system triggers immediate alerts. Alerts can be configured to notify security personnel, law enforcement, and relevant authorities.

πŸš€ Technologies

  • Python
  • FastAPI
  • Streamlit
  • YOLO
  • OpenCV
  • Docker

File Structure

File structure of the project

.
β”œβ”€β”€ config
β”‚   └── config.ini
β”œβ”€β”€ images
β”‚   └── cam_images
β”‚       └── th-3711382641.jpg
β”œβ”€β”€ logs
β”‚   β”œβ”€β”€ gun_det.log
β”‚   └── ipcam.log
β”œβ”€β”€ resources
β”‚   β”œβ”€β”€ alert
β”‚   β”‚   └── alert.mp3
β”‚   β”œβ”€β”€ flag_load_image
β”‚   β”œβ”€β”€ image_capturing
β”‚   └── models
β”‚       β”œβ”€β”€ best.pt
β”‚       β”œβ”€β”€ v1
β”‚       β”‚   └── best.pt
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ api
β”‚   β”‚   β”œβ”€β”€ fast_api.py
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ services
β”‚   β”‚   β”œβ”€β”€ alert_service
β”‚   β”‚   β”‚   β”œβ”€β”€ alert_service.py
β”‚   β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”‚   └── __pycache__
β”‚   β”‚   β”œβ”€β”€ entity
β”‚   β”‚   β”‚   β”œβ”€β”€ entity_config.py
β”‚   β”‚   β”‚   └── __init__.py
β”‚   β”‚   β”œβ”€β”€ image_capture_service
β”‚   β”‚   β”‚   β”œβ”€β”€ capture_main.py
β”‚   β”‚   β”‚   β”œβ”€β”€ image_load_main.py
β”‚   β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   β”œβ”€β”€ __init__.py
β”‚   β”‚   └── weapon_det_service
β”‚   β”‚       β”œβ”€β”€ __init__.py
β”‚   β”‚       └── weapon_detection_service.py
β”‚   └── utils
β”‚       β”œβ”€β”€ __init__.py
β”‚       β”œβ”€β”€ __pycache__
β”‚       └── settings.py
β”œβ”€β”€ demos
β”‚   β”œβ”€β”€ alert_service_example.py
β”‚   β”œβ”€β”€ cam_service_example
β”‚   β”‚   β”œβ”€β”€ start_frame_capturing.py
β”‚   β”‚   └── stop_frame_capturing.py
β”‚   β”œβ”€β”€ image_load_service_example
β”‚   β”‚   β”œβ”€β”€ start_image_load_example.py
β”‚   β”‚   └── stop_image_load_example.py
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── single_image_inference.py
β”œβ”€β”€ Dockerfiles
β”œβ”€β”€ app.py
β”œβ”€β”€ main.py
β”œβ”€β”€ README.md
β”œβ”€β”€ requirements.txt
└── streamlit_app.py

How to Run

  1. Clone the repository:

    git clone https://github.com/ishworrsubedii/gun-detection-alert.git
    cd cd gun-detection
    
  2. Create and activate the Conda environment:

    conda create -n weapon-detection python=3.10 -y
    conda activate gun-detection
    
  3. Install required packages:

    pip install -r requirements.txt
    
  4. Perform Inference/Prediction:

    streamlit run streamlit_app.py
    
    • We have to run both programs for inference. py for fastapi post request and streamlit for UI for the prediction.
  5. Perform Single Image Inference:

    streamlit run app.py
    

Docker

docker build -t myapp .

Then run the docker container

docker myapp

πŸ”₯Features

  • Real-time Gun Detection: The system can detect guns in real-time images captured by an IP camera.
  • Alert System: The system can send alerts to security personnel and law enforcement when a gun is detected.

⚠️ Limitations

  • The system may not be able to detect guns in low-light conditions or when the weapon is partially obscured.
  • Accuracy may vary based on the quality of the images captured by the IP camera.

Future Work

  • One of the future work is to train the model on diverse datasets to improve the model's performance and accuracy.
  • Implement and test the system in real-world scenarios using raspberry pi or other edge devices.
  • Develop a feature to share the location of detected with the authorities.

Demo

For single image inference i have used huggingface here you can try it out here

img.png

Recommendations

Your recommendations are highly valuable, and I highly value your insights and suggestions to enhance this project! Feel free to propose new features, report bugs, or suggest improvements.

Contributors

Contributions are always welcome! If you'd like to contribute to this project or have any suggestions, please feel free to reach out or submit a pull request.