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

asked 2019-02-15 00:53:41 -0600

manoharsonwan gravatar image

updated 2019-02-15 04:35:22 -0600

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)
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-11-09 10:36:28.564093

Comments

what have you tried, so far ? show us !

berak gravatar imageberak ( 2019-02-15 02:45:39 -0600 )edit

Can you post code after boxpoint and before saving?

supra56 gravatar imagesupra56 ( 2019-02-15 03:58:05 -0600 )edit
1

@break Please look at the code which I have updated.

manoharsonwan gravatar imagemanoharsonwan ( 2019-02-15 04:37:02 -0600 )edit

yea, good. but honestly - box-box collision is a "solved problem", daily used in 2d games and whatnot. you're unable to look it up ?

berak gravatar imageberak ( 2019-02-15 04:52:50 -0600 )edit

I want to detect collision between tennis racket and ball, Is there any method that I can detect that collision time on video by using Python3

manoharsonwan gravatar imagemanoharsonwan ( 2019-02-15 05:23:29 -0600 )edit

really, you should not ask this !

http://lmgtfy.com/?q=detect+collision...

berak gravatar imageberak ( 2019-02-15 05:38:46 -0600 )edit

opencv does not have "collision detection" or "physics".

this is off-topic here. again, if you can't solve it on your own, go and ask the gamers.

berak gravatar imageberak ( 2019-02-15 09:36:46 -0600 )edit

@berak. You are missing. Corrected way like this: detect collision between tennis racket and ball opencv python

supra56 gravatar imagesupra56 ( 2019-02-16 07:11:45 -0600 )edit

supra56, thanks, but what am i missing ?

berak gravatar imageberak ( 2019-02-16 08:56:09 -0600 )edit

detect collision between tennis racket and ball python

supra56 gravatar imagesupra56 ( 2019-02-16 09:11:32 -0600 )edit