demo.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import copy
  2. import cv2
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5. from src import util
  6. from src.body import Body
  7. body_estimation = Body('model/body_pose_model.pth')
  8. # hand_estimation = Hand('model/hand_pose_model.pth')
  9. test_image = 'pose_source_images/4-0.png'
  10. oriImg = cv2.imread(test_image) # B,G,R order
  11. candidate, subset = body_estimation(oriImg)
  12. print(candidate)
  13. np.save('pose_temp_data/4-0.npy', candidate)
  14. canvas = copy.deepcopy(oriImg)
  15. canvas = util.draw_bodypose(canvas, candidate, subset)
  16. # detect hand
  17. # hands_list = util.handDetect(candidate, subset, oriImg)
  18. # all_hand_peaks = []
  19. # for x, y, w, is_left in hands_list:
  20. # # cv2.rectangle(canvas, (x, y), (x+w, y+w), (0, 255, 0), 2, lineType=cv2.LINE_AA)
  21. # # cv2.putText(canvas, 'left' if is_left else 'right', (x, y), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
  22. # # if is_left:
  23. # # plt.imshow(oriImg[y:y+w, x:x+w, :][:, :, [2, 1, 0]])
  24. # # plt.show()
  25. # peaks = hand_estimation(oriImg[y:y+w, x:x+w, :])
  26. # peaks[:, 0] = np.where(peaks[:, 0]==0, peaks[:, 0], peaks[:, 0]+x)
  27. # peaks[:, 1] = np.where(peaks[:, 1]==0, peaks[:, 1], peaks[:, 1]+y)
  28. # # else:
  29. # # peaks = hand_estimation(cv2.flip(oriImg[y:y+w, x:x+w, :], 1))
  30. # # peaks[:, 0] = np.where(peaks[:, 0]==0, peaks[:, 0], w-peaks[:, 0]-1+x)
  31. # # peaks[:, 1] = np.where(peaks[:, 1]==0, peaks[:, 1], peaks[:, 1]+y)
  32. # # print(peaks)
  33. # all_hand_peaks.append(peaks)
  34. # canvas = util.draw_handpose(canvas, all_hand_peaks)
  35. plt.imshow(canvas[:, :, [2, 1, 0]])
  36. plt.axis('off')
  37. plt.savefig('pose_processed_images/4-0-result.jpg')
  38. plt.show()