def process_video_frame(video_frame): video_frame = video_frame[:, :, :3] video_frame = scipy.misc.imresize(video_frame, (240, 320)) image_v = np.expand_dims((video_frame.astype('float') / 255.0) - 0.5, 0) keypoint_coord3d_tf, scale_tf, center_tf, keypoints_scoremap_tf = network_elements keypoint_coord3d_v, scale_v, center_v, keypoints_scoremap_v = sess.run( [keypoint_coord3d_tf, scale_tf, center_tf, keypoints_scoremap_tf], feed_dict={image_tf: image_v}) keypoints_scoremap_v = np.squeeze(keypoints_scoremap_v) keypoint_coord3d_v = np.squeeze(keypoint_coord3d_v) # post processing coord_hw_crop = detect_keypoints(np.squeeze(keypoints_scoremap_v)) coord_hw = trafo_coords(coord_hw_crop, center_v, scale_v, 256) plot_hand_2d(coord_hw, video_frame) score_label = process_keypoints(keypoint_coord3d_v) if score_label is not None: font = cv2.FONT_HERSHEY_SIMPLEX cv2.putText(video_frame, score_label, (10, 200), font, 1.0, (255, 0, 0), 2, cv2.LINE_AA) return video_frame
def process_img(known_finger_poses, img_name): image_raw = scipy.misc.imread(img_name)[:, :, :3] image_raw = np.array(Image.fromarray(image_raw).resize((320, 240))) image_v = np.expand_dims((image_raw.astype('float') / 255.0) - 0.5, 0) #if args.plot_fingers == 1: scale_v, center_v, keypoints_scoremap_v, \ keypoint_coord3d_v = sess.run([scale_tf, center_tf, keypoints_scoremap_tf,\ keypoint_coord3d_tf], feed_dict = {image_tf: image_v}) keypoints_scoremap_v = np.squeeze(keypoints_scoremap_v) keypoint_coord3d_v = np.squeeze(keypoint_coord3d_v) # post processing coord_hw_crop = detect_keypoints(np.squeeze(keypoints_scoremap_v)) coord_hw = trafo_coords(coord_hw_crop, center_v, scale_v, 256) plot_hand_2d(coord_hw, image_raw) # Classifying based on Geometry #if args.solve_by == 0: score_label = predict_by_geometry(keypoint_coord3d_v, known_finger_poses, 0.55) # Classifying based on Neural networks # elif args.solve_by == 1: # score_label = predict_by_neural_network(keypoint_coord3d_v, known_finger_poses, # args.pb_file, args.threshold) # Classifying based on SVM # elif args.solve_by == 2: # score_label = predict_by_svm(keypoint_coord3d_v, known_finger_poses, args.svc_file) # save processed image font = cv2.FONT_HERSHEY_SIMPLEX cv2.putText(image_raw, score_label, (10, 200), font, 1.0, (255, 0, 0), 2, cv2.LINE_AA) file_save_path = os.path.join('../images_out', "{}.png".format(int(time.time()))) mpimg.imsave(file_save_path, image_raw) return score_label
image_raw = scipy.misc.imresize(image_raw, (240, 320)) image_v = np.expand_dims((image_raw.astype('float') / 255.0) - 0.5, 0) if args.plot_fingers == 1: scale_v, center_v, keypoints_scoremap_v, \ keypoint_coord3d_v = sess.run([scale_tf, center_tf, keypoints_scoremap_tf,\ keypoint_coord3d_tf], feed_dict = {image_tf: image_v}) keypoints_scoremap_v = np.squeeze(keypoints_scoremap_v) keypoint_coord3d_v = np.squeeze(keypoint_coord3d_v) # post processing coord_hw_crop = detect_keypoints(np.squeeze(keypoints_scoremap_v)) coord_hw = trafo_coords(coord_hw_crop, center_v, scale_v, 256) plot_hand_2d(coord_hw, image_raw) else: keypoint_coord3d_v = sess.run(keypoint_coord3d_tf, feed_dict={image_tf: image_v}) # Classifying based on Geometry if args.solve_by == 0: score_label = predict_by_geometry(keypoint_coord3d_v, known_finger_poses, args.threshold) # Classifying based on Neural networks elif args.solve_by == 1: score_label = predict_by_neural_network(keypoint_coord3d_v, known_finger_poses, args.pb_file,