Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021-115
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-115
2021-115
Commits
8a74cb9e
Commit
8a74cb9e
authored
Jul 04, 2021
by
Pramodya Hettiarachchi
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'it18006308_pramodya' into 'master'
video Feed added See merge request
!29
parents
c0fef690
256d81e6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
14 deletions
+79
-14
Hazardous_object_detection/Hot_objects/hotObject-detection.py
...rdous_object_detection/Hot_objects/hotObject-detection.py
+12
-12
Hazardous_object_detection/Sharp_objects/sharpObject-detection.py
...s_object_detection/Sharp_objects/sharpObject-detection.py
+67
-2
No files found.
Hazardous_object_detection/Hot_objects/hotObject-detection.py
View file @
8a74cb9e
...
...
@@ -58,12 +58,12 @@ def forFrame(frame_number, output_array, outpun_count, returned_frame):
y2
=
person
[
3
]
# x_center = (x1+x2)/2
person_midpoint
=
((
x1
+
x2
)
/
2
,
(
y1
+
y2
)
/
2
)
# X and Y coordinates
person_midpoint
=
((
x1
+
x2
)
/
2
,
(
y1
+
y2
)
/
2
)
# X and Y coordinates
if
kettle_count
>
0
:
# Loop each kettle
for
kettle
in
kettles
:
kettle_box
=
box
(
kettle
[
0
]
+
50
,
kettle
[
3
]
+
50
,
kettle
[
1
]
+
50
,
kettle
[
2
]
+
50
)
kettle_box
=
box
(
kettle
[
0
]
+
50
,
kettle
[
3
]
+
50
,
kettle
[
1
]
+
50
,
kettle
[
2
]
+
50
)
# Check weather child is in proximity to the kettle
k_x1
=
kettle
[
0
]
+
50
# Left
k_x2
=
kettle
[
1
]
+
50
# Right
...
...
@@ -88,17 +88,17 @@ def forFrame(frame_number, output_array, outpun_count, returned_frame):
overlap
=
True
# If kettle and child bounding bor overlap, Calculate Distance between center point of two boxes
if
(
overlap
==
True
):
kettle_midpoint
=
((
k_x1
+
k_x2
)
/
2
,
(
k_y1
+
k_y2
)
/
2
)
distance
=
((((
kettle_midpoint
[
0
]
-
person_midpoint
[
0
])
**
2
)
+
((
kettle_midpoint
[
1
]
-
person_midpoint
[
1
])
**
2
)
)
**
0.5
)
if
(
overlap
==
True
):
kettle_midpoint
=
((
k_x1
+
k_x2
)
/
2
,
(
k_y1
+
k_y2
)
/
2
)
distance
=
((((
kettle_midpoint
[
0
]
-
person_midpoint
[
0
])
**
2
)
+
((
kettle_midpoint
[
1
]
-
person_midpoint
[
1
])
**
2
))
**
0.5
)
else
:
print
(
"No Kettles Found"
)
# Video Test
detector
.
detectObjectsFromVideo
(
input_file_path
=
os
.
path
.
join
(
"input/"
,
"video1.mp4"
),
output_file_path
=
os
.
path
.
join
(
"output/"
,
"video_frame_analysis"
),
frames_per_second
=
24
,
per_frame_function
=
forFrame
,
minimum_percentage_probability
=
50
,
return_detected_frame
=
True
)
Hazardous_object_detection/Sharp_objects/sharpObject-detection.py
View file @
8a74cb9e
...
...
@@ -2,6 +2,7 @@
# Import Libraries
from
imageai.Detection
import
ObjectDetection
,
VideoObjectDetection
from
shapely.geometry
import
box
from
imageai.Detection.Custom
import
CustomObjectDetection
import
os
...
...
@@ -35,7 +36,7 @@ def forFrame(frame_number, output_array, outpun_count, returned_frame):
scissors_count
=
0
scissors
=
[]
knife_count
=
0
knife
=
[]
knife
s
=
[]
fork_count
=
0
fork
=
[]
person_count
=
0
...
...
@@ -62,7 +63,7 @@ def forFrame(frame_number, output_array, outpun_count, returned_frame):
# RetinaNet Model
if
detection
[
'name'
]
==
'knife'
and
detection
[
'percentage probability'
]
>=
THRESHOLD_ITEM
:
knife_count
=
knife_count
+
1
knife
.
append
(
detection
[
'box_point'
])
knife
s
.
append
(
detection
[
'box_point'
])
print
(
detection
[
"name"
],
" : "
,
detection
[
"percentage_probability"
],
" : "
,
detection
[
"box_point"
])
if
detection
[
'name'
]
==
'fork'
and
detection
[
'percentage_probability'
]
>=
THRESHOLD_ITEM
:
...
...
@@ -76,3 +77,67 @@ def forFrame(frame_number, output_array, outpun_count, returned_frame):
if
len
(
person
)
>
1
:
print
(
"Person in room"
)
if
len
(
person
)
>=
1
:
for
child
in
person
:
# Create Person(minx, miny, maxx, maxy)
person_box
=
box
(
child
[
0
],
child
[
3
],
child
[
1
],
child
[
2
])
x1
=
child
[
0
]
x2
=
child
[
1
]
y1
=
child
[
2
]
y2
=
child
[
3
]
person_midpoint
=
((
x1
+
x2
)
/
2
,
(
y1
+
y2
)
/
2
)
# (x1, y1)
if
knife_count
>
0
:
# Iterate each Knife
for
knife
in
knifes
:
knife_box
=
box
(
knife
[
0
]
+
50
,
knife
[
3
]
+
50
,
knife
[
1
]
+
50
,
knife
[
2
]
+
50
)
# Check if Knife Overlaps with the Person's Safety Boundary
k_x1
=
knife
[
0
]
+
50
# Left
k_x2
=
knife
[
1
]
+
50
# Right
k_y1
=
knife
[
2
]
+
50
# Top
k_y2
=
knife
[
3
]
+
50
# Bottom
overlap
=
False
if
knife_box
.
intersection
(
person_box
)
!=
None
:
print
(
"Knife - Person is inside the Knives Danger Region"
)
overlap
=
True
if
x1
>=
k_x1
&
x1
<=
k_x2
:
print
(
"Knife - X1 is inside the Person's Danger region!"
)
overlap
=
True
if
x2
>=
k_x1
&
x2
<=
k_x2
:
print
(
"Knife - X2 is inside the Person's Danger region!"
)
overlap
=
True
if
y1
>=
k_y2
&
y1
<=
k_y1
:
print
(
"Knife - Y1 is inside the Person's Danger region!"
)
overlap
=
True
if
y2
>=
k_y2
&
y2
<=
k_y2
:
print
(
"Knife - Y2 is inside the Person's Danger region!"
)
overlap
=
True
if
overlap
==
True
:
# If knife and child bounding bor overlap, Calculate Distance between center point of two boxes
knife_midpoint
=
((
k_x1
+
k_x2
)
/
2
,
(
k_y1
+
k_y2
)
/
2
)
# (x2, y2)
distance
=
((((
knife_midpoint
[
0
]
-
person_midpoint
[
0
])
**
2
)
+
(
(
knife_midpoint
[
1
]
-
person_midpoint
[
1
])
**
2
))
**
0.5
)
DISTANCE_THRESHOLD_KNIFE_MED
=
0
DISTANCE_THRESHOLD_KNIFE_HIGH
=
0
if
distance
>
DISTANCE_THRESHOLD_KNIFE_HIGH
:
print
(
"Person is in the High Danger Zone of Knife"
)
elif
distance
>
DISTANCE_THRESHOLD_KNIFE_MED
:
print
(
"Person is in the Medium Danger Zone of Knife"
)
else
:
print
(
"No Knives Found"
)
# Testing by Video
detector
.
detectObjectsFromVideo
(
input_file_path
=
os
.
path
.
join
(
"input/"
,
"video1.mp4"
),
output_file_path
=
os
.
path
.
join
(
"output/"
,
"video_frame_analysis"
),
frames_per_second
=
24
,
per_frame_function
=
forFrame
,
minimum_percentage_probability
=
50
,
return_detected_frame
=
True
)
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