Beispiel #1
0
from imageai.Detection import ObjectDetection, VideoObjectDetection
import os
import cv2
import rospy
from std_msgs.msg import Bool, String

video_detector = VideoObjectDetection()
video_detector_resnet = VideoObjectDetection()
camera = cv2.VideoCapture(0)

model_path = "./models/yolo-tiny.h5"
model_path_resnet = "./models/resnet50_coco_best_v2.0.1.h5"

video_detector.setModelTypeAsTinyYOLOv3()
video_detector_resnet.setModelTypeAsRetinaNet()

video_detector.setModelPath(model_path)
video_detector_resnet.setModelPath(model_path_resnet)

#video_detector.loadModel()
video_detector_resnet.loadModel()

#publishers
pub_bool = rospy.Publisher('detecting_object', Bool, queue_size=100)
pub_str = rospy.Publisher('objects_detected', String, queue_size=100)

custom = video_detector_resnet.CustomObjects(person=True,
                                             handbag=True,
                                             tie=True,
                                             suitcase=True,
                                             bottle=True,
Beispiel #2
0
from imageai.Detection import VideoObjectDetection
import os

execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(
    os.path.join(execution_path, "C:\\Users\\Admin_Robo\\Desktop\\yolo.h5"))
detector.loadModel(detection_speed='faster')

video_path = detector.detectObjectsFromVideo(
    input_file_path=os.path.join(
        execution_path,
        "C:\\Users\\Admin_Robo\\Desktop\\WIN_20190912_17_36_23_Pro.mp4"),
    output_file_path=os.path.join(execution_path,
                                  "C:\\Users\\Admin_Robo\\Desktop\\esp_test"),
    frames_per_second=1,
    log_progress=True)
print(video_path)
Beispiel #3
0
def predict():

    data = request.get_json(force=True)
    body = data.get('data')
    filew = body.get('file')

    print(filew)
    decoded_string = base64.b64decode(filew)
    with open('1.mp4', 'wb') as wfile:
        wfile.write(decoded_string)

    video = cv2.VideoCapture("1.mp4")

    # Find OpenCV version
    (major_ver, minor_ver, subminor_ver) = (cv2.__version__).split('.')

    fps = 0

    if int(major_ver) < 3:
        fps = round(video.get(cv2.cv.CV_CAP_PROP_FPS))
        print("Frames per second using video.get(cv2.cv.CV_CAP_PROP_FPS): {0}".
              format(fps))
    else:
        fps = round(video.get(cv2.CAP_PROP_FPS))
        print(
            "Frames per second using video.get(cv2.CAP_PROP_FPS) : {0}".format(
                fps))

    video.release()

    # def incr():
    #     global varib
    #     varib = 'bbbbbbbb'

    # incr()

    # print("varib", varib)

    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 --------------")

    def forFull(output_arrays, count_arrays, average_output_count):
        #Perform action on the 3 parameters returned into the function
        # 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)
        global objects
        objects = output_arrays

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

    video_detector.detectObjectsFromVideo(
        input_file_path=os.path.join(execution_path, "1.mp4"),
        output_file_path=os.path.join(execution_path, "traffic_detected"),
        frames_per_second=fps,
        per_second_function=forSeconds,
        video_complete_function=forFull,
        minimum_percentage_probability=30)

    def convert_avi_to_mp4(avi_file_path, output_name):
        os.popen(
            "ffmpeg -i '{input}' -ac 2 -b:v 2000k -c:a aac -c:v libx264 -b:a 160k -vprofile high -bf 0 -strict experimental -f mp4 './static/{output}.mp4'"
            .format(input=avi_file_path, output=output_name))
        return True

    convert_avi_to_mp4("traffic_detected.avi", "converted")

    json_dump = pd.Series(objects).to_json(orient='values')

    print("==============", json_dump)

    return json_dump
Beispiel #4
0
 def __init__(self):
     execution_path = os.getcwd()
     self.myDetector = VideoObjectDetection()
Beispiel #5
0
 def configureVideoDetector(self):
     self.detector = VideoObjectDetection()
     self.detector.setModelTypeAsYOLOv3()
     self.detector.setModelPath( os.path.join(self.execution_path , yolo_network_path))
     self.detector.loadModel()
          average_output_count)
    print("------------END OF A MINUTE --------------")


#full
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 --------------")


camera = cv2.VideoCapture(0)
detectormodel = VideoObjectDetection()
detectormodel.setModelTypeAsYOLOv3()
detectormodel.setModelPath(os.path.join(os.getcwd(), "yolo.h5"))
detectormodel.loadModel()
# plt.show()
video_path = detectormodel.detectObjectsFromVideo(
    camera_input=camera,
    output_file_path=os.path.join(os.getcwd(), "camera_detected_video"),
    frames_per_second=20,
    log_progress=True,
    minimum_percentage_probability=40,
    detection_timeout=20,
    per_minute_function=forMinute)

# output(plots)
resized = False
    start_cv = time.time()
    bbox, label, conf = cv.detect_common_objects(frame)
    elapsed_time_cv += (time.time() - start_cv)

    #print(bbox, label, conf)

    # draw bounding box over detected objects
    out = draw_bbox(frame, bbox, label, conf)

    output_movie_cv.write(frame)
    frame_number += 1

print("time spent in conversion: {}".format(elapsed_time_cv))
input_movie.release()

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

custom_objects = detector5.CustomObjects(person=True)

start = time.time()
video_path = detector5.detectCustomObjectsFromVideo(
    custom_objects=custom_objects,
    input_file_path=os.path.join(execution_path,
                                 "data/test_videos/hamilton_clip.mp4"),
    output_file_path=os.path.join(execution_path,
                                  "data/test_videos/obj_det_normal"),
    frames_per_second=29)
eplased_time = time.time() - start