Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021-208
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2021-208
2021-208
Commits
99a82bb9
Commit
99a82bb9
authored
Oct 15, 2021
by
Givindu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
V1.16.2
parent
5228f988
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
35 deletions
+65
-35
abnormal_behavior_detection/HumanDetection/Human_Detection_Video.py
...ehavior_detection/HumanDetection/Human_Detection_Video.py
+5
-7
abnormal_behavior_detection/WeaponDetection/Knife_Detection.py
...mal_behavior_detection/WeaponDetection/Knife_Detection.py
+4
-26
abnormal_behavior_detection/WeaponDetection/Weapon_Detection.py
...al_behavior_detection/WeaponDetection/Weapon_Detection.py
+56
-2
No files found.
abnormal_behavior_detection/HumanDetection/Human_Detection_Video.py
View file @
99a82bb9
...
...
@@ -20,14 +20,12 @@ def capture_humans(path):
# detector.setPreferableBackend(cv2.dnn.DNN_BACKEND_INFERENCE_ENGINE)
# detector.setPreferableTarget(cv2.dnn.DNN_TARGET_CPU)
CLASSES
=
[
"background"
,
"aeroplane"
,
"bicycle"
,
"bird"
,
"boat"
,
"bottle"
,
"bus"
,
"car"
,
"cat"
,
"chair"
,
"cow"
,
"diningtable"
,
"dog"
,
"horse"
,
"motorbike"
,
"person"
,
"pottedplant"
,
"sheep"
,
"sofa"
,
"train"
,
"tvmonitor"
]
CLASSES
=
[
]
classFile
=
'E:/BACKBONE/abnormal_behavior_detection/Models/Human Detection/class.names'
with
open
(
classFile
,
'rt'
)
as
f
:
CLASSES
=
f
.
read
()
.
rstrip
(
'
\n
'
)
.
split
(
'
\n
'
)
print
(
"STEP 1 ON PROGRESS..."
)
print
(
"test12345"
)
print
(
"test11"
)
#Get input video
...
...
@@ -50,7 +48,7 @@ def capture_humans(path):
while
True
:
ret
,
frame
=
cap
.
read
()
if
ret
!=
False
:
frame
=
imutils
.
resize
(
frame
,
width
=
5
00
)
frame
=
imutils
.
resize
(
frame
,
width
=
8
00
)
total_frames
=
total_frames
+
1
(
H
,
W
)
=
frame
.
shape
[:
2
]
...
...
abnormal_behavior_detection/WeaponDetection/Knife_Detection.py
View file @
99a82bb9
...
...
@@ -36,7 +36,7 @@ def weaponDetection():
## Model Files
modelConfiguration
=
"E:/BACKBONE/abnormal_behavior_detection/Models/Knife Detection/yolov4-custom.cfg"
modelWeights
=
"E:/BACKBONE/abnormal_behavior_detection/Models/Knife Detection/yolov4-custom_
la
st.weights"
modelWeights
=
"E:/BACKBONE/abnormal_behavior_detection/Models/Knife Detection/yolov4-custom_
be
st.weights"
net
=
cv
.
dnn
.
readNetFromDarknet
(
modelConfiguration
,
modelWeights
)
net
.
setPreferableBackend
(
cv
.
dnn
.
DNN_BACKEND_OPENCV
)
net
.
setPreferableTarget
(
cv
.
dnn
.
DNN_TARGET_CPU
)
...
...
@@ -70,32 +70,8 @@ def weaponDetection():
box
=
bbox
[
i
]
x
,
y
,
w
,
h
=
box
[
0
],
box
[
1
],
box
[
2
],
box
[
3
]
# Detect handguns
if
classIds
[
i
]
==
0
:
# print(x,y,w,h)
text
=
"{:.4f}
%
"
.
format
((
confs
[
i
])
*
100
)
print
(
"Suspect Detected : "
,
"["
,
text
,
"]"
)
cv
.
rectangle
(
img
,
(
x
,
y
),
(
x
+
w
,
y
+
h
),
(
255
,
0
,
255
),
2
)
cv
.
putText
(
img
,
f
'{classNames[classIds[i]].upper()} {int(confs[i] * 100)}
%
'
,
(
x
,
y
-
10
),
cv
.
FONT_HERSHEY_SIMPLEX
,
0.6
,
(
255
,
0
,
255
),
2
)
# save detected frames
cv2
.
imwrite
(
'C:/Users/Givindu/Desktop/New folder/frames/Suspects with Weapons/frame
%
d.jpg'
%
count
,
img
)
count
+=
1
# Create and save in a CSV file
type
=
"Abnormal Activity"
weapon
=
"The Pistol was used as a weapon"
with
open
(
'C:/Users/Givindu/Desktop/New folder/frames/Abnormal Activity.csv'
,
'w'
,
newline
=
''
)
as
file
:
Num
+=
1
TimeD
=
start
-
time
.
time
()
arr
=
[
Num
,
type
,
weapon
,
TimeD
]
writer
=
csv
.
writer
(
file
)
writer
.
writerow
(
field
)
writer
.
writerow
(
arr
)
# Detect Knives
if
classIds
[
i
]
==
1
:
# print(x,y,w,h)
text
=
"{:.4f}
%
"
.
format
((
confs
[
i
])
*
100
)
...
...
@@ -120,6 +96,8 @@ def weaponDetection():
writer
.
writerow
(
arr
)
while
True
:
success
,
img
=
cap
.
read
()
if
success
!=
False
:
...
...
abnormal_behavior_detection/WeaponDetection/Weapon_Detection.py
View file @
99a82bb9
...
...
@@ -36,7 +36,7 @@ def weaponDetection():
## Model Files
modelConfiguration
=
"E:/BACKBONE/abnormal_behavior_detection/Models/Weapon Detection/yolov4-custom.cfg"
modelWeights
=
"E:/BACKBONE/abnormal_behavior_detection/Models/Weapon Detection/yolov4-custom_
la
st.weights"
modelWeights
=
"E:/BACKBONE/abnormal_behavior_detection/Models/Weapon Detection/yolov4-custom_
be
st.weights"
net
=
cv
.
dnn
.
readNetFromDarknet
(
modelConfiguration
,
modelWeights
)
net
.
setPreferableBackend
(
cv
.
dnn
.
DNN_BACKEND_OPENCV
)
net
.
setPreferableTarget
(
cv
.
dnn
.
DNN_TARGET_CPU
)
...
...
@@ -70,8 +70,34 @@ def weaponDetection():
box
=
bbox
[
i
]
x
,
y
,
w
,
h
=
box
[
0
],
box
[
1
],
box
[
2
],
box
[
3
]
# Detect handguns
if
classIds
[
i
]
==
0
:
if
classIds
[
i
]
==
'0'
:
# print(x,y,w,h)
text
=
"{:.4f}
%
"
.
format
((
confs
[
i
])
*
100
)
print
(
"Suspect Detected : "
,
"["
,
text
,
"]"
)
# cv.rectangle(img, (x, y), (x + w, y + h), (255, 0, 255), 2)
# cv.putText(img, f'{classNames[classIds[i]].upper()} {int(confs[i] * 100)}%',
# (x, y - 10), cv.FONT_HERSHEY_SIMPLEX, 0.6, (255, 0, 255), 2)
cv2
.
imwrite
(
'E:/BACKBONE/abnormal_behavior_detection/frames/Suspects with Weapons/frame
%
d.jpg'
%
count
,
img
)
count
+=
1
# Create and save in a CSV File
type
=
"Abnormal Activity"
weapon
=
"The Pistol was used as a weapon"
with
open
(
'E:/BACKBONE/abnormal_behavior_detection/CSV/Abnormal Activity.csv'
,
'w'
,
newline
=
''
)
as
file
:
Num
+=
1
TimeD
=
time
.
time
()
-
start
arr
=
[
Num
,
type
,
weapon
,
TimeD
]
writer
=
csv
.
writer
(
file
)
writer
.
writerow
(
field
)
writer
.
writerow
(
arr
)
# Detect knives
if
classIds
[
i
]
==
1
:
# print(x,y,w,h)
text
=
"{:.4f}
%
"
.
format
((
confs
[
i
])
*
100
)
print
(
"Suspect Detected : "
,
"["
,
text
,
"]"
)
...
...
@@ -79,6 +105,7 @@ def weaponDetection():
#cv.putText(img, f'{classNames[classIds[i]].upper()} {int(confs[i] * 100)}%',
# (x, y - 10), cv.FONT_HERSHEY_SIMPLEX, 0.6, (255, 0, 255), 2)
# save detected frames
cv2
.
imwrite
(
'E:/BACKBONE/abnormal_behavior_detection/frames/Suspects with Weapons/frame
%
d.jpg'
%
count
,
img
)
count
+=
1
...
...
@@ -94,6 +121,33 @@ def weaponDetection():
writer
.
writerow
(
arr
)
# Detect grenades
if
classIds
[
i
]
==
'2'
:
# print(x,y,w,h)
text
=
"{:.4f}
%
"
.
format
((
confs
[
i
])
*
100
)
print
(
"Suspect Detected : "
,
"["
,
text
,
"]"
)
#cv.rectangle(img, (x, y), (x + w, y + h), (255, 0, 255), 2)
#cv.putText(img, f'{classNames[classIds[i]].upper()} {int(confs[i] * 100)}%',
# (x, y - 10), cv.FONT_HERSHEY_SIMPLEX, 0.6, (255, 0, 255), 2)
# save detected frames
cv2
.
imwrite
(
'E:/BACKBONE/abnormal_behavior_detection/frames/Suspects with Weapons/frame
%
d.jpg'
%
count
,
img
)
count
+=
1
# Create and save in a CSV File
type
=
"Abnormal Activity"
weapon
=
"The Grenade was used as a weapon"
with
open
(
'E:/BACKBONE/abnormal_behavior_detection/CSV/Abnormal Activity.csv'
,
'w'
,
newline
=
''
)
as
file
:
Num
+=
1
TimeD
=
time
.
time
()
-
start
arr
=
[
Num
,
type
,
weapon
,
TimeD
]
writer
=
csv
.
writer
(
file
)
writer
.
writerow
(
field
)
writer
.
writerow
(
arr
)
while
True
:
success
,
img
=
cap
.
read
()
if
success
!=
False
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment