You are on page 1of 57

INDUSTRIAL TRAINING REPORT

ON

PROJECT “CRIMINAL ACTIVITY


DETECTION”
Int’l Centre for Free and Open Source Software (ICFOSS)

Submitted in partial fulfillment of the requirements


for the award of degree of

Bachelor of Technology
Information Technology

Submitted To: - Submitted By:- Samridhi Bhandari


Dr. Isha Singh (00113303119)

HMR INSITUTE OF TECHNOLOGY AND


MANAGEMENT
HAMIDPUR, DELHI -110036
Affiliated To

GURU GOBIND SINGH INDRAPRASTHA


UNIVERSITY
2019-23 1
00113303119-Samridhi Bhandari

DECLARATION

I, Samridhi Bhandari, Student of BTech ( I T) declare that the project titled

“CRIMINAL ACTIVITY DETECTION ” which is submitted by me to Department

of Information and Technology, HMR INSTITUTE OF TECHNOLOGY AND

MANAGEMENT,HAMIDPUR DELHI affiliated to Guru Gobind Singh Indraprastha

University.

Date: 14TH Dec 2021

Samridhi Bhandari

2
00113303119-Samridhi Bhandari

ACKNOWLEDGEMENT

The successful completion of this project mark the beginning of an ever - going

learning experience of converting ideas and concepts into real life, practical

system. This project was a quite a learning experience for me at each and every

step. At the same time it has given me confidence to work in professional setup.

I feel the experience gained during the project will lead me to gain the bright

prospect in the future. First of all I would like to give thanks to Head,

Education and Training, Mr. Devendra Kumar Mishra, for guiding us to

participate and undergo training and internship program , which not only has

increased our awareness about latest fields but also taught me the importance of

team building. With the deep sense of gratitude, I express my sincere thanks to Dr.

Isha Singh for her active support and continuous guidance without which it would

have been difficult for me to complete this project. I will also like to thank the

other working staff teachers at FOSS CELL,BPIT,Delhi for taking keen interest

in my project and giving valuable suggestions and helping me directly or

indirectly to complete this project.

SAMRIDHI

BHANDARI

00113303119

BTech (IT)

3
00113303119-Samridhi Bhandari

CERTIFICATE

4
00113303119-Samridhi Bhandari

CERTIFICATE FOR INTERNSHIP

5
00113303119-Samridhi Bhandari

ABSTRACT

The project “CRIMINAL ACTIVITY DETECTION “focuses on the problem of increasing

violence rate concerning guns and harmful weapons every year, becoming a challenge for

law enforcement agencies to deal with this issue on time. There are many places where the

crime rate caused by guns or knives is very high, especially in places where there are no gun

control laws. The early detection of violent crime is of paramount importance for citizens'

security. One way to prevent these situations is by detecting the presence of dangerous

weapons such as handguns and knives through surveillance videos. Present surveillance and

control systems still require manual monitoring and intervention. Here, we present a system

of automatic detection of weapons in the video, which is appropriate for surveillance and

control purposes. We have used the python code along with OpenCV for the detection of

weapons in real-time video. It focuses on a specific area of the image and trains each

component separately. The dataset is trained for classifying three classes of weapons

Handgun, Knife, and Heavy Guns. Once the weapon is detected, an alert beep will be sent to

authorities who can act accordingly and reduce the violent crimes before they take place.

6
00113303119-Samridhi Bhandari

CONTENTS

DECLARATION 2

ACKNOWLEDGEMENT 3

CERTIFICATE 4

ABSTRACT 5

CONTENTS 6

CHAPTER 1-INTRODUCTION

1.1 Organization Profile .........................................................................................8

1.2 Overview of Project .......................................................................................... 11

1.3 Literature Survey… ........................................................................................... 12

1.3.1 Machine Learning

1.3.2 Python Language

1.4 Problem Specification ....................................................................................... 12

1.5 Problem Definition ............................................................................................ 12

1.6 Limitation of Existing System........................................................................... 13

1.7 Scope of Study ....................................................................................................13

CHAPTER 2-SYSTEM ANALYSIS

2.1 General ................................................................................................................ 14

2.2 Introduction ........................................................................................................ 14


7
00113303119-Samridhi Bhandari

2.3 Preliminary Investigation..................................................................................15

2.4 Summary and Constraint… .............................................................................. 15

2.5 Feasible Study… ................................................................................................16

2.6 Types of Feasible Study ..................................................................................... 16

2.6.1 Technical Feasibility….......................................................... 17

2.6.2 Economic Feasibility… ............................................................... 17

2.6.3 Operational Feasibility… ....................................................... 18

2.7 Hardware and Software Specifications…........................................................ 18

2.8 Data Flow Diagram .......................................................................................... 19

CHAPTER 3-DEVELPOMENT ENVIRONMENT

3.1 Introduction to Python ...................................................................................... 18

3.1.1 Uses of Python ............................................................................... 19

3.1.2 Facts about Python ............................................................. 20

3.2 Introduction to Microsoft Virtual Studio Code ..............................................23

3.2.1 Language Support… ........................................................................... 23

3.2.2 Data Collection............................................................................23

3.2.3 Version Control… ....................................................................... 24

3.3 CodeSnack IDE… ............................................................................................... 24

3.4 PyCharm ......................................................................................................... 24

8
00113303119-Samridhi Bhandari

CHAPTER 4-SYSTEM DESIGN

4.1 Modular Description ........................................................................................ 31

4.2 User Interface Design ....................................................................................... 32

CHAPTER 5-TESTING

5.1 Testing Technique & Testing Strategies ......................................................... 33

5.2 Debugging & Code Improvement… ...............................................................35

CHAPTER 6-CODES

CHAPTER 7-IMPLEMENTATION

7.1 System Implementation .............................................................................. 37

7.2 Screenshots ....................................................................... 38

7.3 Software Installation............................................................................... 39

CONCLUSION & FUTURE SCOPE… .................................................................. 44

BIBLIOGRAPHY… .......................................................................................................... 47

9
00113303119-Samridhi Bhandari

CHAPTER 1

INTRODUCTION

1.1 ORGANISATION PROFILE:

1.1.1 ABOUT

ICFOSS (International Centre for Free and Open Source Software)

International Centre for Free and Open Source Software (ICFOSS) is an autonomous

organization set up by the Government of Kerala, India and having the combined mandate of

popularizing Free and Open Source Software for universal use; consolidating the early FOSS

work done in Kerala; and networking with different nations, communities and governments

to collaboratively promote FOSS. ICFOSS is the outcome of a decade of work by Free

Software enthusiasts, advocates, developers and supporters in the state of Kerala and outside.

Recognizing the strides made by the FOSS community in Kerala, and sensing a need to do

more, the Government of Kerala, in 2008, had set up a Committee headed by Prof Rahul De

of IIM Bangalore to recommend what further could be done to support the cause of FOSS.

10
00113303119-Samridhi Bhandari

The FOSS Cell Programme of ICFOSS aims to provide promotional services of FOSS to

educational institutions by promoting the formation of a group of interested students and

teachers in the institution, called the FOSS Cell, on a voluntary basis.

1.1.2 Vision

The vision of the FOSS Cell is to encourage and promote the use of Free and Open

Source Software and related areas such as Open Hardware, amongst the students and

teachers of the institution for every possible kind of use.

1.1.3 Mission

The FOSS Cell shall carry this out through associating with ICFOSS and its programmes, as

well as with other FOSS community, industry and research organizations, and taking up

programmes including training & capacity building, student projects, lectures & seminars,

conferences and exhibitions, by participating at the institutional level as well as inter-

institutional, state, national and international levels.

The Student Ambassadors of ICFOSS will support this mission. Where student 11
00113303119-Samridhi Bhandari

ambassadors are not available for a particular institution, ICFOSS will directly assist to the

extent possible.

1.1.4 Objectives

• Identify and quantify the political, cultural and economic benefits for India as a result of

FOSS. This would not just be restricted to software but also to issues like patents,

copyright, digital content, scientific publishing etc.

• Develop an action plan aimed at making India a global leader in the open source

community Leverage the open source development model based on community,

collaboration and shared ownership of intellectual resources to bridge the digital divide

• Create a road-map for open source software development for India's software export

industry

• Take the lead role in identifying technologies for different applications for the

government, public enterprises, educational institutions, small business, individuals and

other key sectors.

Organisation website https://icfoss.in/home

12
00113303119-Samridhi Bhandari

1.1.6 FOSS Training

ICFOSS trainings and workshops are mainly aimed at the development and promotion of

FOSS initiatives among the students, Faculty, professionals and Government employees to

make them competent and aware of the benefits of using FOSS applications and tools in tune

with the e-policy of Governments. It also popularize and familiarise the concept and use of

Open Source Operating Systems and softwares to improve operational skills of people.

ICFOSS has started trainings on the above concepts and currently within emphasis to FOSS

based support services to public as well as private sector employees, innovators, young

graduates and students. We are also providing capacity building programmes for

Government employees (Secretariat and Line Departments in State Government ),

Researchers, Students, Professionals, Academicians etc. We have trained around 6,000

people from the year 2017. We are also engage in conducting various FDPs (Faculty

Development Programmes) to academic community.

1.1.7 FOSS Cell

To promote the use of FOSS (Free and Open Source Software) technologies and

applications among students and faculties and to encore them in contributing towards the

community development in FOSS, ICFOSS has initiated setting up of FOSS Cells in

educational institutions, in the year 2015. The Cell’s activities are bound in participation

with the members of the institutions and ICFOSS. These deeds of the Cell aim in promoting

FOSS activities through a group of interested students and teachers (Faculty Development

Programmes) of the institution, on a voluntary basis.

13
00113303119-Samridhi Bhandari

1.2 OVERVIEW OF PROJECT

1.2.1 INTRODUCTION

During my course duration I had built a project based on Machine Learning in python language.

Below is a gist of the project along with running code and attached output. In brief the project lets

a user detect the number of time gun I detected in a frame during the whole duration of video.

1.1 LITERATURE SURVEY

Latest Research papers and articles based on Criminal Activity Detection project were

deeply studied and in this section a brief summary about the same is provided.

Major Technologies used for making this project are Machine learning and python

programming.

Giving a brief introduction about both of them below:

1.1.1 Machine Learning


Machine learning (ML) is the study of computer algorithms that can improve

automatically through experience and by the use of data.[1] It is seen as a part of

artificial intelligence. Machine learning algorithms build a model based on sample

data, known as training data, in order to make predictions or decisions without

being explicitly programmed to do so.[2] Machine learning algorithms are used in

a wide variety of applications, such as in medicine, email filtering, speech

recognition, and computer vision, where it is difficult or unfeasible to develop

conventional algorithms to perform the needed tasks.[3]

A subset of machine learning is closely related to computational statistics,

which focuses on making predictions using computers; but not all machine

learning is statistical learning. The study of mathematical 14


optimization delivers methods, theory and application domains to the field of
00113303119-Samridhi Bhandari

machine learning.

Why is machine learning important?

Machine learning is important because it gives enterprises a view of trends in

customer behavior and business operational patterns, as well as supports the

development of new products. Many of today's leading companies, such as

Facebook, Google and Uber, make machine learning a central part of their

operations. Machine learning has become a significant competitive differentiator

for many companies.

What are the different types of machine learning?

Classical machine learning is often categorized by how an algorithm learns to

become more accurate in its predictions. There are four basic approaches:

supervised learning, unsupervised learning, semi-supervised learning and

reinforcement learning. The type of algorithm data scientists choose to use

depends on what type of data they want to predict.

 Supervised learning: In this type of machine learning, data scientists supply

algorithms with labeled training data and define the variables they want the

algorithm to assess for correlations. Both the input and the output of the algorithm

is specified.

 Unsupervised learning: This type of machine learning involves algorithms

that train on unlabeled data. The algorithm scans through data sets looking for

15
00113303119-Samridhi Bhandari

any meaningful connection. The data that algorithms train on as well as the

predictions or recommendations they output are predetermined.

 Semi-supervised learning: This approach to machine learning involves a

mix of the two preceding types. Data scientists may feed an algorithm mostly

labeled training data, but the model is free to explore the data on its own and

develop its own understanding of the data set.

 Reinforcement learning: Data scientists typically use reinforcement

learning to teach a machine to complete a multi-step process for which there

are clearly defined rules. Data scientists program an algorithm to complete a

task and give it positive or negative cues as it works out how to complete a

task. But for the most part, the algorithm decides on its own what steps to

take along the way.

How does supervised machine learning work?

Supervised machine learning requires the data scientist to train the algorithm with

both labeled inputs and desired outputs. Supervised learning algorithms are good

for the following tasks:

 Binary classification: Dividing data into two categories.

 Multi-class classification: Choosing between more than two types of

answers.

 Regression modeling: Predicting continuous values.

16
00113303119-Samridhi Bhandari

 Ensembling: Combining the predictions of multiple machine learning models

to produce an accurate prediction.

How does unsupervised machine learning work?

Unsupervised machine learning algorithms do not require data to be labeled. They

sift through unlabeled data to look for patterns that can be used to group data

points into subsets. Most types of deep learning, including neural networks, are

unsupervised algorithms. Unsupervised learning algorithms are good for the

following tasks:

 Clustering: Splitting the dataset into groups based on similarity.

 Anomaly detection: Identifying unusual data points in a data set.

 Association mining: Identifying sets of items in a data set that frequently

occur together.

 Dimensionality reduction: Reducing the number of variables in a data set.

What are the advantages and disadvantages of machine learning?

Machine learning has seen use cases ranging from predicting customer

behavior to forming the operating system for self-driving cars.

When it comes to advantages, machine learning can help enterprises

understand their customers at a deeper level. By collecting customer data and

correlating it with behaviors over time, machine learning algorithms can

learn associations and help teams tailor product development and marketing

initiatives to customer demand.


17
00113303119-Samridhi Bhandari

1.1.2 Python Language

Python is an interpreted high-level general-purpose programming language. Its

design philosophy emphasizes code readability with its use of significant

indentation. Its language constructs as well as its object-oriented approach aim to

help programmers write clear, logical code for small and large-scale projects.

Python is dynamically-typed and garbage-collected. It supports

multiple programming paradigms, including structured (particularly, procedural),


object-oriented and functional programming. It is often described as a "batteries

included" language due to its comprehensive standard library.

Guido van Rossum began working on Python in the late 1980s, as a successor to

the ABC programming language, and first released it in 1991 as

Python 0.9.0. Python 2.0 was released in 2000 and introduced new features, such

as list comprehensions and a cycle-detecting garbage collection system (in

addition to reference counting). Python 3.0 was released in 2008 and was a major

revision of the language that is not completely backward-compatible. Python 2

was discontinued with version 2.7.18 in 2020.

Python consistently ranks as one of the most popular programming languages.

Python Documentation by Version

Python 3.10.1, documentation released on 6 December 2021.

Python 3.10.0, documentation released on 4 October 2021.

Python 3.9.9, documentation released on 15 November 2021.

18
00113303119-Samridhi Bhandari

Python 3.9.8, documentation released on 05 November 2021.

Python 3.9.7, documentation released on 30 August 2021.

Python 3.9.6, documentation released on 28 June 2021.

Python 3.9.5, documentation released on 3 May 20

Python 3.9.4, documentation released on 4 April 2021.

Python 3.9.3, documentation released on 2 April 2021.

Python 3.9.2, documentation released on 19 February 2021.

Python 3.9.1, documentation released on 8 December 202

19
00113303119-Samridhi Bhandari

1.2 PROBLEM SPECIFICATION:

This problem is assigned to me during my Machine Learning/AI training to create a project on

“Criminal Activity Detection” using Python3.6 and OpenCV applying Machine learning

techniques.

1.3 PROBLEM DEFINITION:

A folder is made in which python code of project is stored along with libraries and sample

video/videos in which the gun detection operation is to be performed. Along with these files a

.rar file is been stored to hear audio/beep whenever a gun is detected in the frame during the

running video.

This project works by giving the specific path i.e. name of the video provided in that folder,

then after saving the file we run the python code on python3.6 IDE. For the output part, the

whole video runs on our screen and the algorithm set by us detects the guns in frame by

indicating green color box around the gun in each frame. At left bottom of the video we

could see the exact date and time when the gun was detected in video. With every gun

detection we hear a beep. After the whole video gets over we observe the total number of

times the gun was detected on python shell.

20
00113303119-Samridhi Bhandari

1.4 LIMITATION OF EXISTING SYSTEM:

1.4.1 Correct path of video entered during input

During the compilation we are supposed to provide the path of video(the file

must be in same folder as that of the code).It is important to enter correct

path inorder to get desired result.The format of file must me .amp or .mp4

1.6.Detecting real gun and fake/toy gun

We have implemented binary classification assuming pistol class as the

reference class and relevant confusion objects inclusion concept is

introduced to reduce false positives and false negatives.

1.6.3 Unsatisfactory security measures:

A password key could be included into the system so that only the official

user with valid ID could access the recording and detect the crime.This

ensures the data security and protection from hackers.

1.6.4 Videos with .mp4 could be detected

The exising system was able to detect only videos with .amp format but now

even .mp4 files with whatsoever duration could also be detected in the given

system. Hence increasing the range of detection i.e. more optimized system.

1.5 SCOPE OF STUDY


Despite state-of-the-art deep learning algorithms, fast processing hardware, and advanced

CCTV cameras, weapon detection in real-time is still a serious challenge. Observing angle

differences, occlusions by the carrier of the firearm and persons around it further enhances

21
00113303119-Samridhi Bhandari

the difficulty of the challenge. This work focuses on providing the user with exact date and

time when the gun is detected in the frame of given sample video. As a gun is detected we

hear a beep sound from our system. After the whole video ends ,we get an output on python

shell indicating the total number of detections .We have implemented binary classification

assuming pistol class as the reference class and relevant confusion objects inclusion concept

is introduced to reduce false positives and false negatives. No standard dataset was available

for real-time scenario so we made our own dataset by making weapon photos from our own

camera, manually collected images from internet, extracted data from YouTube CCTV

videos, through GitHub repositories. Two approaches are used i.e. sliding

window/classification and region proposal/object detection. Precision and recall count the

most rather than accuracy when object detection is performed .The project is executed in

python language.

22
00113303119-Samridhi Bhandari

CHAPTER-2
FEASIBILITY STUDY

An initial investigation in a proposal that determines whether an alternative system is


feasible. A proposal summarizing

the thinking of the analyst is presented to the user for review. When approved, the proposal
initiates feasibility study that describes and evaluates candidate systems and provides
for the selection of best system that meets system performance requirements.
To do a feasibility study, we need to consider the economic, technical factors in system
development. First a project team is formed. The team develops system flowcharts that
identify the characteristics of candidate systems, evaluate the performance of each system,
weigh system performance and cost data and select the best candidate system for the
job. The study culminates in a final report to the management.

INTRODUCTION:

1. Describe and identify characteristics of candidate systems.


2. Determine and evaluate performance and cost effectiveness of each
candidate system.
3. Weigh system performance and cost data.
4. Select the best candidate system.

SUMMARY:

1. A feasibility study is conducted to select the best system that meets performance
requirements. This entails an identification description, an evaluation of candidate
systems, and the selection of the best system for the job.
2. A statement of constraints, the identification of specific system objectives and a
description of outputs define a system’s required performance. The analyst is then
ready to evaluate the feasibility of candidate systems to produce these outputs.
3. Three key considerations are involved in feasibility analysis: economic, technical
and behavioral.

23
00113303119-Samridhi Bhandari

4. There are few steps in feasibility study:


STATEMENT OF CONSTRAINTS: - Constraints are factors that limit
the solution of a problem. Some constraints are identified during the initial
investigation

5. IDENTIFICATION OF SPECIFIC SYSTEM OBJECTIVES:


- Once the constraints are spelled out, the analyst proceeds to identify the system’s
specific performance objectives. They are derived from the general objectives
specified in the project directive at the end of the initial investigation. The steps
are to state the system’s benefits and then translate them into measurable
objectives.

6. DESCRIPTION OF OUTPUTS: - A final step in system performance


definition is describing the output required by the user. An actual sketch of the
format and contents of the reports as well as a specification of the media used, their
frequency, size and numbers of copies required are prepared at this point

TYPES OF FEASIBLE STUDY :-

• Legal Feasibility: - Determines whether the proposed system conflicts


with legal requirements, e.g. a data processing system must comply with
the local Data Protection Acts.
• Operational Feasibility: -Operational feasibility is a measure of
how well a proposed system solves the problems, and takes advantage
of the opportunities identified during scope definition and how it
satisfies the requirements identified in the requirements analysis
phase of system development.
The operational feasibility assessment focuses on the degree to
which the proposed development projects fits in with the existing
business environment and objectives with regard to development
schedule, delivery date, corporate culture, and existing business
processes.
To ensure success, desired operational outcomes must be imparted
during design and development. These include such design-
dependent parameters such as reliability, maintainability,
supportability, usability, predictability, disposability, sustainability,
affordability and others. These parameters are required to be
considered at the early stages of design if desired operational

24
00113303119-Samridhi Bhandari

behaviors are to be realized. A system design and development requires appropriate and
timely application of engineering and management efforts to meet the previously
mentioned parameters. A system may serve its intended purpose most effectively
when its technical and operating characteristics are engineered into the design. Therefore
operational feasibility is a critical aspect of systems engineering that needs to be an
integral part of the early design phases
i. Economic Feasibility: -The purpose of the economic feasibility
assessment is to determine the positive economic benefits to the
organization that the proposed system will provide. It includes
quantification and identification of all the benefits expected. This
assessment typically involves a cost/ benefits analysis.

ii. Technical Feasibility: -The technical feasibility assessment is


focused on gaining an understanding of the present technical resources
of the organization and their applicability to the expected needs of the
proposed system. It is an evaluation of the hardware and software and
how it meets the need of the proposed system.

25
00113303119-Samridhi Bhandari

HARDWARE AND SOFTWARE REQUIREMENTS

1. HARDWARE REQUIREMENT:-

 PROCESSOR : Pentium IV processor or Greater


 RAM : 128 Mega Byte (MB) or Greater
 HARDDISK : 1.2 Giga Byte (GB) or Greater
 Keyboard & Mouse
 MONITOR : Colour (For Best Result)
 Printer

2. SOFTWARE REQUIREMENTS:-

 Operating System : Windows 2000/ XP /7/8


 Python IDE
 OpenCV
 PyCharm
 Microsoft Visual Studio Code
 CodeSnack IDE
 Python 3.6

26
00113303119-Samridhi Bhandari

DATA FLOW DIAGRAM (DFD)

27
00113303119-Samridhi Bhandari

CHAPTER-3

DEVELOPMENT ENVIROMENT

3.1 INTRODUCTION TO PYTHON

• Python was founded by Gudio Van rossum in 1995.

• Python is an interpreted high-level general purpose programming language.

• Its design philosophy emphasizes code readability with its use of significant

indentation.

• Its language constructs as well as its object-oriented approach aim to help

programmers write clear, logical code for small and large-scale projects.

• Python is dynamically-typed and garbage-collected.

• It supports programming paradigms including structured (particularly, procedural),

object-oriented and functional programming.

• Python's simple, easy to learn syntax emphasizes readability and therefore reduces

the cost of program maintenance.

• Python is easy to understand for writing new software – it’s often possible to write

code faster .

• Python easy to understand it’s also often easier to understand someone else’s code

faster .

• Lots of IT project testers have started using Python to carry out repeatable test

procedures.

3.1.1 USES OF PYTHON

Python is a popular and in-demand skill to learn. But what is python programming
28
00113303119-Samridhi Bhandari

used for? We’ve already briefly touched on some of the areas it can be applied to,

and we’ve expanded on these and more Python examples below.

Python can be used for:

AI and Machine Learning

Python is such a stable, flexible, and simple programming language, it’s perfect for various

machine learning (ML) and artificial intelligence (AI) projects. In fact, Python is among the

favourite languages among data scientists, and there are many Python machine learning and

AI libraries and packages available.

Data Analytics

Much like AI and machine learning, data analytics is another rapidly developing field that

utilises Python programming. At a time when we’re creating more data than ever before, there

is a need for those who can collect, manipulate and organise the information. Python for data

science and analytics makes sense. The language is easy-to-learn, flexible, and wellsupported,

meaning it’s relatively quick and easy to use for analysing data. When working with large

amounts of information, it’s useful for manipulating data and carrying out repetitive tasks.

Data Visualisation

Data visualisation is another popular and developing area of interest. Again, it plays into many

of the strengths of Python. As well as its flexibility and the fact it’s open-source, Python

provides a variety of graphing libraries with all kinds of features. Whether you’re looking to

create a simple graphical representation or a more interactive plot, you can find a library to

match your needs. Examples include Pandas Visualization and Plotly. The possibilities are

29
00113303119-Samridhi Bhandari

vast, allowing you to transform data into meaningful insights.

Programming Applications

You can program all kinds of applications using Python. The general-purpose language can

be used to read and create file directories, create GUIs and APIs, and more. Whether it’s

blockchain applications, audio and video apps, or machine learning applications, you can build

them all with Python.

Web development

Python is a great choice for web development. This is largely due to the fact that there are

many Python web development frameworks to choose from, such as Django, Pyramid, and

Flask. These frameworks have been used to create sites and services such as Spotify, Reddit

and Mozilla. The extensive libraries and modules that come with Python frameworks,

functions such as database access, content management, and data authorisation are all possible

and easily accessible. Given its versatility, it’s hardly surprising that Python is so widely used

in web development.

Game development

Although far from an industry-standard in game development, Python does have its uses in

the industry. It’s possible to create simple games using the programming language, which

means it can be a useful tool for quickly developing a prototype. Similarly, certain functions

(such as dialogue tree creation) are possible in Python.

3.1.2 FACTS ABOUT PYTHON

Python is one of the most emerging programming languages.


30
 It is a high-level programming
00113303119-Samridhi Bhandari

language that has user-friendly syntax. It is known to have fewer lines of code in
an easy and simple form.

Python is extensively used by many large organizations. Besides all

these technical aspects, there are amazing Python facts as well.

Nomenclature fact of Python

This name ‘Python’ is extracted from a British comedy series, “Monty Python’s Flying

Circus”. It is not named a snake. It is said that this was the favorite series of its inventor Guido

Van Rossum. He named it Python because it is short, mysterious and unique.

 Python follows chain comparison

In Python, there can be multiple comparisons at once. It is able to check multiple conditions

at the same time. While in other programming languages, you can not program a chain of

comparison operators.

The comparison operators can be chained randomly. It does not have to follow a particular

order of operators.

 Python does not need compiler

Python relies on an interpreter. Unlike other programming languages, it does not need a

compiler.

The code is stored in a .pyc file. This file acts as a dynamic engine for Python eliminating the

need of any compiler.

 Python does not enhance the use of pointer

In Python, every program is done by reference. It does not support pointer.

31
00113303119-Samridhi Bhandari

 Python has a variant of C and Java

Python has incorporated the variants of C and Java such as CPython, Jython, etc. The C variant

is

CPython, to give Python the glimpse benefits of C language. It is because CPython is

beneficial in

terms of performance, as it has both a compiler and an interpreter.

 Python can implement the ‘else’ clause within ‘for’ loop

Unlike other languages, Python is the only language that can use else within for a loop. This

will be true only when the loop exists nature.

3.2 Microsoft Visual Studio Code

Visual Studio Code is a source-code editor made

by Microsoft for Windows, Linux and macOS. Features include support

for debugging, syntax highlighting, intelligent code completion, snippets, code

refactoring, and embedded Git. Users can change the theme, keyboard shortcuts,

preferences, and install extensions that add additional functionality.

Visual Studio Code is a source-code editor that can be used with a variety of

programming languages,

including Java, JavaScript, Go, Node.js, Python and C++. It is based on

the Electron framework, which is used to develop Node.js Web applications that

32
00113303119-Samridhi Bhandari

run on the Blink layout engine. Visual Studio Code employs the same editor

component (codenamed "Monaco") used in Azure DevOps (formerly called Visual

Studio Online and Visual Studio Team Services).20]

This allows it to operate as

a language-agnostic code editor for any language. It supports a number of

programming languages and a set of features that differs per language. Unwanted

files and folders can be excluded from the project tree via the settings. Many

Visual Studio Code features are not exposed through menus or the user interface

but can be accessed via the command palette.

Visual Studio Code can be extended via extensions, available through a central

repository. This includes additions to the editor and language support. A notable

feature is the ability to create extensions that add support for

new languages, themes, and debuggers, perform static code analysis, and add code

linters using the Language Server Protocol.


3.3 Code Snack IDE

33
00113303119-Samridhi Bhandari

CodeSnack is the first mobile IDE made from the ground up for iPhone and iPad. It provides

you with fast and easy-to-use tools that make it possible for anyone to create great programs,

learn how to code by samples, and deploy real-world back-end and front-end apps within

minutes — for free.

CodeSnack is the first mobile IDE made from the ground up for iPhone and

iPad. It provides you with fast and easy-to-use tools that make it possible for

anyone to create great programs, learn how to code by samples, and deploy

real-world back-end and front-end apps within minutes — for free.

Getting started takes seconds, and you don't need to be a strong coder or have

server administrator's skills to learn how to use it. With CodeSnack IDE, you

get all the control and flexibility you need to make things your way without

any compromise.

Everything you can do with CodeSnack IDE:

- Write & run real code (like on PC, Mac, or Linux)

- Use any programming language

- Use your favorite hardware keyboard and shortcuts

- Debug program output, and see detailed error logs (in real-time)

- Practice to code with examples library (we have 1000+ examples to check

out)

34
00113303119-Samridhi Bhandari

- Sync your projects between all your devices

- Install complex dependencies and Linux libraries

And so much more!

This is the only mobile application supporting many programming languages

for coding:

* Java

* Python

*C

* C++

* C#

* Dart

* JavaScript

* TypeScript

* PHP

* Shell

* Swift

35
00113303119-Samridhi Bhandari

* Ruby

* Go

* Kotlin

* Lua

* Haskell

Subscription benefits:

- Up to 8x faster

- Sync between all your devices

- Upload code to your server using SFTP

- Virtual keyboard customization

- Unlock all chapters from the code library

- Access extra color schemas

- No ads

3.4 PyCharm

PyCharm is an integrated development environment (IDE) used in computer

programming, specifically for the Python language. It is developed by the

Czech company JetBrains (formerly known as IntelliJ).[5] It provides code

36
00113303119-Samridhi Bhandari

analysis, a graphical debugger, an integrated unit tester, integration with

version control systems (VCSes), and supports web development with Django

as well as data science with Anaconda.

PyCharm is cross-platform, with Windows, macOS and Linux versions. The

Community Edition is released under the Apache License,[7] and there is also

Professional Edition with extra features – released under a proprietary license.

FeaturesEditCoding assistance and analysis, with code completion, syntax

and error highlighting, linter integration, and quick fixesProject and code

navigation: specialized project views, file structure views and quick jumping

between files, classes, methods and usagesPython refactoring: includes

rename, extract method, introduce variable, introduce constant, pull up, push

down and othersSupport for web frameworks: Django, web2py and Flask

[professional edition only][8]Integrated Python debuggerIntegrated unit

testing, with line-by-line code coverageGoogle App Engine Python

development [professional edition only]Version control integration: unified

user interface for Mercurial, Git, Subversion, Perforce and CVS with change

lists and mergeSupport for scientific tools like matplotlib, numpy and scipy .

It competes mainly with a number of other Python-oriented IDEs, including

Eclipse's PyDev, and the more broadly focused Komodo IDE.

PyCharm provides an API so that developers can write their own plugins to

extend PyCharm features. Several plugins from other JetBrains IDE also

37
00113303119-Samridhi Bhandari

work with PyCharm. There are more than 1000 plugins which are compatible

with PyCharm.

38
00113303119-Samridhi Bhandari

CHAPTER_4
SYSTEM DESIGN

4.1MODULAR DESCRIPTION

4.1.1 LOGIN AND REGISTRATION: -In this module new student or user
requires to enter his all details that’s has been asked to enter in signup form.
No field be remain unfilled.

All these details gets stored in the database, creating record for each student also
these details can be accessed further.

4.1.2 CHOICE OF SUBJECTS :- Here the students are new and want to
explore their potential. So the choice is given to them in the form of
topic/subjects, in which they can take the quiz in which they are
comfortable, so as to evaluate their performance and enhance their scope of
further improvement
.

4.1.3 CATEGORIES OF SUBJECTS:-

4 RESULT GENERATION: At the end of the quiz i.e. the 8 MCQ’s the
result will be generated when the user or student submit his test. The result is
generated based on the student’s performance or his inputs. The result will
enable the user to access his performance and improve it.

39
00113303119-Samridhi Bhandari

CHAPTER-5
TESTING

5.1 TESTING TECHNIQUES AND STRATEGIES:-

Testing is the process of exercising software with the intent of finding errors and

ultimately correcting them. The following testing techniques have been used to make this

project free of errors.

Content Review

The whole content of the project has been reviewed thoroughly to uncover

typographical errors, grammatical error and ambiguous sentences.

Navigation Errors

Different users were allowed to navigate through the project to uncover the navigation

errors. The views of the user regarding the navigation flexibility and user friendliness were

taken into account and implemented in the project.

Unit Testing

Focuses on individual software units, groups of related units.

 Unit – smallest testable piece of software.

 A unit can be compiled /assembled / linked/loaded; and put under a test

harness.

 Unit testing done to show that the unit does not satisfy the application and

 /or its implemented software does not match the intended designed structure.

Integration Testing

Focuses on combining units to evaluate the interaction among them

40
00113303119-Samridhi Bhandari

 Integration is the process of aggregating components to create larger

components.

 Integration testing done to show that even though components were

individually satisfactory, the combination is incorrect and inconsistent.

System testing

Focuses on a complete integrated system to evaluate compliance with specified

requirements (test characteristics that are only present when entire system is run)

 A system is a big component.

 System testing is aimed at revealing bugs that cannot be attributed to a component as

such, to inconsistencies between components or planned interactions between

components.

 Concern: issues, behaviors that can only be exposed by testing the entire integrated

system (e.g., performance, security, recovery)each form encapsulates (labels, texts,

grid etc.). Hence in case of project in V.B. form are the basic units. Each form is tested

thoroughly in term of calculation, display etc.

Regression Testing

Each time a new form is added to the project the whole project is tested thoroughly to

rectify any side effects. That might have occurred due to the addition of the new form.

Thus regression testing has been performed.

White-Box testing

White-box testing (also known as clear box testing, glass box testing, transparent box

testing and structural testing) tests internal structures or workings of a program, as opposed

to the functionality exposed to the end-user. In white-box testing an internal

41
00113303119-Samridhi Bhandari

perspective of the system, as well as programming skills, are used to design test cases. The

tester chooses inputs to exercise paths through the code and determine the appropriate

outputs.

This is analogous to testing nodes in a circuit, e.g. in-circuit testing (ICT).

While white-box testing can be applied at the unit, integration and system levels of the

software testing process, it is usually done at the unit level. It can test paths within a

unit, paths between units during integration, and between subsystems during a system–

level test. Though this method of test design can uncover many errors or problems, it might

not detect unimplemented parts of the specification or missing requirements.

Techniques used in white-box testing include:

 API testing (application programming interface) – testing of the application using

public and private APIs

 Code coverage – creating tests to satisfy some criteria of code coverage (e.g., the

test designer can create tests to cause all statements in the program to be executed at

least once)

 Fault injection methods – intentionally introducing faults to gauge the efficacy of

testing strategies.

Code coverage tools can evaluate the completeness of a test suite that was created

with any method, including black-box testing. This allows the software team to

examine parts of a system that are rarely tested and ensures that the most important

function points have been tested. Code coverage as a software metric can be reported

as a percentage for:

Function coverage, which reports on functions executed

42
00113303119-Samridhi Bhandari

Statement coverage, which reports on the number of lines executed to complete the test

100% statement coverage ensures that all code paths, or branches (in terms of control

flow) are executed at least once. This is helpful in ensuring correct functionality, but not

sufficient since the same code may process different inputs correctly or incorrectly.

Black-box testing

Black-box testing treats the software as a "black box", examining functionality without

any knowledge of internal implementation. The tester is only aware of what the software

is supposed to do, not how it does it. Black-box testing methods include: equivalence

partitioning, boundary value analysis, all-pairs testing, state transition tables, decision

table testing, fuzz testing, model-based testing, use case testing, exploratory testing and

specification-based testing.

Specification-based testing aims to test the functionality of software according to the

applicable requirements. This level of testing usually requires thorough test cases to be

provided to the tester, who then can simply verify that for a given input, the output

value (or behaviour), either "is" or "is not" the same as the expected value specified in the

test case. Test cases are built around specifications and requirements, i.e., what the

application is supposed to do. It uses external descriptions of the software, including

specifications, requirements, and designs to derive test cases. These tests can be functional

or non-functional, though usually functional.

Specification-based testing may be necessary to assure correct functionality, but it is

insufficient to guard against complex or high-risk situations.

One advantage of the black box technique is that no programming knowledge is required.

43
00113303119-Samridhi Bhandari

Whatever biases the programmers may have had, the tester likely has a different set and

may emphasize different areas of functionality. On the other hand, black-box testing has

been said to be "like a walk in a dark labyrinth without a flashlight." Because they do

not examine the source code, there are situations when a tester writes many test cases

to check something that could have been tested by only one test case, or leaves some parts

of the program untested.

This method of test can be applied to all levels of software testing: unit, integration, system

and acceptance. It typically comprises most if not all testing at higher levels, but can

also dominate unit testing as well.

Alpha Testing

Alpha testing is simulated or actual operational testing by potential users/customers or

an independent test team at the developers' site. Alpha testing is often employed for

off-the-shelf software as a form of internal acceptance testing, before the software goes to

beta testing.

Beta Testing

Beta testing comes after alpha testing and can be considered a form of external user

acceptance testing. Versions of the software, known as beta versions, are released to a

limited audience outside of the programming team. The software is released to groups of

people so that further testing can ensure the product has few faults or bugs. Sometimes,

beta versions are made available to the open public to increase the feedback field to a

maximal number of future users.

5.2 DEBUGGING AND CODE IMPROVEMENT

44
00113303119-Samridhi Bhandari

5.2.1 Debugging

Developers often find themselves in situations where the code they've written

is not working quite right. When that happens, a developer debugs their code

by instrumenting, executing and inspecting the code to determine what state

of the application does not match the assumptions of how the code should be

correctly running.

Why is debugging important?

There are bugs in every modest sized or larger application. Every developer

has to learn how to debug code in order to write programs that work as

correctly as time and budget allow.

In addition to fixing bugs, debugging is an important skill for improving the

efficiency of an application by optimizing performance and improving the

logic. Debugging is a complex skill that takes time and practice for a

developer to gain as a capability.

What are some common debugging techniques?

Some common debugging techniques include:

 Printing out or displaying values of variables and state at certain times

during the execution of an application

 Changing the state of a program to make it do different things. This is

called altering the "path" of the program

 Stepping through the execution of a program line by line

45
00113303119-Samridhi Bhandari

 Breakpoints

 Trace Points

 Stopping the program at certain events

 Viewing the output of a program in a debugger window

5.2.2 Debugging tools

There are many debugging tools, some of which are built

into IDEs like PyCharm and others that are standalone applications. The

following list contains mostly standalone tools that you can use in

any development environment.

 pdb is a debugger built into the Python standard library and is the one most developers

come across first when trying to debug their programs.

 Web-PDB provides a web-based user interface for pdb to make it easier to understand

what is happening while inspecting your running code.

 wdb uses WebSockets to allow you to debug running Python code from a web browser.

 Pyflame (source code) is a profiling tool that generates flame graphs for executing Python

program code.

 objgraph (source code) uses graphviz to draw the connections between Python objects

running in an application

46
00113303119-Samridhi Bhandari

5.2.3 For Code Improvement:

1.UseBuilt-InFunctions

Built-in function in any language is always useful because you don’t need to write

your code from scratch. The same goes for Python. Python comes with many

useful libraries and built-in functions. These libraries are helpful in writing the

features at several places in your development project. You can write high-quality,

efficient code, but it is difficult to beat the underlying libraries. Python

libraries are optimized and tested rigorously (like your code). These built- in

functions are easy to use in your project. You won’t have redundant code in your

project and the code will be optimized very well. 2.WriteYourOwnGenerator

In Python use generator wherever it is possible. It allows you to return a single

item at a time instead of returning the items all at once. Xrange() function is a

generator in Python 2, similar to the range() function in Python 3. If

you’re using lists, you should write your own generator. Generators give you lazy

evaluation and memory will be used efficiently. Generators are very useful if

you’re reading numerous large files. You can process a single chunk without

worrying about the size of the files.

3.UseListComprehensions

//

4.Usexrange()Insteadofrange()

square_numbers
In Python = loops
2, to iterate over [] for n
weincan
range(0,10):
use range()ifand
n %xrange()
2 == 1: fun ctions. The
square_numbers.append(n**2)

first function stores all the numbers in the range in memory, and it got linearly

large as range did. Other function xrange() return the generator object. If you loop
47
00113303119-Samridhi Bhandari

with these object numbers will be available in memory only on demand.

The above code returns 560064. If you use xrange with the same range, it will

return 40. If you’re writing your application in Python 2, Then swapping functions

will create a big impact on memory usage. In Python 3 xrange() functionality is

implemented by default. If there is no xrange() function, then the range() function

5.UseSetsandUnions

If you’re using too many loops in your code, then you will put unnecessary strain

on your server. This will be the most efficient approach. You can get the

overlapping values in two lists. You can do this using nested for loops, as given

below… import sys counter = range(1, 70000) print(sys.getsizeof(counter))

6. BeLazyWithModuleImporting

Experts in Python suggest importing all the modules at the start of your program.

You can sort these alphabetically. This approach will help you in keeping the track

48
00113303119-Samridhi Bhandari

of the dependencies your program has, but the disadvantage is that your imports

loadatstartup.

You can try a different approach? You can load the modules when you need them.

This technique will help you in distributing the loading time for modules evenly,

This will reduce peaks of memory usage.

7. e“in”ifPossible

It is recommended to use the “in” keyword to check the membership of a list. for

username in member_list: print('{} is a member'.format(username)) Conclusion

All the above code will help you in running your code faster, and this will allow

you to get a better Python performance from your application. As you will progress

with Python, you will find many tips, and you on your own will learn to optimize

your code in Python. You will be using lists, dictionaries, tuples, and many other

things in Python and while building your logic or adding some features, slowly

you will get to know that how things can be optimized.

49
00113303119-Samridhi Bhandari

CHAPTER 6
CODES

import numpy as np
import cv2
import imutils
import datetime

gun_cascade = cv2.CascadeClassifier('cascade.xml')
camera = cv2.VideoCapture('data/gun4_2.mp4')

# initialize the first frame in the video stream


firstFrame = None

# loop over the frames of the video

gun_exist = False

while True:
(grabbed, frame) = camera.read()

# if the frame could not be grabbed, then we have reached the end of the
video
if not grabbed:
break

# resize the frame, convert it to grayscale, and blur it


frame = imutils.resize(frame, width=500)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (21, 21), 0)

gun = gun_cascade.detectMultiScale(gray, 1.3, 5, minSize = (100, 100))

if len(gun) > 0:

gun_exist = True 50
00113303119-Samridhi Bhandari

for (x,y,w,h) in gun:


frame = cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = frame[y:y+h, x:x+w]

# if the first frame is None, initialize it


if firstFrame is None:
firstFrame = gray
continue

# draw the text and timestamp on the frame


cv2.putText(frame, datetime.datetime.now().strftime("%A %d %B %Y
%I:%M:%S%p"),
(10, frame.shape[0] - 10), cv2.FONT_HERSHEY_SIMPLEX,
0.35, (0, 0, 255), 1)

# show the frame and record if the user presses a key


cv2.imshow("Security Feed", frame)
key = cv2.waitKey(1) & 0xFF

if gun_exist:
print("guns detected")
else:
print("guns NOT detected")

# cleanup the camera and close any open windows


camera.release()
cv2.destroyAllWindows()

51
00113303119-Samridhi Bhandari

CHAPTER-7
IMPLEMENTATION

7.2 SYSTEM IMPLEMENTATION

Code run on VS Code

import numpy as np
import cv2
import imutils
import datetime

gun_cascade = cv2.CascadeClassifier('cascade.xml')
camera = cv2.VideoCapture('data/gun4_2.mp4')

# initialize the first frame in the video stream


firstFrame = None

# loop over the frames of the video

gun_exist = False

while True:
(grabbed, frame) = camera.read()

# if the frame could not be grabbed, then we have reached the end of the
video
if not grabbed:
break

# resize the frame, convert it to grayscale, and blur it


frame = imutils.resize(frame, width=500)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (21, 21), 0)

gun = gun_cascade.detectMultiScale(gray, 1.3, 5, minSize = (100, 100))

if len(gun) > 0:
gun_exist = True

52
00113303119-Samridhi Bhandari

for (x,y,w,h) in gun:


frame = cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = frame[y:y+h, x:x+w]

# if the first frame is None, initialize it


if firstFrame is None:
firstFrame = gray
continue

# draw the text and timestamp on the frame


cv2.putText(frame, datetime.datetime.now().strftime("%A %d %B %Y
%I:%M:%S%p"),
(10, frame.shape[0] - 10), cv2.FONT_HERSHEY_SIMPLEX,
0.35, (0, 0, 255), 1)

# show the frame and record if the user presses a key


cv2.imshow("Security Feed", frame)
key = cv2.waitKey(1) & 0xFF

if gun_exist:
print("guns detected")
else:
print("guns NOT detected")

# cleanup the camera and close any open windows


camera.release()
cv2.destroyAllWindows()

53
00113303119-Samridhi Bhandari

7.3 Screenshots

OUTPUT

54
00113303119-Samridhi Bhandari

55
00113303119-Samridhi Bhandari

CONCLUSION

The project “ Criminal Activity Detection” aims to detect the authority about guns
detected in a frame along with exact date and time.

This project uses machine learning to detect objects and even .mp4 files could be
detected no matter what length. We are able to hear a beep sound after each gun
spotted. The project is good for security purposes and would surely provide an aid to
detect criminal activities and hence ultimately aims to reduce such activities in future.

This project cover very much every function needed by user in Criminal Activity
Detection.

56
00113303119-Samridhi Bhandari

BIBLIOGRAPHY

1. www.python.org

2. Python Data Science Handbook byJake Vanderplas

3. The Hitchhiker’s guide to Python by Kenneth Retz

4. Think Python by Allen B.Downey

5. Code.visualstudio.com

6. www.jetbrains.com

7. www.google.com

8. www.wikipedia.org

9. www.codesnack-ide.com

10.www.icfoss.in

57

You might also like