Commit 5d129a81 authored by Maduranga Jayakody's avatar Maduranga Jayakody

Update microwave detection

parent 75c922eb
......@@ -5,27 +5,30 @@ from imageai.Detection import ObjectDetection, VideoObjectDetection
import sys
import os
import cv2
import time
from shapely.geometry import box
THRESHOLD_ITEM = 0.5
THRESHOLD_PERSON = 0.5
print("Sharp Object Detection Begins")
execution_path = "input/"
Output_Path = "output/"
#print("Sharp Object Detection Begins")
detector = VideoObjectDetection()
detector2 = VideoObjectDetection()
detector = VideoObjectDetection()
detector2 = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath("../model/yolo.h5")
detector.CustomObjects(microwave=True,oven=True,person=True)
detector.setModelPath("../models/yolo.h5")
detector.loadModel(detection_speed="fast")
detector.loadModel()
detector2.setModelTypeAsRetinaNet()
detector2.setModelPath("model/resnet50_coco_best_v2.1.0.h5")
detector2.loadModel()
def forFrame(frame_number, output_array, output_count, returned_frame):
microwave_count = 0
......@@ -39,7 +42,7 @@ def forFrame(frame_number, output_array, output_count, returned_frame):
count = 0
persons = []
# YOLO Model (Person) and RetinaModel (Toaster, Microwave and Oven, Hair Dryer) both - Single Frame - Person
for detection in output_array:
print(
detection['name'] + " - " + str(detection['percentage_probability']) + " - " + str(detection['box_points']))
......@@ -71,7 +74,8 @@ def forFrame(frame_number, output_array, output_count, returned_frame):
powercords.append(detection['box_points'])
print(detection["name"], " : ", detection["percentage_probability"], " : ", detection["box_points"])
# Check if Child is in 100 Pixels to Left and 100 Pixels to Right of the Identified Object(s)
# Check if there is a person in view
if (len(persons) == 0):
print("There is no Person in the Room!")
......@@ -80,33 +84,38 @@ def forFrame(frame_number, output_array, output_count, returned_frame):
if (len(persons) >= 1):
for person in persons:
# Create Person(minx, miny, maxx, maxy)
person_box = box(person[0], person[3], person[1], person[2])
coords = person
coords = person # (x1, x2, y1, y2)
x1 = person[0]
x2 = person[1]
y1 = person[2]
y2 = person[3]
person_midpoint = ((x1 + x2) / 2, (y1 + y2) / 2)
x_center = (x1 + x2) / 2
y_center = (y1 + y2) / 2
x_center = (x1 + x2) / 2 # Center X Coordinate
y_center = (y1 + y2) / 2 # Center Y Coordinate
# x1 => Left, x2 => Right, y1 => Top, y2 => Bottom
# (x1, y1) - Top Left
# (x2, y2) - Bottom Right
# (x2, y1) - Top Right
# (x1, y2) - Bottom Left
if microwave_count > 0:
# Iterate each Microwave
for microwave in microwaves:
# Create Microwave(minx, miny, maxx, maxy)
microwave_box = box(microwave[0] + 50, microwave[3] + 50, microwave[1] + 50, microwave[2] + 50)
e_x1 = microwave[0] + 50
e_x2 = microwave[1] + 50
e_y1 = microwave[2] + 50
e_y2 = microwave[3] + 50
# Check if Microwave Overlaps with the Person's Safety Boundary
# We Add 50px in all directions of the Bounding Box - Top+50, Bottom+50, Left+50, Right+50
e_x1 = microwave[0] + 50 # Left
e_x2 = microwave[1] + 50 # Right
e_y1 = microwave[2] + 50 # Top
e_y2 = microwave[3] + 50 # Bottom
overlap = False
# Check if the Microwave Oven is in the Persons Danger Region
if (microwave_box.intersection(person_box) != None):
print("Microwave/Oven - Person is in the Microwave/Oven's Danger Region!")
overlap = True
......@@ -125,7 +134,8 @@ def forFrame(frame_number, output_array, output_count, returned_frame):
overlap = True
if (overlap == True):
# If the Bounding Boxes Overlap at some point
# Calculate Distnace between center point of two boxes
microwave_midpoint = ((e_x1 + e_x2) / 2, (e_y1 + e_y2) / 2)
distance = ((((microwave_midpoint[0] - person_midpoint[0]) ** 2) + (
(microwave_midpoint[1] - person_midpoint[1]) ** 2)) ** 0.5)
......
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