File size: 5,516 Bytes
c94e8f4
 
234f597
c94e8f4
234f597
 
c94e8f4
 
 
 
 
 
234f597
c640bc9
066c36c
 
 
c640bc9
 
 
066c36c
c640bc9
 
 
 
 
 
066c36c
c640bc9
 
 
 
 
066c36c
c640bc9
066c36c
 
 
 
 
 
c640bc9
066c36c
c640bc9
066c36c
c640bc9
066c36c
 
c640bc9
066c36c
c640bc9
066c36c
 
c640bc9
066c36c
 
c640bc9
066c36c
 
 
 
c640bc9
066c36c
 
 
 
 
 
c640bc9
 
066c36c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c640bc9
066c36c
c640bc9
066c36c
c640bc9
 
 
066c36c
c640bc9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
066c36c
 
 
 
c640bc9
 
 
 
066c36c
 
 
 
 
 
 
c640bc9
 
 
 
066c36c
 
 
c640bc9
 
066c36c
 
 
c640bc9
 
066c36c
 
 
 
c640bc9
 
066c36c
 
 
 
 
c640bc9
 
 
066c36c
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
---
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

```angular2html
.
β”œβ”€β”€ 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:**
    ```bash
    git clone https://github.com/ishworrsubedii/gun-detection-alert.git
    cd cd gun-detection
    ```

2. **Create and activate the Conda environment:**
    ```bash
    conda create -n weapon-detection python=3.10 -y
    conda activate gun-detection
    ```

3. **Install required packages:**
    ```bash
    pip install -r requirements.txt
    ```

4. **Perform Inference/Prediction:**
    ```bash
    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:**
    ```bash
    streamlit run app.py
    ```

### Docker

```commandline
docker build -t myapp .
```

Then run the docker container

```commandline
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](https://huggingface.co/spaces/ishworrsubedii/weapon-detection)

![img.png](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.