Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hzzone committed Nov 15, 2018
1 parent 6e3952c commit 6e71411
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
11 changes: 6 additions & 5 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
body_estimation = Body('model/body_pose_model.pth')
hand_estimation = Hand('model/hand_pose_model.pth')

test_image = 'images/demo.jpg'
# test_image = 'images/demo.jpg'
test_image = '/Users/hzzone/Desktop/1.jpeg'
oriImg = cv2.imread(test_image) # B,G,R order
candidate, subset = body_estimation(oriImg)
# canvas = util.draw_bodypose(oriImg, candidate, subset)
Expand All @@ -24,10 +25,10 @@
cv2.putText(canvas, 'left' if is_left else 'right', (x, y), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)

if is_left:
plt.imshow(oriImg[y:y+w, x:x+w, :][:, :, [2, 1, 0]])
plt.show()
# peaks = hand_estimation(oriImg[y:y+w, x:x+w, :])
# canvas = util.draw_handpose(canvas, peaks, True)
# plt.imshow(oriImg[y:y+w, x:x+w, :][:, :, [2, 1, 0]])
# plt.show()
peaks = hand_estimation(oriImg[y:y+w, x:x+w, :], x, y)
canvas = util.draw_handpose(canvas, peaks)

plt.imshow(canvas[:, :, [2, 1, 0]])
plt.show()
Expand Down
4 changes: 2 additions & 2 deletions python/hand.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, model_path):
self.model.load_state_dict(model_dict)
self.model.eval()

def __call__(self, oriImg):
def __call__(self, oriImg, initial_x=0, initial_y=0):
scale_search = [0.5, 1.0, 1.5, 2.0]
# scale_search = [0.5]
boxsize = 368
Expand Down Expand Up @@ -67,7 +67,7 @@ def __call__(self, oriImg):
map_ori[label_img == 0] = 0

y, x = util.npmax(map_ori)
all_peaks.append([x, y])
all_peaks.append([x+initial_x, y+initial_y])
return np.array(all_peaks)

if __name__ == "__main__":
Expand Down
16 changes: 7 additions & 9 deletions python/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import numpy as np
import math
import cv2
import colorsys
import matplotlib


def padRightDownCorner(img, stride, padValue):
Expand Down Expand Up @@ -68,19 +70,13 @@ def draw_bodypose(canvas, candidate, subset):
# plt.imshow(canvas[:, :, [2, 1, 0]])
return canvas

def draw_handpose(canvas, peaks, show_number=False, initial_x=0, initial_y=0):
def draw_handpose(canvas, peaks, show_number=False):
edges = [[0, 1], [1, 2], [2, 3], [3, 4], [0, 5], [5, 6], [6, 7], [7, 8], [0, 9], [9, 10], \
[10, 11], [11, 12], [0, 13], [13, 14], [14, 15], [15, 16], [0, 17], [17, 18], [18, 19], [19, 20]]
colors = [[100, 100, 100], [100, 0, 0], [150, 0, 0], \
[200, 0, 0], [255, 0, 0], [100, 100, 0], [150, 150, 0], [200, 200, 0], \
[255, 255, 0], [0, 100, 50], [0, 150, 75], [0, 200, 100], [0, 255, 125], \
[0, 50, 100], [0, 75, 150], [0, 100, 200], \
[0, 125, 255], [100, 0, 100], [150, 0, 150], \
[200, 0, 200], [255, 0, 255]]

for ie, e in enumerate(edges):
if np.sum(np.all(peaks[e], axis=1)==0)==0:
cv2.line(canvas, tuple(peaks[e[0]]), tuple(peaks[e[1]]), colors[ie], thickness=1)
cv2.line(canvas, tuple(peaks[e[0]]), tuple(peaks[e[1]]), matplotlib.colors.hsv_to_rgb([ie/float(len(edges)), 1.0, 1.0])*255, thickness=2)
for i, keyponit in enumerate(peaks):
cv2.circle(canvas, tuple(keyponit), 2, (0, 0, 255), thickness=-1)
if show_number:
Expand Down Expand Up @@ -142,7 +138,9 @@ def handDetect(candidate, subset, oriImg):
if x + width > image_width: width1 = image_width - x
if y + width > image_height: width2 = image_height - y
width = min(width1, width2)
detect_result.append([int(x), int(y), int(width), is_left])
# the max hand box value is 20 pixels
if width >= 20:
detect_result.append([int(x), int(y), int(width), is_left])

'''
return value: [[x, y, w, True if left hand else False]].
Expand Down

0 comments on commit 6e71411

Please sign in to comment.