Beispiel #1
0
import cv2 as cv
from imageai.Detection import VideoObjectDetection
import os

execution_path = os.getcwd()

fourcc = cv.VideoWriter_fourcc(*'XVID')
out = cv.VideoWriter('output.avi', fourcc, 29.97, (1280, 720))


def forFrame(frame_number, output_array, output_count, detected_frame):
    frame = detected_frame
    frame = cv.cvtColor(frame, cv.COLOR_BGR2RGB)
    out.write(frame)


detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(os.path.join(execution_path, "yolo.h5"))
detector.loadModel()

detector.detectObjectsFromVideo(input_file_path=os.path.join(
    execution_path, "piter2.mp4"),
                                save_detected_video=False,
                                frames_per_second=29.97,
                                log_progress=True,
                                per_frame_function=forFrame,
                                return_detected_frame=True)
out.release()
Beispiel #2
0
import os
from imageai.Detection import VideoObjectDetection
import cv2

camera = cv2.VideoCapture(0)
execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(os.path.join(execution_path, "yolo.h5"))
detector.loadModel()

video_path = detector.detectObjectsFromVideo(camera_input=camera,
                                             output_file_path=os.path.join(
                                                 execution_path + "videos/",
                                                 "camera_detected_1"),
                                             frames_per_second=29,
                                             log_progress=True)
print(video_path)
from imageai.Detection import VideoObjectDetection
import os

execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best_v2.0.1.h5"))
detector.loadModel(detection_speed="flash")

custom_objects = detector.CustomObjects(person=True, bicycle=True, motorcycle=True)

video_path = detector.detectCustomObjectsFromVideo(custom_objects=custom_objects, input_file_path=os.path.join(execution_path, "traffic-small.mp4"),
                                output_file_path=os.path.join(execution_path, "traffic_small_custom_flash_detected")
                                , frames_per_second=20, log_progress=True)
print(video_path)
Beispiel #4
0
import os

from imageai.Detection import VideoObjectDetection

execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath(
    os.path.join(execution_path, "resnet50_coco_best_v2.0.1.h5"))
detector.loadModel()

video_path = detector.detectObjectsFromVideo(
    input_file_path=os.path.join(execution_path, "../../videos/traffic.mp4"),
    output_file_path=os.path.join(execution_path, "traffic_detected"),
    frames_per_second=20,
    log_progress=True)
print(video_path)
Beispiel #5
0
from imageai.Detection import VideoObjectDetection
import os

execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath( os.path.join(execution_path , "Resnet.h5"))
detector.loadModel("fast")

video_path = detector.detectObjectsFromVideo(input_file_path=os.path.join(execution_path, "./video/NEED.mp4"),
                                output_file_path=os.path.join(execution_path, "traffic_detected")
                                , frames_per_second=1, log_progress=True)
print(video_path)
Beispiel #6
0
from imageai.Detection import VideoObjectDetection
import os
import cv2

execution_path = os.getcwd()

camera = cv2.VideoCapture(0)

detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(os.path.join(execution_path , "yolo.h5"))
detector.loadModel()

video_path = detector.detectObjectsFromVideo(camera_input=camera,
    output_file_path=os.path.join(execution_path, "camera_detected_video")
    , frames_per_second=15, log_progress=True, minimum_percentage_probability=30)

print(video_path)
 def __init__(self,setModelPath):
     self.execution_path = os.getcwd()
     self.detetor = VideoObjectDetection()
     self.detetor.setModelTypeAsRetinaNet()
     self.detetor.setModelPath(os.path.join(self.execution_path,setModelPath))
     self.detetor.loadModel()
# -*- coding: utf-8 -*-
"""
Created on Fri Jun  5 23:05:28 2020

@author: oguzkaya
"""

from imageai.Detection import VideoObjectDetection
import os

base_path_train = 'dataset/training_set'
base_path_test = 'dataset/test_set'
base_path_video = 'dataset'
execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(os.path.join(base_path_video, "yolo.h5"))
detector.loadModel()

video_path = detector.detectObjectsFromVideo(
    input_file_path=os.path.join(base_path_video, "test_video.mp4"),
    output_file_path=os.path.join(base_path_video, "test_result_1"),
    frames_per_second=29,
    log_progress=True)
print(video_path)
Beispiel #9
0
parking meter, bench, bird, cat, dog, horse, sheep, cow, elephant, bear, zebra,
giraffe, backpack, umbrella, handbag, tie, suitcase, frisbee, skis, snowboard,
sports ball, kite, baseball bat, baseball glove, skateboard, surfboard, tennis racket,
bottle, wine glass, cup, fork, knife, spoon, bowl, banana, apple, sandwich, orange,
broccoli, carrot, hot dog, pizza, donot, cake, chair, couch, potted plant, bed,
dining table, toilet, tv, laptop, mouse, remote, keyboard, cell phone, microwave,
oven, toaster, sink, refrigerator, book, clock, vase, scissors, teddy bear, hair dryer,
toothbrush.
"""

#import tensorflow.compat.v1 as tf
#tf.disable_v2_behavior()


from imageai.Detection import VideoObjectDetection
import os

#execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath( "/content/drive/My Drive/Colab Notebooks/yolo.h5")
detector.loadModel()

video_path = detector.detectObjectsFromVideo(input_file_path="/content/Crow fly (slow motion).mp4",output_file_path="/content/bird1.mp4"
                                , frames_per_second=25, log_progress=True)
print(video_path)



    # print("Array for the outputs of each frame ", output_arrays)
    # print("Array for output count for unique objects in each frame : ", count_arrays)
    print("Output average count for unique objects in the last minute: ",
          average_output_count)
    print("\n\n\n")


def forFull(output_arrays, count_arrays, average_output_count):
    # print("Array for the outputs of each frame ", output_arrays)
    # print("Array for output count for unique objects in each frame : ", count_arrays)
    print("Output average count for unique objects in the entire video: ",
          average_output_count)
    print("------------END OF THE VIDEO --------------")


detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(os.path.join(execution_path, "yolo.h5"))
detector.loadModel(detection_speed="faster")

video_path = detector.detectObjectsFromVideo(
    input_file_path=os.path.join(execution_path, "input.mp4"),
    output_file_path=os.path.join(execution_path, "upload/output_detected_1"),
    frames_per_second=29,
    per_frame_function=forFrame,
    per_second_function=forSeconds,
    per_minute_function=forMinute,
    video_complete_function=forFull,
    minimum_percentage_probability=20,
    log_progress=True)
print(video_path)
    plt.subplot(1, 2, 1)
    plt.title("Frame : " + str(frame_number))
    plt.axis("off")
    plt.imshow(returned_frame, interpolation="none")

    plt.subplot(1, 2, 2)
    plt.title("Analysis: " + str(frame_number))
    plt.pie(sizes,
            labels=labels,
            colors=this_colors,
            shadow=True,
            startangle=140,
            autopct="%1.1f%%")

    plt.pause(0.01)


video_detector = VideoObjectDetection()
video_detector.setModelTypeAsYOLOv3()
video_detector.setModelPath(os.path.join(execution_path, "yolo.h5"))
video_detector.loadModel()

plt.show()

video_detector.detectObjectsFromVideo(
    input_file_path=os.path.join(execution_path, "airport_security.mp4"),
    output_file_path=os.path.join(execution_path, "video_frame_analysis"),
    frames_per_second=20,
    per_frame_function=forFrame,
    minimum_percentage_probability=30,
    return_detected_frame=True)
fgbg = cv.bgsegm.createBackgroundSubtractorGMG()
while(1):
    ret, frame = cap.read()
    fgmask = fgbg.apply(frame)
    fgmask = cv.morphologyEx(fgmask, cv.MORPH_OPEN, kernel)
    cv.imshow('frame',fgmask)
    k = cv.waitKey(30) & 0xff
    if k == 27:
        break
cap.release()
cv.destroyAllWindows()


# Object Detection and Tracking

from imageai.Detection import VideoObjectDetection
import os

execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best_v2.0.1.h5"))
detector.loadModel()
detections = detector.detectObjectsFromVideo(input_file_path=os.path.join(execution_path , "View_001_S2_L1.mp4"), output_file_path=os.path.join(execution_path , "brandnew.mp4"))

for eachObject in detections:
    print(eachObject["name"] , " : " , eachObject["percentage_probability"] )
    

    # plt.pause(0.01)

    screen.fill([0, 0, 0])
    frame = cv2.cvtColor(returned_frame, cv2.COLOR_BGR2RGB)
    frame = np.rot90(frame)
    frame = np.flip(frame, 0)
    frame = pygame.surfarray.make_surface(frame)
    screen.blit(frame, (0, 0))
    pygame.display.update()
    for event in pygame.event.get():
        if event.type == KEYDOWN:
            sys.exit(0)


video_detector = VideoObjectDetection()
video_detector.setModelTypeAsYOLOv3()
video_detector.setModelPath(os.path.join(execution_path, "yolo.h5"))
video_detector.loadModel()

#plt.show()
custom = video_detector.CustomObjects(person=True,
                                      bicycle=True,
                                      car=True,
                                      motorcycle=True,
                                      airplane=True,
                                      bus=True,
                                      train=True,
                                      truck=True,
                                      boat=True,
                                      traffic_light=True,
Beispiel #14
0
from imageai.Detection import VideoObjectDetection
import os
import cv2

camera = cv2.VideoCapture(0)
detector = VideoObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath("resnet50_coco_best_v2.0.1.h5")
detector.loadModel()

video_path = detector.detectObjectsFromVideo(
    camera_input=camera,
    output_file_path="camera_detected_video",
    frames_per_second=20,
    log_progress=True,
    minimum_percentage_probability=40)
Beispiel #15
0
    print("Output average count for unique objects in the last second: ",
          average_output_count)
    print("------------END OF A SECOND --------------")


def forMinute(minute_number, output_arrays, count_arrays,
              average_output_count):
    print("MINUTE : ", minute_number)
    print("Array for the outputs of each frame ", output_arrays)
    print("Array for output count for unique objects in each frame : ",
          count_arrays)
    print("Output average count for unique objects in the last minute: ",
          average_output_count)
    print("------------END OF A MINUTE --------------")


camera = cv2.VideoCapture(0)
video_detector = VideoObjectDetection()
video_detector.setModelTypeAsYOLOv3()
video_detector.setModelPath(os.path.join(execution_path, "yolo.h5"))
video_detector.loadModel()

video_detector.detectObjectsFromVideo(camera_input=camera,
                                      output_file_path=os.path.join(
                                          execution_path, "traffic_detected"),
                                      frames_per_second=10,
                                      per_second_function=forSeconds,
                                      per_frame_function=forFrame,
                                      per_minute_function=forMinute,
                                      minimum_percentage_probability=30)
from imageai.Detection import VideoObjectDetection
import os

execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(os.path.join(execution_path, "yolo.h5"))
detector.loadModel()

video_path = detector.detectObjectsFromVideo(
    input_file_path=os.path.join(execution_path, "video_0.mp4"),
    output_file_path=os.path.join(execution_path, "moderate"),
    frames_per_second=30,
    log_progress=True)

print(video_path)
        this_colors.append(color_index[eachItem])

    global resized

    if (resized == False):
        manager = plt.get_current_fig_manager()
        manager.resize(width=1000, height=500)
        resized = True

    plt.subplot(1, 2, 1)
    plt.title("Frame : " + str(frame_number))
    plt.axis("off")
    plt.imshow(returned_frame, interpolation="none")

    plt.subplot(1, 2, 2)
    plt.title("Analysis: " + str(frame_number))
    plt.pie(sizes, labels=labels, colors=this_colors, shadow=True, startangle=140, autopct="%1.1f%%")

    plt.pause(0.01)



video_detector = VideoObjectDetection()
video_detector.setModelTypeAsYOLOv3()
video_detector.setModelPath(os.path.join(execution_path, "yolo.h5"))
video_detector.loadModel()

plt.show()

video_detector.detectObjectsFromVideo(input_file_path=os.path.join(execution_path, "traffic.mp4"), output_file_path=os.path.join(execution_path, "video_frame_analysis") ,  frames_per_second=20, per_frame_function=forFrame,  minimum_percentage_probability=30, return_detected_frame=True)
Beispiel #18
0
from imageai.Detection import VideoObjectDetection
import os
import time

execution_path = os.getcwd()
s = time.time()
detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(os.path.join(execution_path, "yolo.h5"))
detector.loadModel(detection_speed="faster")

custom_objects = detector.CustomObjects(person=True)

video_path = detector.detectCustomObjectsFromVideo(
    custom_objects=custom_objects,
    input_file_path=os.path.join(execution_path, "1080p_test.mp4"),
    output_file_path=os.path.join(execution_path, "custom_detected1080"),
    frames_per_second=30,
    log_progress=True)
print(video_path)
e = time.time()
timetaken = e - s
print(timetaken)
#The needed libraries are imported
from imageai.Detection import VideoObjectDetection
import cv2
from IPython.display import clear_output

#Start the video capture of the camera
camera = cv2.VideoCapture('http://lopezrui.ddns.net/video/mjpg.cgi')

#Initialise the detector, very similar to the still image detector
detector = VideoObjectDetection()
detector.setModelTypeAsTinyYOLOv3()
detector.setModelPath('/content/drive/My Drive/yolo-tiny.h5')

#The argument within loadModel increases the speed of detection,
#but sacrifices a little accuracy
detector.loadModel(detection_speed="flash")
custom_objects = detector.CustomObjects(person=True)


#Create the function that is run every second the camera is recording.
def forSeconds(second_number, output_arrays, count_arrays,
               average_output_count):
    number = ""
    people_in_frame = str(average_output_count)

    #If the system doesn't detect any people in the frame, it will print 0.
    if people_in_frame == "{}":
        number = "0"
    else:
        #The number of people in the frame is prepared.
        #This for loop analyses every character in the output and gathers
Beispiel #20
0
exec_path = os.getcwd()

detector = ObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath(os.path.join(exec_path, "resnet50_coco_best_v2.0.1.h5"))
detector.loadModel()

list = detector.detectCustomObjectsFromImage(
    input_image=os.path.join(exec_path, "objects.jpg"),
    output_image_path=os.path.join(exec_path, "new_objects.jpg"),
    minimum_percentage_probability=70,
    display_percentage_probability=True,
    display_object_name=False)

from imageai.Detection import VideoObjectDetection
import os

execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(os.path.join(execution_path, "yolo.h5"))
detector.loadModel()

video_path = detector.detectObjectsFromVideo(
    input_file_path=os.path.join(execution_path, "traffic.mp4"),
    output_file_path=os.path.join(execution_path, "traffic_detected"),
    frames_per_second=20,
    log_progress=True)

print(video_path)
#This is the library that we're using for the object detection. It was created by deepquest AI.
from imageai.Detection import VideoObjectDetection
import os

#The following line of code returns a working directory for the actual folder of the file.
execution_path = os.getcwd()

#Initialize the detector.
detector = VideoObjectDetection()

#This sets the initial object detection model instance to the pre trained "RetinaNet" model.
detector.setModelTypeAsRetinaNet()

#Set the model path of the model file we downloaded (the resnet model that uses the COCO database).
detector.setModelPath(
    os.path.join(execution_path, "resnet50_coco_best_v2.0.1.h5"))

#Load the model to begin processing.
detector.loadModel()

# This takes each frame from the video and detects each object inside of the frame.
#After doing so, it parses the images together in to an output video at 20 frames per second. The output file is in AVI.
#Note: It takes the input file and stores the output file in the same folder.
path = detector.detectObjectsFromVideo(
    input_file_path=os.path.join(execution_path, "waste.mp4"),
    output_file_path=os.path.join(execution_path, "Detected_Output"),
    frames_per_second=20,
    log_progress=False)

#For me to make sure the model goes into the right folder.
print(path)
Beispiel #22
0
from imageai.Detection import VideoObjectDetection
import os

execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(os.path.join(execution_path, "yolo.h5"))
detector.loadModel()

video_path = detector.detectObjectsFromVideo(
    input_file_path=os.path.join(execution_path, "traffic-mini.mp4"),
    output_file_path=os.path.join(execution_path, "traffic_mini_detected_1"),
    frames_per_second=29,
    log_progress=True)
print(video_path)
    plt.subplot(1, 2, 1)
    plt.title("Frame : " + str(frame_number))
    plt.axis("off")
    plt.imshow(returned_frame, interpolation="none")

    plt.subplot(1, 2, 2)
    plt.title("Analysis: " + str(frame_number))
    plt.pie(sizes,
            labels=labels,
            colors=this_colors,
            shadow=True,
            startangle=140,
            autopct="%1.1f%%")

    plt.pause(0.01)


video_detector = VideoObjectDetection()
video_detector.setModelTypeAsYOLOv3()
video_detector.setModelPath(os.path.join(execution_path, "yolo.h5"))
video_detector.loadModel()

plt.show()

video_detector.detectObjectsFromVideo(camera_input=camera,
                                      save_detected_video=False,
                                      frames_per_second=10,
                                      per_frame_function=forFrame,
                                      minimum_percentage_probability=30,
                                      return_detected_frame=True)
Beispiel #24
0
def detection_of_vehicles_from_video(folder1, folder2, findex):
    '''
    Detects and saves the arrays containing bounding boxes of detected
    vehicles from videos of a given folder

    Parameters:
    folder1 : path of the folder containing videos
    folder2 : path of the folder in which arrays are required to be stored
    findex : index number of the first video in folder1 
    '''

    #modifying forFrame function of ImageAI to make a list
    #of bounding box coordinates for vehichles detected in a
    #particular frame
    def forFrame(frame_number, output_array, output_count):

        bboxes = []

        for i in range(len(output_array)):
            bboxes.append(list(output_array[i]['box_points']))

        B.append(bboxes)

    #reading and sorting the filenames of folder1
    videos = glob.glob(folder1 + '/video*.MOV')
    videos = natsort.natsorted(videos)

    #set and load ResNet Model for detection of vehicles
    execution_path = os.getcwd()
    detector = VideoObjectDetection()
    detector.setModelTypeAsRetinaNet()
    #use detector.setModelTypeAsYOLOv3() to use YOLOv3 instead of RetinaNet
    detector.setModelPath(
        os.path.join(
            execution_path,
            "/home/siddhi/Desktop/RoadCrossingAssistant_FY_Project_Data/resnet50_coco_best_v2.0.1.h5"
        ))
    #use model path of yolo.h5 if to use YOLOv3 instead of RetinaNet
    detector.loadModel()
    custom_objects = detector.CustomObjects(bicycle=True,
                                            motorcycle=True,
                                            car=True,
                                            truck=True)

    for video in videos:
        print('processing' + video)
        B = []
        detector.detectCustomObjectsFromVideo(
            save_detected_video=False,
            custom_objects=custom_objects,
            input_file_path=os.path.join(execution_path, video),
            frames_per_second=30,
            per_frame_function=forFrame,
            minimum_percentage_probability=40)
        B = np.array(B)
        print('saving array for video' + video + '\n shape of array: ' +
              str(B.shape))
        np.save(folder2 + '/array' + str(findex), B)
        findex = findex + 1
Beispiel #25
0
from imageai.Detection import VideoObjectDetection
import os
import tensorflow
execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(os.path.join(execution_path, "yolo.h5"))
detector.loadModel()

video_path = detector.detectObjectsFromVideo(
    input_file_path=os.path.join(execution_path, "ingredients.jpg"),
    output_file_path=os.path.join(execution_path, "vegetable_detected"),
    frames_per_second=29,
    log_progress=True)
print(video_path)
Beispiel #26
0
from imageai.Detection import VideoObjectDetection
import os

execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath( os.path.join(execution_path , "../models/resnet50_coco_best_v2.0.1.h5"))
detector.loadModel()

custom = detector.CustomObjects(person=True, motorcycle=True, bus=True)

video_path = detector.detectCustomObjectsFromVideo(custom_objects=custom, input_file_path=os.path.join(execution_path, "traffic-mini.mp4"),
                                output_file_path=os.path.join(execution_path, "traffic-mini_detected_custom")
                                , frames_per_second=20, log_progress=True)
print(video_path)
from imageai.Detection import VideoObjectDetection
import os, logging

logging.basicConfig(level=logging.DEBUG,
                    filename='app.log',
                    filemode='w',
                    format='%(name)s - %(levelname)s - %(message)s')

execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsTinyYOLOv3()
detector.setModelPath(execution_path + "\\yolo-tiny.h5")
detector.loadModel()

custom_objects = detector.CustomObjects(person=True)

total_seconds = 0
object_visible = 0
frame_count = 0


def forFrame(frame_number, output_array, output_count):
    global frame_count
    if "person" in output_count:
        frame_count += 1
        logging.info("Frames with visible objects: %s", frame_count)
    else:
        logging.info("No objects visible")

Beispiel #28
0
            pass

    #nos asegguramos que elvalor de cueta sea 0
    iCount = 0
    print("------------END OF A FRAME --------------")
    if (0xFF == ord('q')):
        sys.exit()


execution_path = os.getcwd()

#le decimos a opencv que usaremos la camara de cierto index
camera = cv2.VideoCapture(1)

#iniciamos el detector
detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(os.path.join(execution_path, "yolo.h5"))
detector.loadModel()

#selecionamos cuales objectos queremos detectar
custom_objects = detector.CustomObjects(person=True, chair=True)

#variables para desplegar el video en tiempo real
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('output-count2.avi', fourcc, 29.0, (640, 480))

#funcion de la libreria imageai para detectar los objectos
video_path = detector.detectCustomObjectsFromVideo(
    save_detected_video=False,
    return_detected_frame=True,
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 20 00:07:55 2019

@author: Kim
"""

from imageai.Detection import VideoObjectDetection
import imageai
import os

execution_path = os.getcwd()

# detector = VideoObjectDetection()
# detector.setModelTypeAsRetinaNet()
# detector.setModelPath( os.path.join(execution_path , "models/resnet50_coco_best_v2.0.1.h5"))
detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(os.path.join(execution_path, "models/yolo.h5"))

detector.loadModel(detection_speed="fast")  #fast, faster, fastest, flash

video_path = detector.detectObjectsFromVideo(
    input_file_path=os.path.join(execution_path, "videos/seoul_02_0.mp4"),
    output_file_path=os.path.join(execution_path, "video_out2"),
    frames_per_second=20,
    log_progress=True)
print(video_path)
Beispiel #30
0
from imageai.Detection import VideoObjectDetection
import os

execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best_v2.1.0.h5"))
detector.loadModel()

custom_objects = detector.CustomObjects(person=True, bicycle=True, motorcycle=True)

video_path = detector.detectObjectsFromVideo(
                input_file_path=os.path.join(execution_path, "Animal.mp4"),
                output_file_path=os.path.join(execution_path, "Animal_output"),
                frames_per_second=1, log_progress=True)
print(video_path)
    plt.axis("off")
    plt.imshow(returned_frame, interpolation="none")

    plt.subplot(1, 2, 2)
    plt.title("Analysis: " + str(frame_number))
    plt.pie(sizes,
            labels=labels,
            colors=this_colors,
            shadow=True,
            startangle=140,
            autopct="%1.1f%%")

    plt.pause(0.01)


video_detector = VideoObjectDetection()
video_detector.setModelTypeAsRetinaNet()
video_detector.setModelPath(
    os.path.join(execution_path, "../models/resnet50_coco_best_v2.0.1.h5"))
video_detector.loadModel()

plt.show()

video_detector.detectObjectsFromVideo(
    input_file_path=os.path.join(execution_path, "traffic.mp4"),
    output_file_path=os.path.join(execution_path, "video_frame_analysis"),
    frames_per_second=20,
    per_frame_function=forFrame,
    minimum_percentage_probability=30,
    return_detected_frame=True)
def forFull(output_arrays, count_arrays, average_output_count):
    print("Array for the outputs of each frame ", output_arrays)
    print("Array for output count for unique objects in each frame : ", count_arrays)
    print("Output average count for unique objects in the entire video: ", average_output_count)
    print("------------END OF THE VIDEO --------------")
"""

def forSeconds(second_number, output_arrays, count_arrays, average_output_count):
    print("SECOND : ", second_number)
    print("Array for the outputs of each frame ", output_arrays)
    print("Array for output count for unique objects in each frame : ", count_arrays)
    print("Output average count for unique objects in the last second: ", average_output_count)
    print("------------END OF A SECOND --------------")

#-------------------------------------------------------------------------------#
detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(os.path.join(execution_path,"yolo.h5"))
detector.loadModel(detection_speed="fastest")
plt.show()

custom_objects = detector.CustomObjects(car=True,truck=True,motorcycle=True)

#--------------------------------Features---------------------------------------#
video_path = detector.detectCustomObjectsFromVideo(
minimum_percentage_probability=50,
custom_objects=custom_objects,
per_second_function=forSeconds,
display_percentage_probability=True,
display_object_name=True,
log_progress=True,
from imageai.Detection import VideoObjectDetection
import os

execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath( os.path.join(execution_path , "yolo.h5"))
detector.loadModel()

video_path = detector.detectObjectsFromVideo(input_file_path=os.path.join(execution_path, "traffic.mp4"),
                                output_file_path=os.path.join(execution_path, "traffic_detected")
                                , frames_per_second=20, log_progress=True)
print(video_path)
from imageai.Detection import VideoObjectDetection
import os

execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsRetinaNet()
detector.setModelPath( os.path.join(execution_path , "resnet50_coco_best_v2.0.1.h5"))
detector.loadModel()

video_path = detector.detectObjectsFromVideo(input_file_path=os.path.join(execution_path, "traffic.mp4"),
                                output_file_path=os.path.join(execution_path, "traffic_detected")
                                , frames_per_second=20, log_progress=True)
print(video_path)