added experiments

This commit is contained in:
Mikołaj Pokrywka 2023-01-31 16:12:51 +01:00
parent 1a7e485599
commit 793e099029
18 changed files with 58 additions and 38 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
yolo.h5 yolo.h5
venv venv

Binary file not shown.

After

Width:  |  Height:  |  Size: 496 KiB

Binary file not shown.

BIN
ch_man.mp4.avi Normal file

Binary file not shown.

BIN
ch_up.mp4.avi Normal file

Binary file not shown.

BIN
changed_man.mp4.avi Normal file

Binary file not shown.

BIN
changed_shorted.mp4.avi Normal file

Binary file not shown.

BIN
changed_up.mp4.avi Normal file

Binary file not shown.

85
main.py
View File

@ -2,48 +2,51 @@ import matplotlib.pyplot as plt
import saved_cordinats import saved_cordinats
from imageai.Detection import VideoObjectDetection # from imageai.Detection import VideoObjectDetection
vid_obj_detect = VideoObjectDetection() # vid_obj_detect = VideoObjectDetection()
vid_obj_detect.setModelTypeAsYOLOv3() # vid_obj_detect.setModelTypeAsYOLOv3()
vid_obj_detect.setModelPath(r"/home/mikolaj/2ait_tech/sportowe/film/yolo.h5") # vid_obj_detect.setModelPath(r"/home/mikolaj/2ait_tech/sportowe/film/yolo.h5")
vid_obj_detect.loadModel() # vid_obj_detect.loadModel()
person_points = [] # person_points = []
ball_points = [] # ball_points = []
def forFrame(frame_number, output_array, output_count, detected_frame): # def forFrame(frame_number, output_array, output_count, detected_frame):
for index, object in enumerate(output_array): # for index, object in enumerate(output_array):
if object['name'] == 'sports ball': # if object['name'] == 'sports ball':
ball_points.append((index, object['box_points'][0], object['box_points'][3])) # ball_points.append((index, object['box_points'][0], object['box_points'][1]))
else: # else:
person_points.append((index, object['box_points'][0], object['box_points'][3])) # person_points.append((index, object['box_points'][0], object['box_points'][1]))
detected_vid_obj = vid_obj_detect.detectObjectsFromVideo( # detected_vid_obj = vid_obj_detect.detectObjectsFromVideo(
input_file_path = r"shorted.mp4", # input_file_path = r"man.mp4",
output_file_path = r"changed_shorted.mp4", # output_file_path = r"man_changed.mp4",
frames_per_second=20, # frames_per_second=20,
frame_detection_interval=20, # frame_detection_interval=2,
log_progress=True, # log_progress=True,
per_frame_function = forFrame, # per_frame_function = forFrame,
# per_second_function=forSeconds, # # per_second_function=forSeconds,
return_detected_frame = True, # return_detected_frame = True,
) # )
with open('saved_cordinats', 'w') as file: # with open('saved_cordinats', 'w') as file:
file.write(str(person_points)) # file.write(str(person_points))
file.write("\n"*3) # file.write("\n"*3)
file.write(str(ball_points)) # file.write(str(ball_points))
fig = plt.figure() fig = plt.figure()
ax = fig.add_subplot(111) 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'] COLORS = ['red', 'blue', 'orange', 'pink', 'yellow', 'brown', 'white', 'magenta', 'cyan']
LABELS = ['p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9', 'p10'] LABELS = ['p1', 'p2', 'p3', 'p4', 'p5', 'p6', 'p7', 'p8', 'p9', 'p10']
@ -101,29 +104,37 @@ persons = {
for index, p in enumerate(person_points): for index, p in enumerate(person_points):
persons[p[0]]['x'].append(p[1]) # if p[0] > 6:
persons[p[0]]['y'].append(p[2]) # 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(): for k, v in persons.items():
if k > 2: # if k > 6:
continue # continue
ax.plot( ax.plot(
persons[k]['x'], persons[k]['x'],
persons[k]['y'], persons[k]['y'],
color=COLORS[k], color=COLORS[k%7],
lw=2, lw=2,
label=LABELS[k] label=LABELS[k%7]
) )
ball_x = [x[1] for x in ball_points] ball_x = [x[1] for x in ball_points]
ball_y = [x[2] 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.plot(ball_x, ball_y, color='green', lw=2, label='ball')
ax.legend() ax.legend()
plt.savefig('shorted_wykres.png') plt.savefig('man_shorted_wykres.png')
plt.show() plt.show()

BIN
man.mp4 Normal file

Binary file not shown.

BIN
man_changed.mp4.avi Normal file

Binary file not shown.

BIN
man_shorted_wykres.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

4
saved_cordinats Normal file

File diff suppressed because one or more lines are too long

5
saved_cordinats.py Normal file

File diff suppressed because one or more lines are too long

BIN
shorted.mp4 Normal file

Binary file not shown.

BIN
shorted_wykres.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
shorted_wykres_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
up.mp4 Normal file

Binary file not shown.