Commit f900e5fe authored by Odhara Kodikara's avatar Odhara Kodikara

Merge branch 'master' of http://gitlab.sliit.lk/2021-115/2021-115 into it18110708_kodikara

 Conflicts:
	.idea/workspace.xml
parents cfabc76c 0f324cce
# IT18006308 # IT18006308
# Import Libraries
from imageai.Detection import ObjectDetection, VideoObjectDetection
import os
import pickle
import time
import cv2
import sys
THRESHOLD_ITEM = 0.5
THRESHOLD_PERSON = 0.5
print("Test 1 : Hot Object Detection Start")
detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath("../model/yolo.h5")
detector.loadModel()
def forFrame(frame_number, output_array, outpun_count, returned_frame):
kettle_count = 0
kettles = []
person_count = 0
persons = []
for detection in output_array:
print(str(detection['name']) + " - " + str(detection['percentage_probability']) + " - " + str(
detection['box_point']))
if detection['name'] == 'kettle' and detection['percentage_probability'] >= THRESHOLD_ITEM:
kettle_count = kettle_count + 1
kettles.append(detection['box_point'])
print(detection["name"], " : ", detection["percentage_probability"], " : ", detection['box_point'])
if detection['name'] == 'person' and detection['percentage_probability'] >= THRESHOLD_PERSON:
person_count = person_count + 1
persons.append(detection['box_point'])
print(detection["name"], " : ", detection["percentage_probability"], " : ", detection['box_point'])
# Check the person is in room
if len(persons) == 0:
print("Person is not in room")
if len(persons) > 1:
print("Person in room")
# IT18006308 # IT18006308
# Import Libraries # Import Libraries
from imageai.Detection import ObjectDetection from imageai.Detection import ObjectDetection, VideoObjectDetection
from imageai.Detection.Custom import CustomObjectDetection
import os import os
import pickle import pickle
import time import time
...@@ -9,35 +11,68 @@ import cv2 ...@@ -9,35 +11,68 @@ import cv2
import sys import sys
THRESHOLD_ITEM = 0.5 THRESHOLD_ITEM = 0.5
THRESHOLD_PERSON = 0.5
print("Test 1 : Sharp Object Detection Start") print("Test 1 : Sharp Object Detection Start")
detector = ObjectDetection() # detector = ObjectDetection()
detector2 = ObjectDetection() detector = VideoObjectDetection()
detector2 = VideoObjectDetection()
detector.setModelTypeAsYOLOv3() detector.setModelTypeAsYOLOv3()
detector.setModelPath("model/yolo.h5") detector.setModelPath("../model/yolo.h5")
detector.loadModel() detector.loadModel()
detection1 = detector.detectObjectsFromImage(input_image="input/sharp2.jpg", output_image_path="output/sharp2.jpg") # detection1 = detector.detectObjectsFromImage(input_image="input/sharp2.jpg", output_image_path="output/sharp2.jpg")
detector2.setModelTypeAsRetinaNet() detector2.setModelTypeAsRetinaNet()
detector2.setModelPath("model/resnet50_coco_best_v2.1.0.h5") detector2.setModelPath("model/resnet50_coco_best_v2.1.0.h5")
detector2.loadModel() detector2.loadModel()
detection2 = detector2.detectObjectsFromImage(input_image="input/sharp2.jpg", output_image_path="output/sharp2.jpg")
scissors_count = 0 # detection2 = detector2.detectObjectsFromImage(input_image="input/sharp2.jpg", output_image_path="output/sharp2.jpg")
scissors = []
def forFrame(frame_number, output_array, outpun_count, returned_frame):
scissors_count = 0
scissors = []
knife_count = 0
knife = []
fork_count = 0
fork = []
person_count = 0
person = []
print(detection1) print(frame_number)
# YOLOv3 Model # YOLOv3 Model (person and scissors)
for detection in detection1: for detection in output_array:
print(str(detection['name']) + " - " + str(detection['precentage_probability']) + " - " + str( print(str(detection['name']) + " - " + str(detection['percentage_probability']) + " - " + str(
detection['box_point'])) detection['box_point']))
# identify Scissors # identify Scissors
if(detection['name'] == 'scissors' and detection['precentage_probability'] >= THRESHOLD_ITEM): if detection['name'] == 'scissors' and detection['percentage_probability'] >= THRESHOLD_ITEM:
scissors_count = scissors_count + 1 scissors_count = scissors_count + 1
scissors.append(detection['box_point']) scissors.append(detection['box_point'])
print(detection["name"], " : ", detection["precentage_probability"], " : ", detection['box_point']) print(detection["name"], " : ", detection["percentage_probability"], " : ", detection['box_point'])
if detection['name'] == 'person' and detection['percentage_probability'] >= THRESHOLD_PERSON:
person_count = person_count + 1
person.append(detection['box_point'])
print(detection["name"], " : ", detection["percentage_probability"], " : ", detection['box_point'])
# RetinaNet Model
if detection['name'] == 'knife' and detection['percentage probability'] >= THRESHOLD_ITEM:
knife_count = knife_count + 1
knife.append(detection['box_point'])
print(detection["name"], " : ", detection["percentage_probability"], " : ", detection["box_point"])
if detection['name'] == 'fork' and detection['percentage_probability'] >= THRESHOLD_ITEM:
fork_count = fork_count + 1
fork.append(detection['box_point'])
print(detection["name"], " : ", detection["percentage_probability"], " : ", detection["box_point"])
# Check the person is in room
if len(person) == 0:
print("Person is not in room")
if len(person) > 1:
print("Person in room")
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