-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_partial_skeleton_from_video.py
84 lines (70 loc) · 2.55 KB
/
generate_partial_skeleton_from_video.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import cv2
import PartialSkeleton
import video_utils
from estimator import TfPoseEstimator
from networks import get_graph_path
class CoordinateStore:
def __init__(self):
self.points = []
def select_point(self, event, x, y, flags, param):
if event == cv2.EVENT_LBUTTONDBLCLK:
cv2.circle(img, (x, y), 3, (255, 0, 0), -1)
self.points.append((x, y))
def generate_skeletonize_video():
"""
The method takes images , save a skeleton per image and creates a video output
:return:
"""
input_folder = "./videos/demo/"
output_folder = "./videos"
results_folder = "./images/demo/"
input_video = "./videos/demo.mp4"
images = video_utils.load_images_from_folder(input_folder)
w = 432
h = 368
estimator = TfPoseEstimator(get_graph_path('mobilenet_thin'), target_size=(w, h))
count = 1
for i in images:
image_parts = estimator.inference(i, scales=None)
image_skeleton = TfPoseEstimator.draw_humans(i, image_parts, imgcopy=True)
cv2.imwrite(r".\images\demo\{}.png".format(count), image_skeleton)
count = count + 1
video_utils.create_video(input_video, results_folder, output_folder)
if __name__ == '__main__':
input_folder = "./videos/walking/"
results_folder = "./images/results/"
input_video = "./videos/walking.mp4"
output_folder = "./videos"
print("Start splitting video")
video_utils.split_video(input_video, input_folder)
print("Video was splited")
print("Loading all images")
images = video_utils.load_images_from_folder(input_folder, False, True)
print("Loaded {} images from {} folder".format(images.__len__(), input_folder))
first_image = images[0]
# instantiate class
coordinateStore1 = CoordinateStore()
# Bind the function to window
img = images[0]
cv2.namedWindow('image')
cv2.setMouseCallback('image', coordinateStore1.select_point)
while 1:
cv2.imshow('image', first_image)
k = cv2.waitKey(20) & 0xFF
if k == 27: # ESC
break
cv2.destroyAllWindows()
print("Selected Coordinates: ")
for i in coordinateStore1.points:
print(i)
hip = coordinateStore1.points
w = 432
h = 368
estimator = TfPoseEstimator(get_graph_path('mobilenet_thin'), target_size=(w, h))
count = 0
for img in images:
PartialSkeleton.skeletonize(estimator, img, hip, count)
count += 1
print("Creating output video...")
video_utils.create_video(input_video, results_folder, output_folder)
print("Video was created.")