Commit 8a74cb9e authored by Pramodya Hettiarachchi's avatar Pramodya Hettiarachchi

Merge branch 'it18006308_pramodya' into 'master'

video Feed added

See merge request !29
parents c0fef690 256d81e6
......@@ -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)
......@@ -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 = []
knifes = []
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'])
knifes.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)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment