Ask Your Question

Revision history [back]

How to detect a collision of two objects and stop video at collision point on saved video file

I have been working on Video analysis and want to detect a collision of two objects in a saved video file. So far I have done detecting the object in the video by using YOLO model in Python3, and I am able to collect box points of all object in each video frame and I have expanded a lot of time on this problem but I am not getting a result. please help me here

How to detect a collision of two objects and stop video at collision point on saved video file

I have been working on Video analysis and want to detect a collision of two objects in a saved video file. So far I have done detecting the object in the video by using YOLO model in Python3, and I am able to collect box points of all object in each video frame and I have expanded a lot of time on this problem but I am not getting a result. please help me here here.

How to detect a collision of two objects and stop video at collision point on saved video file

I have been working on Video analysis and want to detect a collision of two objects in a saved video file. So far I have done detecting the object in the video by using YOLO model in Python3, and I am able to collect box points of all object in each video frame and I have expanded a lot of time on this problem but I am not getting a result. please help me here.

from imageai.Detection import VideoObjectDetection
import os



execution_path = os.getcwd()

def forFrame(frame_number, output_array, output_count):
    print("FOR FRAME " , frame_number)
    print (costomObject)    
    boxes = output_array
    for i in boxes:
    box_points = list(i['box_points'])
    print (box_points)
    scores = i['percentage_probability']
    print (scores)
    if scores >=30.00:
        mid_x =(box_points[2]-box_points[0])/2
        print (mid_x)
        mid_y =(box_points[3]-box_points[1])/2
        print (mid_y)
        apx_distance = round((1-(box_points[2]-box_points[0]))**2,1)
        print("apx_diatance", apx_distance)



video_detector = VideoObjectDetection()
video_detector.setModelTypeAsYOLOv3()
video_detector.setModelPath(os.path.join(execution_path, "yolo.h5"))
video_detector.loadModel()
costomObject = video_detector.CustomObjects(tennis_racket=True, sports_ball=True)

video_detector.detectCustomObjectsFromVideo(custom_objects 
=costomObject,input_file_path=os.path.join(execution_path, "test2.0203709949409783.mp4"), 
output_file_path=os.path.join(execution_path, "IMG_2029_object_detected_1") ,  frames_per_second=30,  
per_frame_function = forFrame,  minimum_percentage_probability=30)