Skip to content

Commit 3e414e6

Browse files
author
Arash Hosseini
committed
camera feed
1 parent b5c76a3 commit 3e414e6

File tree

2 files changed

+58
-9
lines changed

2 files changed

+58
-9
lines changed

demo_camera.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,47 @@
1-
# TODO
1+
import demo_image
2+
import argparse
3+
import cv2
4+
import time
5+
import config
6+
from model import get_testing_model
7+
import json
8+
import os
9+
10+
if __name__ == '__main__':
11+
parser = argparse.ArgumentParser()
12+
parser.add_argument('--output', type=str, default='result.png', help='output image')
13+
parser.add_argument('--model', type=str, default='model/keras/model.h5', help='path to the weights file')
14+
args = parser.parse_args()
15+
output = args.output
16+
keras_weights_file = args.model
17+
18+
tic = time.time()
19+
print('start processing...')
20+
# load model
21+
# authors of original model don't use
22+
# vgg normalization (subtracting mean) on input images
23+
model = get_testing_model(38,19)
24+
model.load_weights(keras_weights_file)
25+
# load config
26+
_config = config.GetConfig("Canonical")
27+
toc = time.time()
28+
print ('processing time is %.5f' % (toc - tic))
29+
cam = cv2.VideoCapture(0)
30+
frame = 0
31+
while True:
32+
ret_val, canvas = cam.read()
33+
if ret_val:
34+
scanvas, pose_keypoints = demo_image.process(canvas,
35+
_config,
36+
model)
37+
38+
with open(os.path.join("./json", '{0}_keypoints.json'.format(str(frame).zfill(12))), 'w') as outfile:
39+
json.dump(pose_keypoints, outfile)
40+
41+
cv2.imshow('keras Pose Estimation', canvas)
42+
cv2.imwrite(output, canvas)
43+
frame += 1
44+
if cv2.waitKey(1) == 27:
45+
break
46+
47+
cv2.destroyAllWindows()

demo_image.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@
2727
[170, 0, 255], [255, 0, 255], [255, 0, 170], [255, 0, 85]]
2828

2929

30-
def process (input_image, params):
31-
oriImg = cv2.imread(input_image) # B,G,R order
32-
print (oriImg.shape[0], params.width)
30+
31+
32+
def process (input_image, params, model):
33+
34+
oriImg = input_image
35+
if isinstance(input_image, str):
36+
oriImg = cv2.imread(input_image) # B,G,R order
37+
3338
multiplier = [x * params.width / oriImg.shape[0] for x in params.scale_search]
3439

3540
heatmap_avg = np.zeros((oriImg.shape[0], oriImg.shape[1], 19))
@@ -201,11 +206,9 @@ def process (input_image, params):
201206
subset = np.delete(subset, deleteIdx, axis=0)
202207
flat = [0.0 for i in range(36)]
203208
dc = {"people":[]}
204-
canvas = cv2.imread(input_image) # B,G,R order
209+
canvas = oriImg # B,G,R order
205210
for i in range(18):
206211
for j in range(len(all_peaks[i])):
207-
print (all_peaks[i][j][0:2])
208-
209212
flat[i*2] = int(all_peaks[i][j][0:2][0])
210213
flat[i*2+1] = int(all_peaks[i][j][0:2][1])
211214
cv2.circle(canvas, all_peaks[i][j][0:2], 4, colors[i], thickness=-1)
@@ -248,12 +251,12 @@ def process (input_image, params):
248251
# load model
249252
# authors of original model don't use
250253
# vgg normalization (subtracting mean) on input images
254+
251255
model = get_testing_model(38,19)
252256
model.load_weights(keras_weights_file)
253-
254257
# load config
255258
_config = config.GetConfig("Canonical")
256-
canvas, pose_keypoints = process(input_image, _config)
259+
canvas, pose_keypoints = process(input_image, _config, model)
257260

258261
toc = time.time()
259262
print ('processing time is %.5f' % (toc - tic))

0 commit comments

Comments
 (0)