How to detect a collision of two objects and stop video at collision point on saved video file [closed]
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)
what have you tried, so far ? show us !
Can you post code after boxpoint and before saving?
@break Please look at the code which I have updated.
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 ?
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
really, you should not ask this !
http://lmgtfy.com/?q=detect+collision...
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. You are missing. Corrected way like this: detect collision between tennis racket and ball opencv python
supra56, thanks, but what am i missing ?
detect collision between tennis racket and ball python