added experiments
This commit is contained in:
parent
1a7e485599
commit
793e099029
|
@ -1,2 +1,2 @@
|
|||
yolo.h5
|
||||
venv
|
||||
venv
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 496 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
85
main.py
85
main.py
|
@ -2,48 +2,51 @@ import matplotlib.pyplot as plt
|
|||
import saved_cordinats
|
||||
|
||||
|
||||
from imageai.Detection import VideoObjectDetection
|
||||
# from imageai.Detection import VideoObjectDetection
|
||||
|
||||
vid_obj_detect = VideoObjectDetection()
|
||||
vid_obj_detect.setModelTypeAsYOLOv3()
|
||||
# vid_obj_detect = VideoObjectDetection()
|
||||
# vid_obj_detect.setModelTypeAsYOLOv3()
|
||||
|
||||
vid_obj_detect.setModelPath(r"/home/mikolaj/2ait_tech/sportowe/film/yolo.h5")
|
||||
vid_obj_detect.loadModel()
|
||||
# vid_obj_detect.setModelPath(r"/home/mikolaj/2ait_tech/sportowe/film/yolo.h5")
|
||||
# vid_obj_detect.loadModel()
|
||||
|
||||
|
||||
person_points = []
|
||||
ball_points = []
|
||||
# person_points = []
|
||||
# ball_points = []
|
||||
|
||||
|
||||
def forFrame(frame_number, output_array, output_count, detected_frame):
|
||||
for index, object in enumerate(output_array):
|
||||
if object['name'] == 'sports ball':
|
||||
ball_points.append((index, object['box_points'][0], object['box_points'][3]))
|
||||
else:
|
||||
person_points.append((index, object['box_points'][0], object['box_points'][3]))
|
||||
# def forFrame(frame_number, output_array, output_count, detected_frame):
|
||||
# for index, object in enumerate(output_array):
|
||||
# if object['name'] == 'sports ball':
|
||||
# ball_points.append((index, object['box_points'][0], object['box_points'][1]))
|
||||
# else:
|
||||
# person_points.append((index, object['box_points'][0], object['box_points'][1]))
|
||||
|
||||
detected_vid_obj = vid_obj_detect.detectObjectsFromVideo(
|
||||
input_file_path = r"shorted.mp4",
|
||||
output_file_path = r"changed_shorted.mp4",
|
||||
frames_per_second=20,
|
||||
frame_detection_interval=20,
|
||||
log_progress=True,
|
||||
per_frame_function = forFrame,
|
||||
# per_second_function=forSeconds,
|
||||
return_detected_frame = True,
|
||||
)
|
||||
# detected_vid_obj = vid_obj_detect.detectObjectsFromVideo(
|
||||
# input_file_path = r"man.mp4",
|
||||
# output_file_path = r"man_changed.mp4",
|
||||
# frames_per_second=20,
|
||||
# frame_detection_interval=2,
|
||||
# log_progress=True,
|
||||
# per_frame_function = forFrame,
|
||||
# # per_second_function=forSeconds,
|
||||
# return_detected_frame = True,
|
||||
# )
|
||||
|
||||
with open('saved_cordinats', 'w') as file:
|
||||
file.write(str(person_points))
|
||||
file.write("\n"*3)
|
||||
file.write(str(ball_points))
|
||||
# with open('saved_cordinats', 'w') as file:
|
||||
# file.write(str(person_points))
|
||||
# file.write("\n"*3)
|
||||
# file.write(str(ball_points))
|
||||
|
||||
|
||||
fig = plt.figure()
|
||||
ax = fig.add_subplot(111)
|
||||
|
||||
# person_points = saved_cordinats.persons
|
||||
# ball_points= saved_cordinats.ball
|
||||
|
||||
ax.set_xlim([0, 960])
|
||||
ax.set_ylim([540, 0])
|
||||
person_points = saved_cordinats.persons
|
||||
ball_points= saved_cordinats.ball
|
||||
|
||||
COLORS = ['red', 'blue', 'orange', 'pink', 'yellow', 'brown', 'white', 'magenta', 'cyan']
|
||||
LABELS = ['p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9', 'p10']
|
||||
|
@ -101,29 +104,37 @@ persons = {
|
|||
|
||||
|
||||
for index, p in enumerate(person_points):
|
||||
persons[p[0]]['x'].append(p[1])
|
||||
persons[p[0]]['y'].append(p[2])
|
||||
# if p[0] > 6:
|
||||
# continue
|
||||
|
||||
if index - 1 >= 0:
|
||||
if abs(p[1] - person_points[index -1][1]) > 20:
|
||||
continue
|
||||
if abs(p[2] - person_points[index -1][2]) > 20:
|
||||
continue
|
||||
|
||||
persons[p[0]&7]['x'].append(p[1])
|
||||
persons[p[0]&7]['y'].append(p[2])
|
||||
|
||||
for k, v in persons.items():
|
||||
|
||||
if k > 2:
|
||||
continue
|
||||
# if k > 6:
|
||||
# continue
|
||||
|
||||
ax.plot(
|
||||
persons[k]['x'],
|
||||
persons[k]['y'],
|
||||
color=COLORS[k],
|
||||
color=COLORS[k%7],
|
||||
lw=2,
|
||||
label=LABELS[k]
|
||||
label=LABELS[k%7]
|
||||
)
|
||||
|
||||
|
||||
|
||||
ball_x = [x[1] for x in ball_points]
|
||||
ball_y = [x[2] for x in ball_points]
|
||||
|
||||
ax.plot(ball_x, ball_y, color='green', lw=2, label='ball')
|
||||
ax.legend()
|
||||
|
||||
plt.savefig('shorted_wykres.png')
|
||||
plt.savefig('man_shorted_wykres.png')
|
||||
plt.show()
|
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
Loading…
Reference in New Issue