| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import cv2
- import matplotlib.pyplot as plt
- import copy
- import numpy as np
- from src import util
- from src.body import Body
- body_estimation = Body('model/body_pose_model.pth')
- #hand_estimation = Hand('model/hand_pose_model.pth')
- test_image = 'pose_source_images/4-0.png'
- oriImg = cv2.imread(test_image) # B,G,R order
- candidate, subset = body_estimation(oriImg)
- print(candidate)
- np.save('pose_temp_data/4-0.npy',candidate)
- canvas = copy.deepcopy(oriImg)
- canvas = util.draw_bodypose(canvas, candidate, subset)
- # detect hand
- # hands_list = util.handDetect(candidate, subset, oriImg)
- # all_hand_peaks = []
- # for x, y, w, is_left in hands_list:
- # # cv2.rectangle(canvas, (x, y), (x+w, y+w), (0, 255, 0), 2, lineType=cv2.LINE_AA)
- # # 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, :])
- # peaks[:, 0] = np.where(peaks[:, 0]==0, peaks[:, 0], peaks[:, 0]+x)
- # peaks[:, 1] = np.where(peaks[:, 1]==0, peaks[:, 1], peaks[:, 1]+y)
- # # else:
- # # peaks = hand_estimation(cv2.flip(oriImg[y:y+w, x:x+w, :], 1))
- # # peaks[:, 0] = np.where(peaks[:, 0]==0, peaks[:, 0], w-peaks[:, 0]-1+x)
- # # peaks[:, 1] = np.where(peaks[:, 1]==0, peaks[:, 1], peaks[:, 1]+y)
- # # print(peaks)
- # all_hand_peaks.append(peaks)
- # canvas = util.draw_handpose(canvas, all_hand_peaks)
- plt.imshow(canvas[:, :, [2, 1, 0]])
- plt.axis('off')
- plt.savefig('pose_processed_images/4-0-result.jpg')
- plt.show()
|