Update util.py
Browse files
util.py
CHANGED
@@ -306,65 +306,57 @@ def handDetect(candidate, subset, oriImg):
|
|
306 |
'''
|
307 |
return detect_result
|
308 |
|
309 |
-
def drawStickmodel(oriImg,x_ytupple,x_y_sticks,export_edges,export_peaks):
|
310 |
canvas = copy.deepcopy(oriImg)
|
311 |
|
|
|
|
|
|
|
|
|
|
|
|
|
312 |
|
313 |
-
|
314 |
-
[0, 255, 85], [0, 255, 170], [0, 255, 255], [0, 170, 255], [0, 85, 255], [0, 0, 255], [85, 0, 255],
|
315 |
-
[170, 0, 255], [255, 0, 255], [255, 0, 170], [255, 0, 85], [255,255,0], [255,255,85], [255,255,170],
|
316 |
-
[255,255,255],[170,255,255],[85,255,255],[0,255,255]]
|
317 |
-
stickwidth=4
|
318 |
-
|
319 |
-
for idx,(mX,mY,angle,length) in enumerate(x_y_sticks):
|
320 |
cur_canvas = canvas.copy()
|
321 |
-
|
322 |
-
|
323 |
cv2.fillConvexPoly(cur_canvas, polygon, colors[idx])
|
324 |
canvas = cv2.addWeighted(canvas, 0.4, cur_canvas, 0.6, 0)
|
325 |
|
326 |
-
|
327 |
-
|
328 |
-
for idx,(x,y) in enumerate(x_ytupple):
|
329 |
cv2.circle(canvas, (int(x), int(y)), 4, colors[idx], thickness=-1)
|
330 |
-
|
331 |
|
332 |
-
|
333 |
fig = Figure(figsize=plt.figaspect(canvas))
|
334 |
fig.subplots_adjust(0, 0, 1, 1)
|
335 |
-
fig.subplots_adjust(bottom=0, top=1, left=0, right=1)
|
336 |
-
bg = FigureCanvas(fig)
|
337 |
ax = fig.subplots()
|
338 |
ax.axis('off')
|
339 |
ax.imshow(canvas)
|
340 |
|
341 |
-
edges = [[0, 1], [1, 2], [2, 3], [3, 4], [0, 5], [5, 6], [6, 7], [7, 8], [0, 9],
|
342 |
-
|
|
|
343 |
|
344 |
for both_hand_edges in export_edges:
|
345 |
-
for (ie,(x1, y1),(x2, y2)) in both_hand_edges:
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
width, height = ax.figure.get_size_inches() * ax.figure.get_dpi()
|
350 |
|
351 |
for both_hand_peaks in export_peaks:
|
352 |
-
for (x,y,text) in both_hand_peaks:
|
353 |
-
# print(f"new ax.plot({x}, {y}, 'r.')")
|
354 |
ax.plot(x, y, 'r.')
|
355 |
|
356 |
-
|
357 |
-
|
358 |
-
# print(f'NEW width = {width}, height={height}')
|
359 |
bg.draw()
|
360 |
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
|
366 |
-
|
367 |
-
return cv2.resize(canvas,(math.ceil(width),math.ceil(height)))
|
368 |
|
369 |
def draw_bar_plot_below_image(image, predictions, title, origImg):
|
370 |
"""
|
|
|
306 |
'''
|
307 |
return detect_result
|
308 |
|
309 |
+
def drawStickmodel(oriImg, x_ytupple, x_y_sticks, export_edges, export_peaks):
|
310 |
canvas = copy.deepcopy(oriImg)
|
311 |
|
312 |
+
colors = [[255, 0, 0], [255, 85, 0], [255, 170, 0], [255, 255, 0], [170, 255, 0],
|
313 |
+
[85, 255, 0], [0, 255, 0], [0, 255, 85], [0, 255, 170], [0, 255, 255],
|
314 |
+
[0, 170, 255], [0, 85, 255], [0, 0, 255], [85, 0, 255], [170, 0, 255],
|
315 |
+
[255, 0, 255], [255, 0, 170], [255, 0, 85], [255,255,0], [255,255,85],
|
316 |
+
[255,255,170], [255,255,255],[170,255,255],[85,255,255],[0,255,255]]
|
317 |
+
stickwidth = 4
|
318 |
|
319 |
+
for idx, (mX, mY, angle, length) in enumerate(x_y_sticks):
|
|
|
|
|
|
|
|
|
|
|
|
|
320 |
cur_canvas = canvas.copy()
|
321 |
+
polygon = cv2.ellipse2Poly((int(mX), int(mY)), (int(length / 2), stickwidth),
|
322 |
+
int(angle), 0, 360, 1)
|
323 |
cv2.fillConvexPoly(cur_canvas, polygon, colors[idx])
|
324 |
canvas = cv2.addWeighted(canvas, 0.4, cur_canvas, 0.6, 0)
|
325 |
|
326 |
+
for idx, (x, y) in enumerate(x_ytupple):
|
|
|
|
|
327 |
cv2.circle(canvas, (int(x), int(y)), 4, colors[idx], thickness=-1)
|
|
|
328 |
|
329 |
+
# Handpose
|
330 |
fig = Figure(figsize=plt.figaspect(canvas))
|
331 |
fig.subplots_adjust(0, 0, 1, 1)
|
|
|
|
|
332 |
ax = fig.subplots()
|
333 |
ax.axis('off')
|
334 |
ax.imshow(canvas)
|
335 |
|
336 |
+
edges = [[0, 1], [1, 2], [2, 3], [3, 4], [0, 5], [5, 6], [6, 7], [7, 8], [0, 9],
|
337 |
+
[9, 10], [10, 11], [11, 12], [0, 13], [13, 14], [14, 15], [15, 16],
|
338 |
+
[0, 17], [17, 18], [18, 19], [19, 20]]
|
339 |
|
340 |
for both_hand_edges in export_edges:
|
341 |
+
for (ie, (x1, y1), (x2, y2)) in both_hand_edges:
|
342 |
+
ax.plot([x1, x2], [y1, y2],
|
343 |
+
color=matplotlib.colors.hsv_to_rgb([ie/float(len(edges)), 1.0, 1.0]))
|
|
|
|
|
344 |
|
345 |
for both_hand_peaks in export_peaks:
|
346 |
+
for (x, y, text) in both_hand_peaks:
|
|
|
347 |
ax.plot(x, y, 'r.')
|
348 |
|
349 |
+
# Convert figure to numpy array
|
350 |
+
bg = FigureCanvas(fig)
|
|
|
351 |
bg.draw()
|
352 |
|
353 |
+
width, height = fig.get_size_inches() * fig.get_dpi()
|
354 |
+
buf = bg.buffer_rgba()
|
355 |
+
canvas = np.frombuffer(buf, dtype=np.uint8).reshape(int(height), int(width), 4)
|
356 |
+
canvas = canvas[:, :, :3] # keep only RGB
|
357 |
|
358 |
+
plt.close(fig) # clean up
|
359 |
+
return cv2.resize(canvas, (math.ceil(width), math.ceil(height)))
|
360 |
|
361 |
def draw_bar_plot_below_image(image, predictions, title, origImg):
|
362 |
"""
|