# Path: util/config.py
# def load_config(filename = "pose_cfg.yaml"):
#     if 'POSE_PARAM_PATH' in os.environ:
#         filename = os.environ['POSE_PARAM_PATH'] + '/' + filename
#     return cfg_from_file(filename)
# 
# Path: nnet/predict.py
# def setup_pose_prediction(cfg):
# def extract_cnn_output(outputs_np, cfg, pairwise_stats = None):
# def argmax_pose_predict(scmap, offmat, stride):
# def argmax_arrows_predict(scmap, offmat, pairwise_diff, stride):
# 
# Path: util/visualize.py
# def _npcircle(image, cx, cy, radius, color, transparency=0.0):
# def check_point(cur_x, cur_y, minx, miny, maxx, maxy):
# def visualize_joints(image, pose):
# def show_heatmaps(cfg, img, scmap, pose, cmap="jet"):
# def show_arrows(cfg, img, pose, arrows):
# def waitforbuttonpress():
# 
# Path: dataset/pose_dataset.py
# def data_to_input(data):
#     return np.expand_dims(data, axis=0).astype(float)


import os
import sys
from scipy.misc import imread
from util.config import load_config
from nnet import predict
from util import visualize
from dataset.pose_dataset import data_to_input

sys.path.append(os.path.dirname(__file__) + "/../")




cfg = load_config("demo/pose_cfg.yaml")

# Load and setup CNN part detector
sess, inputs, outputs = predict.setup_pose_prediction(cfg)

# Read image from file
file_name = "demo/image.png"
image = imread(file_name, mode='RGB')

image_batch = data_to_input(image)

# Compute prediction with the CNN
outputs_np = sess.run(outputs, feed_dict={inputs: image_batch})
scmap, locref, _ = predict.extract_cnn_output(outputs_np, cfg)

# Extract maximum scoring location from the heatmap, assume 1 person
pose = predict.argmax_pose_predict(scmap, locref, cfg.stride)

# Visualise

# Path: util/config.py
# def load_config(filename = "pose_cfg.yaml"):
#     if 'POSE_PARAM_PATH' in os.environ:
#         filename = os.environ['POSE_PARAM_PATH'] + '/' + filename
#     return cfg_from_file(filename)
# 
# Path: nnet/predict.py
# def setup_pose_prediction(cfg):
# def extract_cnn_output(outputs_np, cfg, pairwise_stats = None):
# def argmax_pose_predict(scmap, offmat, stride):
# def argmax_arrows_predict(scmap, offmat, pairwise_diff, stride):
# 
# Path: util/visualize.py
# def _npcircle(image, cx, cy, radius, color, transparency=0.0):
# def check_point(cur_x, cur_y, minx, miny, maxx, maxy):
# def visualize_joints(image, pose):
# def show_heatmaps(cfg, img, scmap, pose, cmap="jet"):
# def show_arrows(cfg, img, pose, arrows):
# def waitforbuttonpress():
# 
# Path: dataset/pose_dataset.py
# def data_to_input(data):
#     return np.expand_dims(data, axis=0).astype(float)


# Path: demo/singleperson.py
import os
import sys
from scipy.misc import imread
from util.config import load_config
from nnet import predict
from util import visualize
from dataset.pose_dataset import data_to_input


sys.path.append(os.path.dirname(__file__) + "/../")




cfg = load_config("demo/pose_cfg.yaml")

# Load and setup CNN part detector
sess, inputs, outputs = predict.setup_pose_prediction(cfg)

# Read image from file
file_name = "demo/image.png"
image = imread(file_name, mode='RGB')

image_batch = data_to_input(image)

# Compute prediction with the CNN
outputs_np = sess.run(outputs, feed_dict={inputs: image_batch})
scmap, locref, _ = predict.extract_cnn_output(outputs_np, cfg)

# Extract maximum scoring location from the heatmap, assume 1 person
pose = predict.argmax_pose_predict(scmap, locref, cfg.stride)

# Visualise

visualize.show_heatmaps(cfg, image, scmap, pose)