├── .idea ├── .gitignore ├── .name ├── CS 591 - 3rd Year Project (Anirban Laxman).iml ├── inspectionProfiles │ └── profiles_settings.xml ├── misc.xml ├── modules.xml └── vcs.xml ├── Crowd_Report.pdf ├── Images ├── Crowd_Report.docx ├── Crowd_Report.png ├── IMG.jpg ├── Screenshot_20210918-145120_Chrome.jpg ├── Screenshot_20210918-145240_Chrome.jpg ├── Screenshot_20210918-145710_Chrome.jpg ├── Template Image.jpg ├── f1.jpg ├── f2.jpg ├── front1.png ├── front2.png ├── icon.ico ├── icon.jpg ├── image1.jpg ├── image2.png ├── image3.jpg ├── img1.jpg ├── img2.jpg ├── img3.jpg ├── pdf_logo.png └── pdf_logo_down.png ├── LICENSE ├── PPT + Report ├── Final PPT.ppt ├── Final Report.docx ├── Final Report.pdf ├── JETIR2205586.pdf ├── JETIR2205586_Certificate.pdf ├── Project_proposal.docx ├── Project_proposal.pdf └── Weekly Update.ppt ├── README.md ├── Sample Images and Videos ├── Screenshot_20210918-145120_Chrome.jpg ├── Screenshot_20210918-145240_Chrome.jpg ├── Screenshot_20210918-145710_Chrome.jpg ├── img1.jpg ├── img2.jpg ├── img3.jpg ├── vid.webm ├── vid1.mp4 ├── vid2.mp4 ├── vid3.mp4 ├── vid4.mp4 └── vid5.mp4 ├── Screenshots ├── 1.jpg ├── 10.jpg ├── 11.jpg ├── 12.jpg ├── 13.jpg ├── 14.jpg ├── 15.jpg ├── 16.jpg ├── 17.jpg ├── 18.jpg ├── 19.jpg ├── 2.jpg ├── 20.jpg ├── 21.jpg ├── 22.jpg ├── 23.jpg ├── 3.jpg ├── 4.jpg ├── 5.jpg ├── 6.jpg ├── 7.jpg ├── 8.jpg └── 9.jpg ├── __pycache__ ├── persondetection.cpython-310.pyc ├── persondetection.cpython-311.pyc ├── persondetection.cpython-38.pyc └── persondetection.cpython-39.pyc ├── frozen_inference_graph.pb ├── haarcascade_fullbody.xml ├── main.py ├── persondetection.py └── requirements.txt /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | main.py -------------------------------------------------------------------------------- /.idea/CS 591 - 3rd Year Project (Anirban Laxman).iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Crowd_Report.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Crowd_Report.pdf -------------------------------------------------------------------------------- /Images/Crowd_Report.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/Crowd_Report.docx -------------------------------------------------------------------------------- /Images/Crowd_Report.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/Crowd_Report.png -------------------------------------------------------------------------------- /Images/IMG.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/IMG.jpg -------------------------------------------------------------------------------- /Images/Screenshot_20210918-145120_Chrome.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/Screenshot_20210918-145120_Chrome.jpg -------------------------------------------------------------------------------- /Images/Screenshot_20210918-145240_Chrome.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/Screenshot_20210918-145240_Chrome.jpg -------------------------------------------------------------------------------- /Images/Screenshot_20210918-145710_Chrome.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/Screenshot_20210918-145710_Chrome.jpg -------------------------------------------------------------------------------- /Images/Template Image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/Template Image.jpg -------------------------------------------------------------------------------- /Images/f1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/f1.jpg -------------------------------------------------------------------------------- /Images/f2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/f2.jpg -------------------------------------------------------------------------------- /Images/front1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/front1.png -------------------------------------------------------------------------------- /Images/front2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/front2.png -------------------------------------------------------------------------------- /Images/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/icon.ico -------------------------------------------------------------------------------- /Images/icon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/icon.jpg -------------------------------------------------------------------------------- /Images/image1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/image1.jpg -------------------------------------------------------------------------------- /Images/image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/image2.png -------------------------------------------------------------------------------- /Images/image3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/image3.jpg -------------------------------------------------------------------------------- /Images/img1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/img1.jpg -------------------------------------------------------------------------------- /Images/img2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/img2.jpg -------------------------------------------------------------------------------- /Images/img3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/img3.jpg -------------------------------------------------------------------------------- /Images/pdf_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/pdf_logo.png -------------------------------------------------------------------------------- /Images/pdf_logo_down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Images/pdf_logo_down.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Akash Rajak 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /PPT + Report/Final PPT.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/PPT + Report/Final PPT.ppt -------------------------------------------------------------------------------- /PPT + Report/Final Report.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/PPT + Report/Final Report.docx -------------------------------------------------------------------------------- /PPT + Report/Final Report.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/PPT + Report/Final Report.pdf -------------------------------------------------------------------------------- /PPT + Report/JETIR2205586.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/PPT + Report/JETIR2205586.pdf -------------------------------------------------------------------------------- /PPT + Report/JETIR2205586_Certificate.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/PPT + Report/JETIR2205586_Certificate.pdf -------------------------------------------------------------------------------- /PPT + Report/Project_proposal.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/PPT + Report/Project_proposal.docx -------------------------------------------------------------------------------- /PPT + Report/Project_proposal.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/PPT + Report/Project_proposal.pdf -------------------------------------------------------------------------------- /PPT + Report/Weekly Update.ppt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/PPT + Report/Weekly Update.ppt -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## ✔ REAL TIME HUMAN DETECTION & COUNTING 2 | - A tensorflow based `Faster RCNN inception v2` python model to detect and count humans in real time images, videos & camera. 3 | - Used pre-trained `frozen_inference_graph.pb` frozen graph to handle the detection. 4 | - Visualize the data using `Enumeration Plot` and `Avg. Accuracy Plot`. 5 | 6 |

7 | GitHub Repo stars 8 | GitHub Repo forks 9 | GitHub Repo watchers 10 | GitHub contributors 11 |

12 |

13 | GitHub language count 14 | GitHub top language 15 | GitHub repo file count 16 | GitHub repo size 17 |

18 |

19 | GitHub issues 20 | GitHub closed issues 21 | GitHub pull requests 22 | GitHub closed pull requests 23 |

24 |

25 | GitHub commit activity 26 | GitHub commit activity/year 27 | GitHub commit activity/month 28 | GitHub commit activity/week 29 | GitHub last commit 30 | GitHub Discussions 31 |

32 |

33 | Github 34 |

35 | 36 | 69 | 70 | **** 71 | 72 | ### 📌REQUIREMENTS : 73 | - python 3 74 | - tkinter 75 | - messagebox 76 | - PIL 77 | - cv2 78 | - argparse 79 | - matplotlib.pyplot 80 | - numpy 81 | - time 82 | - os 83 | - tensorflow 84 | - fpdf 85 | 86 | **** 87 | 88 | ### 📌How this Script works : 89 | - User just need to download the file and run the main.py on their local system. 90 | - On the starting window of the application, user will be able to see START and EXIT option, using which user can start the application or exit from the application. 91 | - When user starts the application using START button, a new window will open, which allows user with options like, DETECT FROM IMAGE, DETECT FROM VIDEO or DETECT FROM CAMERA. 92 | - When user selects any of the first two option, he/she needs to select the respective files using SELECT button. 93 | - User can preview the selected file using PREVIEW button, and detect and count the humans using DETECT button. 94 | - And when user selects, the last option of detecting through camera, user need to open the Camera, using OPEN CAMERA button, As soon as camera opens, detection process will start. 95 | - After detection process gets completed or user manually completes it, two graph get plotted, 96 | - 1.) Enumeration Plot(Human Count Vs. time) and 97 | - 2.) Avg. Accuracy Plot(Avg. Accuracy Vs. time). 98 | - Along with this two plots, an option to generate crowd report also appears, On clicking on it, a crowd report in form of PDF is generated ans saved autmatically at the project file location. 99 | - In the crowd report genrated, there will be information like, What is Max Human Count, Max Accuracy, Max Avg. Accuracy, and also a two line status about crowd. 100 | 101 | ### 📌Purrpose : 102 | - This scripts helps user to easily get the count of human through real time image, video or camera, and thereafter also analysis of crowd through crowd report. 103 | 104 | ### 📌Compilation Steps : 105 | - Install all the required libraries. 106 | - After that download the code file, and run main.py on local system. 107 | - Then the script will start running and user can explore it by detecting the human and also getting the count of it. 108 | 109 | **** 110 | 111 | ### 📌SCREENSHOTS : 112 | 113 |

114 |
115 |
116 |

117 | 118 | - #### Image: 119 | 120 |

121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |

132 | 133 | - #### Video: 134 | 135 |

136 |
137 |
138 |
139 |
140 |
141 |

142 | 143 | - #### Camera: 144 | 145 |

146 |
147 |
148 |
149 |
150 |
151 |
152 |

153 | 154 | **** 155 | 156 | ### 🌟Stargazers Over Time: 157 | [![Stargazers repo roster for @akash-rajak/Real-Time-Human-Detection-Counting](https://reporoster.com/stars/akash-rajak/Real-Time-Human-Detection-Counting)](https://github.com/akash-rajak/Real-Time-Human-Detection-Counting/stargazers) 158 | 159 | [![Stargazers over time](https://starchart.cc/akash-rajak/Real-Time-Human-Detection-Counting.svg)](https://starchart.cc/akash-rajak/Real-Time-Human-Detection-Counting) 160 | 161 | **** 162 | 163 | ### 🌟Forkers Over Time: 164 | [![Forkers repo roster for @akash-rajak/Real-Time-Human-Detection-Counting](https://reporoster.com/forks/akash-rajak/Real-Time-Human-Detection-Counting)](https://github.com/akash-rajak/Real-Time-Human-Detection-Counting/network/members) 165 | 166 | **** 167 | 168 | ### 📌Contributors: 169 | 170 | 171 | 172 | 173 | -------------------------------------------------------------------------------- /Sample Images and Videos/Screenshot_20210918-145120_Chrome.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Sample Images and Videos/Screenshot_20210918-145120_Chrome.jpg -------------------------------------------------------------------------------- /Sample Images and Videos/Screenshot_20210918-145240_Chrome.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Sample Images and Videos/Screenshot_20210918-145240_Chrome.jpg -------------------------------------------------------------------------------- /Sample Images and Videos/Screenshot_20210918-145710_Chrome.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Sample Images and Videos/Screenshot_20210918-145710_Chrome.jpg -------------------------------------------------------------------------------- /Sample Images and Videos/img1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Sample Images and Videos/img1.jpg -------------------------------------------------------------------------------- /Sample Images and Videos/img2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Sample Images and Videos/img2.jpg -------------------------------------------------------------------------------- /Sample Images and Videos/img3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Sample Images and Videos/img3.jpg -------------------------------------------------------------------------------- /Sample Images and Videos/vid.webm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Sample Images and Videos/vid.webm -------------------------------------------------------------------------------- /Sample Images and Videos/vid1.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Sample Images and Videos/vid1.mp4 -------------------------------------------------------------------------------- /Sample Images and Videos/vid2.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Sample Images and Videos/vid2.mp4 -------------------------------------------------------------------------------- /Sample Images and Videos/vid3.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Sample Images and Videos/vid3.mp4 -------------------------------------------------------------------------------- /Sample Images and Videos/vid4.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Sample Images and Videos/vid4.mp4 -------------------------------------------------------------------------------- /Sample Images and Videos/vid5.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Sample Images and Videos/vid5.mp4 -------------------------------------------------------------------------------- /Screenshots/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/1.jpg -------------------------------------------------------------------------------- /Screenshots/10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/10.jpg -------------------------------------------------------------------------------- /Screenshots/11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/11.jpg -------------------------------------------------------------------------------- /Screenshots/12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/12.jpg -------------------------------------------------------------------------------- /Screenshots/13.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/13.jpg -------------------------------------------------------------------------------- /Screenshots/14.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/14.jpg -------------------------------------------------------------------------------- /Screenshots/15.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/15.jpg -------------------------------------------------------------------------------- /Screenshots/16.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/16.jpg -------------------------------------------------------------------------------- /Screenshots/17.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/17.jpg -------------------------------------------------------------------------------- /Screenshots/18.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/18.jpg -------------------------------------------------------------------------------- /Screenshots/19.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/19.jpg -------------------------------------------------------------------------------- /Screenshots/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/2.jpg -------------------------------------------------------------------------------- /Screenshots/20.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/20.jpg -------------------------------------------------------------------------------- /Screenshots/21.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/21.jpg -------------------------------------------------------------------------------- /Screenshots/22.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/22.jpg -------------------------------------------------------------------------------- /Screenshots/23.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/23.jpg -------------------------------------------------------------------------------- /Screenshots/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/3.jpg -------------------------------------------------------------------------------- /Screenshots/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/4.jpg -------------------------------------------------------------------------------- /Screenshots/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/5.jpg -------------------------------------------------------------------------------- /Screenshots/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/6.jpg -------------------------------------------------------------------------------- /Screenshots/7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/7.jpg -------------------------------------------------------------------------------- /Screenshots/8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/8.jpg -------------------------------------------------------------------------------- /Screenshots/9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/Screenshots/9.jpg -------------------------------------------------------------------------------- /__pycache__/persondetection.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/__pycache__/persondetection.cpython-310.pyc -------------------------------------------------------------------------------- /__pycache__/persondetection.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/__pycache__/persondetection.cpython-311.pyc -------------------------------------------------------------------------------- /__pycache__/persondetection.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/__pycache__/persondetection.cpython-38.pyc -------------------------------------------------------------------------------- /__pycache__/persondetection.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/__pycache__/persondetection.cpython-39.pyc -------------------------------------------------------------------------------- /frozen_inference_graph.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/akash-rajak/Real-Time-Human-Detection-Counting/d7c9a6beeba27f6dd6ff7722a841de82c00074c6/frozen_inference_graph.pb -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | 2 | # Real Time Human Detection & Counting 3 | 4 | # imported necessary library 5 | from tkinter import * 6 | import tkinter as tk 7 | import tkinter.messagebox as mbox 8 | from tkinter import filedialog 9 | from PIL import ImageTk, Image 10 | import cv2 11 | import argparse 12 | from persondetection import DetectorAPI 13 | import matplotlib.pyplot as plt 14 | from fpdf import FPDF 15 | 16 | 17 | # Main Window & Configuration 18 | window = tk.Tk() 19 | window.title("Real Time Human Detection & Counting") 20 | window.iconbitmap('Images/icon.ico') 21 | window.geometry('1000x700') 22 | 23 | # top label 24 | start1 = tk.Label(text = "REAL-TIME-HUMAN\nDETECTION & COUNTING", font=("Arial", 50,"underline"), fg="magenta") # same way bg 25 | start1.place(x = 70, y = 10) 26 | 27 | # function defined to start the main application 28 | def start_fun(): 29 | window.destroy() 30 | 31 | # created a start button 32 | Button(window, text="▶ START",command=start_fun,font=("Arial", 25), bg = "orange", fg = "blue", cursor="hand2", borderwidth=3, relief="raised").place(x =130 , y =570 ) 33 | 34 | # image on the main window 35 | path1 = "Images/front2.png" 36 | img2 = ImageTk.PhotoImage(Image.open(path1)) 37 | panel1 = tk.Label(window, image = img2) 38 | panel1.place(x = 90, y = 250) 39 | 40 | # image on the main window 41 | path = "Images/front1.png" 42 | img1 = ImageTk.PhotoImage(Image.open(path)) 43 | panel = tk.Label(window, image = img1) 44 | panel.place(x = 380, y = 180) 45 | 46 | exit1 = False 47 | # function created for exiting from window 48 | def exit_win(): 49 | global exit1 50 | if mbox.askokcancel("Exit", "Do you want to exit?"): 51 | exit1 = True 52 | window.destroy() 53 | 54 | # exit button created 55 | Button(window, text="❌ EXIT",command=exit_win,font=("Arial", 25), bg = "red", fg = "blue", cursor="hand2", borderwidth=3, relief="raised").place(x =680 , y = 570 ) 56 | 57 | window.protocol("WM_DELETE_WINDOW", exit_win) 58 | window.mainloop() 59 | 60 | if exit1==False: 61 | # Main Window & Configuration of window1 62 | window1 = tk.Tk() 63 | window1.title("Real Time Human Detection & Counting") 64 | window1.iconbitmap('Images/icon.ico') 65 | window1.geometry('1000x700') 66 | 67 | filename="" 68 | filename1="" 69 | filename2="" 70 | 71 | def argsParser(): 72 | arg_parse = argparse.ArgumentParser() 73 | arg_parse.add_argument("-v", "--video", default=None, help="path to Video File ") 74 | arg_parse.add_argument("-i", "--image", default=None, help="path to Image File ") 75 | arg_parse.add_argument("-c", "--camera", default=False, help="Set true if you want to use the camera.") 76 | arg_parse.add_argument("-o", "--output", type=str, help="path to optional output video file") 77 | args = vars(arg_parse.parse_args()) 78 | return args 79 | 80 | # ---------------------------- image section ------------------------------------------------------------ 81 | def image_option(): 82 | # new windowi created for image section 83 | windowi = tk.Tk() 84 | windowi.title("Human Detection from Image") 85 | windowi.iconbitmap('Images/icon.ico') 86 | windowi.geometry('1000x700') 87 | 88 | max_count1 = 0 89 | framex1 = [] 90 | county1 = [] 91 | max1 = [] 92 | avg_acc1_list = [] 93 | max_avg_acc1_list = [] 94 | max_acc1 = 0 95 | max_avg_acc1 = 0 96 | 97 | # function defined to open the image 98 | def open_img(): 99 | global filename1, max_count1, framex1, county1, max1, avg_acc1_list, max_avg_acc1_list, max_acc1, max_avg_acc1 100 | max_count1 = 0 101 | framex1 = [] 102 | county1 = [] 103 | max1 = [] 104 | avg_acc1_list = [] 105 | max_avg_acc1_list = [] 106 | max_acc1 = 0 107 | max_avg_acc1 = 0 108 | 109 | filename1 = filedialog.askopenfilename(title="Select Image file", parent = windowi) 110 | path_text1.delete("1.0", "end") 111 | path_text1.insert(END, filename1) 112 | 113 | # function defined to detect the image 114 | def det_img(): 115 | global filename1, max_count1, framex1, county1, max1, avg_acc1_list, max_avg_acc1_list, max_acc1, max_avg_acc1 116 | max_count1 = 0 117 | framex1 = [] 118 | county1 = [] 119 | max1 = [] 120 | avg_acc1_list = [] 121 | max_avg_acc1_list = [] 122 | max_acc1 = 0 123 | max_avg_acc1 = 0 124 | 125 | image_path = filename1 126 | if(image_path==""): 127 | mbox.showerror("Error", "No Image File Selected!", parent = windowi) 128 | return 129 | info1.config(text="Status : Detecting...") 130 | # info2.config(text=" ") 131 | mbox.showinfo("Status", "Detecting, Please Wait...", parent = windowi) 132 | # time.sleep(1) 133 | detectByPathImage(image_path) 134 | 135 | # main detection process process here 136 | def detectByPathImage(path): 137 | global filename1, max_count1, framex1, county1, max1, avg_acc1_list, max_avg_acc1_list, max_acc1, max_avg_acc1 138 | max_count1 = 0 139 | framex1 = [] 140 | county1 = [] 141 | max1 = [] 142 | avg_acc1_list = [] 143 | max_avg_acc1_list = [] 144 | max_acc1 = 0 145 | max_avg_acc1 = 0 146 | 147 | # function defined to plot the enumeration fo people detected 148 | def img_enumeration_plot(): 149 | plt.figure(facecolor='orange', ) 150 | ax = plt.axes() 151 | ax.set_facecolor("yellow") 152 | plt.plot(framex1, county1, label="Human Count", color="green", marker='o', markerfacecolor='blue') 153 | plt.plot(framex1, max1, label="Max. Human Count", linestyle='dashed', color='fuchsia') 154 | plt.xlabel('Time (sec)') 155 | plt.ylabel('Human Count') 156 | plt.legend() 157 | plt.title("Enumeration Plot") 158 | # plt.get_current_fig_manager().canvas.set_window_title("Plot for Image") 159 | # plt.manager.set_window_title("Plot for Image") 160 | plt.show() 161 | 162 | def img_accuracy_plot(): 163 | plt.figure(facecolor='orange', ) 164 | ax = plt.axes() 165 | ax.set_facecolor("yellow") 166 | plt.plot(framex1, avg_acc1_list, label="Avg. Accuracy", color="green", marker='o', markerfacecolor='blue') 167 | plt.plot(framex1, max_avg_acc1_list, label="Max. Avg. Accuracy", linestyle='dashed', color='fuchsia') 168 | plt.xlabel('Time (sec)') 169 | plt.ylabel('Avg. Accuracy') 170 | plt.title('Avg. Accuracy Plot') 171 | plt.legend() 172 | plt.get_current_fig_manager().canvas.set_window_title("Plot for Image") 173 | plt.show() 174 | 175 | def img_gen_report(): 176 | pdf = FPDF(orientation='P', unit='mm', format='A4') 177 | pdf.add_page() 178 | pdf.set_font("Arial", "", 20) 179 | pdf.set_text_color(128, 0, 0) 180 | pdf.image('Images/Crowd_Report.png', x=0, y=0, w=210, h=297) 181 | 182 | pdf.text(125, 150, str(max_count1)) 183 | pdf.text(105, 163, str(max_acc1)) 184 | pdf.text(125, 175, str(max_avg_acc1)) 185 | if (max_count1 > 25): 186 | pdf.text(26, 220, "Max. Human Detected is greater than MAX LIMIT.") 187 | pdf.text(70, 235, "Region is Crowded.") 188 | else: 189 | pdf.text(26, 220, "Max. Human Detected is in range of MAX LIMIT.") 190 | pdf.text(65, 235, "Region is not Crowded.") 191 | 192 | pdf.output('Crowd_Report.pdf') 193 | mbox.showinfo("Status", "Report Generated and Saved Successfully.", parent = windowi) 194 | 195 | 196 | odapi = DetectorAPI() 197 | threshold = 0.7 198 | 199 | image = cv2.imread(path) 200 | img = cv2.resize(image, (image.shape[1], image.shape[0])) 201 | boxes, scores, classes, num = odapi.processFrame(img) 202 | person = 0 203 | acc=0 204 | for i in range(len(boxes)): 205 | 206 | if classes[i] == 1 and scores[i] > threshold: 207 | box = boxes[i] 208 | person += 1 209 | cv2.rectangle(img, (box[1], box[0]), (box[3], box[2]), (255,0,0), 2) # cv2.FILLED #BGR 210 | cv2.putText(img, f'P{person, round(scores[i], 2)}', (box[1] - 30, box[0] - 8), cv2.FONT_HERSHEY_COMPLEX,0.5, (0, 0, 255), 1) # (75,0,130), 211 | acc += scores[i] 212 | if (scores[i] > max_acc1): 213 | max_acc1 = scores[i] 214 | 215 | if (person > max_count1): 216 | max_count1 = person 217 | if(person>=1): 218 | if((acc / person) > max_avg_acc1): 219 | max_avg_acc1 = (acc / person) 220 | 221 | 222 | cv2.imshow("Human Detection from Image", img) 223 | info1.config(text=" ") 224 | info1.config(text="Status : Detection & Counting Completed") 225 | # info2.config(text=" ") 226 | # info2.config(text="Max. Human Count : " + str(max_count1)) 227 | cv2.waitKey(0) 228 | cv2.destroyAllWindows() 229 | 230 | for i in range(20): 231 | framex1.append(i) 232 | county1.append(max_count1) 233 | max1.append(max_count1) 234 | avg_acc1_list.append(max_avg_acc1) 235 | max_avg_acc1_list.append(max_avg_acc1) 236 | 237 | Button(windowi, text="Enumeration\nPlot", command=img_enumeration_plot, cursor="hand2", font=("Arial", 20),bg="orange", fg="blue").place(x=100, y=530) 238 | Button(windowi, text="Avg. Accuracy\nPlot", command=img_accuracy_plot, cursor="hand2", font=("Arial", 20),bg="orange", fg="blue").place(x=700, y=530) 239 | Button(windowi, text="Generate Crowd Report", command=img_gen_report, cursor="hand2", font=("Arial", 20),bg="light gray", fg="blue").place(x=325, y=550) 240 | 241 | def prev_img(): 242 | global filename1 243 | img = cv2.imread(filename1, 1) 244 | cv2.imshow("Selected Image Preview", img) 245 | 246 | # for images ---------------------- 247 | lbl1 = tk.Label(windowi,text="DETECT FROM\nIMAGE", font=("Arial", 50, "underline"),fg="brown") 248 | lbl1.place(x=230, y=20) 249 | lbl2 = tk.Label(windowi,text="Selected Image", font=("Arial", 30),fg="green") 250 | lbl2.place(x=80, y=200) 251 | path_text1 = tk.Text(windowi, height=1, width=37, font=("Arial", 30), bg="light yellow", fg="orange",borderwidth=2, relief="solid") 252 | path_text1.place(x=80, y = 260) 253 | 254 | Button(windowi, text="SELECT", command=open_img, cursor="hand2", font=("Arial", 20), bg="light green", fg="blue").place(x=220, y=350) 255 | Button(windowi, text="PREVIEW",command=prev_img, cursor="hand2", font=("Arial", 20), bg = "yellow", fg = "blue").place(x = 410, y = 350) 256 | Button(windowi, text="DETECT",command=det_img, cursor="hand2", font=("Arial", 20), bg = "orange", fg = "blue").place(x = 620, y = 350) 257 | 258 | info1 = tk.Label(windowi,font=( "Arial", 30),fg="gray") 259 | info1.place(x=100, y=445) 260 | # info2 = tk.Label(windowi,font=("Arial", 30), fg="gray") 261 | # info2.place(x=100, y=500) 262 | 263 | def exit_wini(): 264 | if mbox.askokcancel("Exit", "Do you want to exit?", parent = windowi): 265 | windowi.destroy() 266 | windowi.protocol("WM_DELETE_WINDOW", exit_wini) 267 | 268 | 269 | # ---------------------------- video section ------------------------------------------------------------ 270 | def video_option(): 271 | # new windowv created for video section 272 | windowv = tk.Tk() 273 | windowv.title("Human Detection from Video") 274 | windowv.iconbitmap('Images/icon.ico') 275 | windowv.geometry('1000x700') 276 | 277 | max_count2 = 0 278 | framex2 = [] 279 | county2 = [] 280 | max2 = [] 281 | avg_acc2_list = [] 282 | max_avg_acc2_list = [] 283 | max_acc2 = 0 284 | max_avg_acc2 = 0 285 | 286 | # function defined to open the video 287 | def open_vid(): 288 | global filename2, max_count2, framex2, county2, max2, avg_acc2_list, max_avg_acc2_list, max_acc2, max_avg_acc2 289 | max_count2 = 0 290 | framex2 = [] 291 | county2 = [] 292 | max2=[] 293 | avg_acc2_list = [] 294 | max_avg_acc2_list = [] 295 | max_acc2 = 0 296 | max_avg_acc2 = 0 297 | 298 | filename2 = filedialog.askopenfilename(title="Select Video file", parent=windowv) 299 | path_text2.delete("1.0", "end") 300 | path_text2.insert(END, filename2) 301 | 302 | # function defined to detect inside the video 303 | def det_vid(): 304 | global filename2, max_count2, framex2, county2, max2, avg_acc2_list, max_avg_acc2_list, max_acc2, max_avg_acc2 305 | max_count2 = 0 306 | framex2 = [] 307 | county2 = [] 308 | max2 = [] 309 | avg_acc2_list = [] 310 | max_avg_acc2_list = [] 311 | max_acc2 = 0 312 | max_avg_acc2 = 0 313 | 314 | video_path = filename2 315 | if (video_path == ""): 316 | mbox.showerror("Error", "No Video File Selected!", parent = windowv) 317 | return 318 | info1.config(text="Status : Detecting...") 319 | # info2.config(text=" ") 320 | mbox.showinfo("Status", "Detecting, Please Wait...", parent=windowv) 321 | # time.sleep(1) 322 | 323 | args = argsParser() 324 | writer = None 325 | if args['output'] is not None: 326 | writer = cv2.VideoWriter(args['output'], cv2.VideoWriter_fourcc(*'MJPG'), 10, (600, 600)) 327 | 328 | detectByPathVideo(video_path, writer) 329 | 330 | # the main process of detection in video takes place here 331 | def detectByPathVideo(path, writer): 332 | global filename2, max_count2, framex2, county2, max2, avg_acc2_list, max_avg_acc2_list, max_acc2, max_avg_acc2 333 | max_count2 = 0 334 | framex2 = [] 335 | county2 = [] 336 | max2 = [] 337 | avg_acc2_list = [] 338 | max_avg_acc2_list = [] 339 | max_acc2 = 0 340 | max_avg_acc2 = 0 341 | 342 | # function defined to plot the people detected in video 343 | def vid_enumeration_plot(): 344 | plt.figure(facecolor='orange', ) 345 | ax = plt.axes() 346 | ax.set_facecolor("yellow") 347 | plt.plot(framex2, county2, label = "Human Count", color = "green", marker='o', markerfacecolor='blue') 348 | plt.plot(framex2, max2, label="Max. Human Count", linestyle='dashed', color='fuchsia') 349 | plt.xlabel('Time (sec)') 350 | plt.ylabel('Human Count') 351 | plt.title('Enumeration Plot') 352 | plt.legend() 353 | plt.get_current_fig_manager().canvas.set_window_title("Plot for Video") 354 | plt.show() 355 | 356 | def vid_accuracy_plot(): 357 | plt.figure(facecolor='orange', ) 358 | ax = plt.axes() 359 | ax.set_facecolor("yellow") 360 | plt.plot(framex2, avg_acc2_list, label="Avg. Accuracy", color="green", marker='o', markerfacecolor='blue') 361 | plt.plot(framex2, max_avg_acc2_list, label="Max. Avg. Accuracy", linestyle='dashed', color='fuchsia') 362 | plt.xlabel('Time (sec)') 363 | plt.ylabel('Avg. Accuracy') 364 | plt.title('Avg. Accuracy Plot') 365 | plt.legend() 366 | plt.get_current_fig_manager().canvas.set_window_title("Plot for Video") 367 | plt.show() 368 | 369 | def vid_gen_report(): 370 | pdf = FPDF(orientation='P', unit='mm', format='A4') 371 | pdf.add_page() 372 | pdf.set_font("Arial", "", 20) 373 | pdf.set_text_color(128, 0, 0) 374 | pdf.image('Images/Crowd_Report.png', x=0, y=0, w=210, h=297) 375 | 376 | pdf.text(125, 150, str(max_count2)) 377 | pdf.text(105, 163, str(max_acc2)) 378 | pdf.text(125, 175, str(max_avg_acc2)) 379 | if(max_count2>25): 380 | pdf.text(26, 220, "Max. Human Detected is greater than MAX LIMIT.") 381 | pdf.text(70, 235, "Region is Crowded.") 382 | else: 383 | pdf.text(26, 220, "Max. Human Detected is in range of MAX LIMIT.") 384 | pdf.text(65, 235, "Region is not Crowded.") 385 | 386 | pdf.output('Crowd_Report.pdf') 387 | mbox.showinfo("Status", "Report Generated and Saved Successfully.", parent = windowv) 388 | 389 | video = cv2.VideoCapture(path) 390 | odapi = DetectorAPI() 391 | threshold = 0.7 392 | 393 | check, frame = video.read() 394 | if check == False: 395 | print('Video Not Found. Please Enter a Valid Path (Full path of Video Should be Provided).') 396 | return 397 | 398 | x2 = 0 399 | while video.isOpened(): 400 | # check is True if reading was successful 401 | check, frame = video.read() 402 | if(check==True): 403 | img = cv2.resize(frame, (800, 500)) 404 | boxes, scores, classes, num = odapi.processFrame(img) 405 | person = 0 406 | acc = 0 407 | for i in range(len(boxes)): 408 | # print(boxes) 409 | # print(scores) 410 | # print(classes) 411 | # print(num) 412 | # print() 413 | if classes[i] == 1 and scores[i] > threshold: 414 | box = boxes[i] 415 | person += 1 416 | cv2.rectangle(img, (box[1], box[0]), (box[3], box[2]), (255, 0, 0), 2) # cv2.FILLED 417 | cv2.putText(img, f'P{person, round(scores[i],2)}', (box[1]-30, box[0]-8), cv2.FONT_HERSHEY_COMPLEX, 0.5, (0,0,255), 1 )#(75,0,130), 418 | acc+=scores[i] 419 | if(scores[i]>max_acc2): 420 | max_acc2 = scores[i] 421 | 422 | if(person>max_count2): 423 | max_count2 = person 424 | county2.append(person) 425 | x2+=1 426 | framex2.append(x2) 427 | if(person>=1): 428 | avg_acc2_list.append(acc/person) 429 | if((acc/person)>max_avg_acc2): 430 | max_avg_acc2 = (acc/person) 431 | else: 432 | avg_acc2_list.append(acc) 433 | 434 | if writer is not None: 435 | writer.write(img) 436 | 437 | cv2.imshow("Human Detection from Video", img) 438 | key = cv2.waitKey(1) 439 | if key & 0xFF == ord('q'): 440 | break 441 | else: 442 | break 443 | 444 | video.release() 445 | info1.config(text=" ") 446 | # info2.config(text=" ") 447 | info1.config(text="Status : Detection & Counting Completed") 448 | # info2.config(text="Max. Human Count : " + str(max_count2)) 449 | cv2.destroyAllWindows() 450 | 451 | for i in range(len(framex2)): 452 | max2.append(max_count2) 453 | max_avg_acc2_list.append(max_avg_acc2) 454 | 455 | Button(windowv, text="Enumeration\nPlot", command=vid_enumeration_plot, cursor="hand2", font=("Arial", 20),bg="orange", fg="blue").place(x=100, y=530) 456 | Button(windowv, text="Avg. Accuracy\nPlot", command=vid_accuracy_plot, cursor="hand2", font=("Arial", 20),bg="orange", fg="blue").place(x=700, y=530) 457 | Button(windowv, text="Generate Crowd Report", command=vid_gen_report, cursor="hand2", font=("Arial", 20),bg="gray", fg="blue").place(x=325, y=550) 458 | 459 | # funcion defined to preview the selected video 460 | def prev_vid(): 461 | global filename2 462 | cap = cv2.VideoCapture(filename2) 463 | while (cap.isOpened()): 464 | ret, frame = cap.read() 465 | if ret == True: 466 | img = cv2.resize(frame, (800, 500)) 467 | cv2.imshow('Selected Video Preview', img) 468 | if cv2.waitKey(25) & 0xFF == ord('q'): 469 | break 470 | else: 471 | break 472 | cap.release() 473 | cv2.destroyAllWindows() 474 | 475 | 476 | lbl1 = tk.Label(windowv, text="DETECT FROM\nVIDEO", font=("Arial", 50, "underline"), fg="brown") 477 | lbl1.place(x=230, y=20) 478 | lbl2 = tk.Label(windowv, text="Selected Video", font=("Arial", 30), fg="green") 479 | lbl2.place(x=80, y=200) 480 | path_text2 = tk.Text(windowv, height=1, width=37, font=("Arial", 30), bg="light yellow", fg="orange", borderwidth=2,relief="solid") 481 | path_text2.place(x=80, y=260) 482 | 483 | Button(windowv, text="SELECT", command=open_vid, cursor="hand2", font=("Arial", 20), bg="light green", fg="blue").place(x=220, y=350) 484 | Button(windowv, text="PREVIEW", command=prev_vid, cursor="hand2", font=("Arial", 20), bg="yellow", fg="blue").place(x=410, y=350) 485 | Button(windowv, text="DETECT", command=det_vid, cursor="hand2", font=("Arial", 20), bg="orange", fg="blue").place(x=620, y=350) 486 | 487 | info1 = tk.Label(windowv, font=("Arial", 30), fg="gray") # same way bg 488 | info1.place(x=100, y=440) 489 | # info2 = tk.Label(windowv, font=("Arial", 30), fg="gray") # same way bg 490 | # info2.place(x=100, y=500) 491 | 492 | #function defined to exit from windowv section 493 | def exit_winv(): 494 | if mbox.askokcancel("Exit", "Do you want to exit?", parent = windowv): 495 | windowv.destroy() 496 | windowv.protocol("WM_DELETE_WINDOW", exit_winv) 497 | 498 | 499 | # ---------------------------- camera section ------------------------------------------------------------ 500 | def camera_option(): 501 | # new window created for camera section 502 | windowc = tk.Tk() 503 | windowc.title("Human Detection from Camera") 504 | windowc.iconbitmap('Images/icon.ico') 505 | windowc.geometry('1000x700') 506 | 507 | max_count3 = 0 508 | framex3 = [] 509 | county3 = [] 510 | max3 = [] 511 | avg_acc3_list = [] 512 | max_avg_acc3_list = [] 513 | max_acc3 = 0 514 | max_avg_acc3 = 0 515 | 516 | # function defined to open the camera 517 | def open_cam(): 518 | global max_count3, framex3, county3, max3, avg_acc3_list, max_avg_acc3_list, max_acc3, max_avg_acc3 519 | max_count3 = 0 520 | framex3 = [] 521 | county3 = [] 522 | max3 = [] 523 | avg_acc3_list = [] 524 | max_avg_acc3_list = [] 525 | max_acc3 = 0 526 | max_avg_acc3 = 0 527 | 528 | args = argsParser() 529 | 530 | info1.config(text="Status : Opening Camera...") 531 | # info2.config(text=" ") 532 | mbox.showinfo("Status", "Opening Camera...Please Wait...", parent=windowc) 533 | # time.sleep(1) 534 | 535 | writer = None 536 | if args['output'] is not None: 537 | writer = cv2.VideoWriter(args['output'], cv2.VideoWriter_fourcc(*'MJPG'), 10, (600, 600)) 538 | if True: 539 | detectByCamera(writer) 540 | 541 | # function defined to detect from camera 542 | def detectByCamera(writer): 543 | #global variable created 544 | global max_count3, framex3, county3, max3, avg_acc3_list, max_avg_acc3_list, max_acc3, max_avg_acc3 545 | max_count3 = 0 546 | framex3 = [] 547 | county3 = [] 548 | max3 = [] 549 | avg_acc3_list = [] 550 | max_avg_acc3_list = [] 551 | max_acc3 = 0 552 | max_avg_acc3 = 0 553 | 554 | # function defined to plot the people count in camera 555 | def cam_enumeration_plot(): 556 | plt.figure(facecolor='orange', ) 557 | ax = plt.axes() 558 | ax.set_facecolor("yellow") 559 | plt.plot(framex3, county3, label="Human Count", color="green", marker='o', markerfacecolor='blue') 560 | plt.plot(framex3, max3, label="Max. Human Count", linestyle='dashed', color='fuchsia') 561 | plt.xlabel('Time (sec)') 562 | plt.ylabel('Human Count') 563 | plt.legend() 564 | plt.title("Enumeration Plot") 565 | plt.get_current_fig_manager().canvas.set_window_title("Plot for Camera") 566 | plt.show() 567 | 568 | def cam_accuracy_plot(): 569 | plt.figure(facecolor='orange', ) 570 | ax = plt.axes() 571 | ax.set_facecolor("yellow") 572 | plt.plot(framex3, avg_acc3_list, label="Avg. Accuracy", color="green", marker='o', markerfacecolor='blue') 573 | plt.plot(framex3, max_avg_acc3_list, label="Max. Avg. Accuracy", linestyle='dashed', color='fuchsia') 574 | plt.xlabel('Time (sec)') 575 | plt.ylabel('Avg. Accuracy') 576 | plt.title('Avg. Accuracy Plot') 577 | plt.legend() 578 | plt.get_current_fig_manager().canvas.set_window_title("Plot for Camera") 579 | plt.show() 580 | 581 | def cam_gen_report(): 582 | pdf = FPDF(orientation='P', unit='mm', format='A4') 583 | pdf.add_page() 584 | pdf.set_font("Arial", "", 20) 585 | pdf.set_text_color(128, 0, 0) 586 | pdf.image('Images/Crowd_Report.png', x=0, y=0, w=210, h=297) 587 | 588 | pdf.text(125, 150, str(max_count3)) 589 | pdf.text(105, 163, str(max_acc3)) 590 | pdf.text(125, 175, str(max_avg_acc3)) 591 | if (max_count3 > 25): 592 | pdf.text(26, 220, "Max. Human Detected is greater than MAX LIMIT.") 593 | pdf.text(70, 235, "Region is Crowded.") 594 | else: 595 | pdf.text(26, 220, "Max. Human Detected is in range of MAX LIMIT.") 596 | pdf.text(65, 235, "Region is not Crowded.") 597 | 598 | pdf.output('Crowd_Report.pdf') 599 | mbox.showinfo("Status", "Report Generated and Saved Successfully.", parent = windowc) 600 | 601 | video = cv2.VideoCapture(0) 602 | odapi = DetectorAPI() 603 | threshold = 0.7 604 | 605 | x3 = 0 606 | while True: 607 | check, frame = video.read() 608 | img = cv2.resize(frame, (800, 600)) 609 | boxes, scores, classes, num = odapi.processFrame(img) 610 | person = 0 611 | acc = 0 612 | for i in range(len(boxes)): 613 | 614 | if classes[i] == 1 and scores[i] > threshold: 615 | box = boxes[i] 616 | person += 1 617 | cv2.rectangle(img, (box[1], box[0]), (box[3], box[2]), (255, 0, 0), 2) # cv2.FILLED 618 | cv2.putText(img, f'P{person, round(scores[i], 2)}', (box[1] - 30, box[0] - 8),cv2.FONT_HERSHEY_COMPLEX, 0.5, (0, 0, 255), 1) # (75,0,130), 619 | acc += scores[i] 620 | if (scores[i] > max_acc3): 621 | max_acc3 = scores[i] 622 | 623 | if (person > max_count3): 624 | max_count3 = person 625 | 626 | if writer is not None: 627 | writer.write(img) 628 | 629 | cv2.imshow("Human Detection from Camera", img) 630 | key = cv2.waitKey(1) 631 | if key & 0xFF == ord('q'): 632 | break 633 | 634 | county3.append(person) 635 | x3 += 1 636 | framex3.append(x3) 637 | if(person>=1): 638 | avg_acc3_list.append(acc / person) 639 | if ((acc / person) > max_avg_acc3): 640 | max_avg_acc3 = (acc / person) 641 | else: 642 | avg_acc3_list.append(acc) 643 | 644 | video.release() 645 | info1.config(text=" ") 646 | # info2.config(text=" ") 647 | info1.config(text="Status : Detection & Counting Completed") 648 | # info2.config(text="Max. Human Count : " + str(max_count3)) 649 | cv2.destroyAllWindows() 650 | 651 | for i in range(len(framex3)): 652 | max3.append(max_count3) 653 | max_avg_acc3_list.append(max_avg_acc3) 654 | 655 | Button(windowc, text="Enumeration\nPlot", command=cam_enumeration_plot, cursor="hand2", font=("Arial", 20),bg="orange", fg="blue").place(x=100, y=530) 656 | Button(windowc, text="Avg. Accuracy\nPlot", command=cam_accuracy_plot, cursor="hand2", font=("Arial", 20),bg="orange", fg="blue").place(x=700, y=530) 657 | Button(windowc, text="Generate Crowd Report", command=cam_gen_report, cursor="hand2", font=("Arial", 20),bg="gray", fg="blue").place(x=325, y=550) 658 | 659 | lbl1 = tk.Label(windowc, text="DETECT FROM\nCAMERA", font=("Arial", 50, "underline"), fg="brown") # same way bg 660 | lbl1.place(x=230, y=20) 661 | 662 | Button(windowc, text="OPEN CAMERA", command=open_cam, cursor="hand2", font=("Arial", 20), bg="light green", fg="blue").place(x=370, y=230) 663 | 664 | info1 = tk.Label(windowc, font=("Arial", 30), fg="gray") # same way bg 665 | info1.place(x=100, y=330) 666 | # info2 = tk.Label(windowc, font=("Arial", 30), fg="gray") # same way bg 667 | # info2.place(x=100, y=390) 668 | 669 | # function defined to exit from the camera window 670 | def exit_winc(): 671 | if mbox.askokcancel("Exit", "Do you want to exit?", parent = windowc): 672 | windowc.destroy() 673 | windowc.protocol("WM_DELETE_WINDOW", exit_winc) 674 | 675 | 676 | # options ----------------------------- 677 | lbl1 = tk.Label(text="OPTIONS", font=("Arial", 50, "underline"),fg="brown") # same way bg 678 | lbl1.place(x=340, y=20) 679 | 680 | # image on the main window 681 | pathi = "Images/image1.jpg" 682 | imgi = ImageTk.PhotoImage(Image.open(pathi)) 683 | paneli = tk.Label(window1, image = imgi) 684 | paneli.place(x = 90, y = 110) 685 | 686 | # image on the main window 687 | pathv = "Images/image2.png" 688 | imgv = ImageTk.PhotoImage(Image.open(pathv)) 689 | panelv = tk.Label(window1, image = imgv) 690 | panelv.place(x = 700, y = 260)# 720, 260 691 | 692 | # image on the main window 693 | pathc = "Images/image3.jpg" 694 | imgc = ImageTk.PhotoImage(Image.open(pathc)) 695 | panelc = tk.Label(window1, image = imgc) 696 | panelc.place(x = 90, y = 415) 697 | 698 | # created button for all three option 699 | Button(window1, text="DETECT FROM IMAGE ➡",command=image_option, cursor="hand2", font=("Arial",30), bg = "light green", fg = "blue").place(x = 350, y = 150) 700 | Button(window1, text="DETECT FROM VIDEO ➡",command=video_option, cursor="hand2", font=("Arial", 30), bg = "light blue", fg = "blue").place(x = 110, y = 300) #90, 300 701 | Button(window1, text="DETECT FROM CAMERA ➡",command=camera_option, cursor="hand2", font=("Arial", 30), bg = "light green", fg = "blue").place(x = 350, y = 450) 702 | 703 | # function defined to exit from window1 704 | def exit_win1(): 705 | if mbox.askokcancel("Exit", "Do you want to exit?"): 706 | window1.destroy() 707 | 708 | # created exit button 709 | Button(window1, text="❌ EXIT",command=exit_win1, cursor="hand2", font=("Arial", 25), bg = "red", fg = "blue").place(x = 440, y = 600) 710 | 711 | window1.protocol("WM_DELETE_WINDOW", exit_win1) 712 | window1.mainloop() 713 | 714 | -------------------------------------------------------------------------------- /persondetection.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import tensorflow as tf 3 | # import cv2 4 | import time 5 | import os 6 | # import tensorflow.compat.v1 as tf 7 | import tensorflow._api.v2.compat.v1 as tf 8 | tf.disable_v2_behavior() 9 | 10 | 11 | class DetectorAPI: 12 | def __init__(self): 13 | path = os.path.dirname(os.path.realpath(__file__)) 14 | self.path_to_ckpt = f'frozen_inference_graph.pb' 15 | self.detection_graph = tf.Graph() 16 | 17 | with self.detection_graph.as_default(): 18 | od_graph_def = tf.GraphDef() 19 | with tf.gfile.GFile(self.path_to_ckpt, 'rb') as fid: 20 | serialized_graph = fid.read() 21 | od_graph_def.ParseFromString(serialized_graph) 22 | tf.import_graph_def(od_graph_def, name='') 23 | 24 | self.default_graph = self.detection_graph.as_default() 25 | self.sess = tf.Session(graph=self.detection_graph) 26 | 27 | # Definite input and output Tensors for detection_graph 28 | self.image_tensor = self.detection_graph.get_tensor_by_name('image_tensor:0') 29 | # Each box represents a part of the image where a particular object was detected. 30 | self.detection_boxes = self.detection_graph.get_tensor_by_name('detection_boxes:0') 31 | # Each score represent how level of confidence for each of the objects. 32 | # Score is shown on the result image, together with the class label. 33 | self.detection_scores = self.detection_graph.get_tensor_by_name('detection_scores:0') 34 | self.detection_classes = self.detection_graph.get_tensor_by_name('detection_classes:0') 35 | self.num_detections = self.detection_graph.get_tensor_by_name('num_detections:0') 36 | 37 | def processFrame(self, image): 38 | # Expand dimensions since the trained_model expects images to have shape: [1, None, None, 3] 39 | image_np_expanded = np.expand_dims(image, axis=0) 40 | # Actual detection. 41 | start_time = time.time() 42 | (boxes, scores, classes, num) = self.sess.run( 43 | [self.detection_boxes, self.detection_scores, 44 | self.detection_classes, self.num_detections], 45 | feed_dict={self.image_tensor: image_np_expanded}) 46 | end_time = time.time() 47 | 48 | # print("Elapsed Time:", end_time-start_time) 49 | # print(self.image_tensor, image_np_expanded) 50 | im_height, im_width, _ = image.shape 51 | boxes_list = [None for i in range(boxes.shape[1])] 52 | 53 | for i in range(boxes.shape[1]): 54 | boxes_list[i] = (int(boxes[0, i, 0] * im_height),int(boxes[0, i, 1]*im_width),int(boxes[0, i, 2] * im_height),int(boxes[0, i, 3]*im_width)) 55 | 56 | return boxes_list, scores[0].tolist(), [int(x) for x in classes[0].tolist()], int(num[0]) 57 | 58 | def close(self): 59 | self.sess.close() 60 | self.default_graph.close() -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | libraries used : python 3 2 | tkinter 3 | messagebox 4 | PIL 5 | cv2 6 | argparse 7 | matplotlib.pyplot 8 | numpy 9 | time 10 | os 11 | tensorflow 12 | fpdf --------------------------------------------------------------------------------