예제 #1
0
def Human_pose_estimation(video_address, describe,num_classes):

    spatial_feature_list_train = []
    net_pose = HumanPoseIRNetwork()
    net_pose.restore("./models_pose/MPII+LSP.ckpt")
    img ,label = company_data_process(video_address,describe,num_classes)
    # 使用该模型生成pose描述向量
    print("生成训练集的空间pose特征向量")
    i=0
    for image in img: 
        # print(batch_image.shape)
        print("处理第"+str(i)+"个batch,维度信息为"+str(np.array(image).shape))
        spatial_feature = net_pose.feed_forward_features(image)
        print(np.array(spatial_feature).shape)
        # spatial-feature shape [298,17,17,32]
        print(spatial_feature)
        print(label[i])
        spatial_feature_list_train.append(np.array(spatial_feature))
        i+=1

    # print(spatial_feature_list_train)
    return spatial_feature_list_train,label
예제 #2
0
    def Human_pose_estimation(self, file_add, des):
        """
        此方法的目的是调用训练好的HumanPose模型
        将所有的图片帧处理成pose 描述向量
        """
        # 恢复模型
        # 处理训练集数据
        spatial_feature_list_train = []
        net_pose = HumanPoseIRNetwork()
        net_pose.restore("./models_pose/MPII+LSP.ckpt")
        # img,label = self.casia_data_process(self.trainset_dir)
        img, label = self.company_data_process(file_add, des)
        # 使用该模型生成pose描述向量

        print("生成训练集的空间pose特征向量")
        i = 0
        for image in img:
            # print(batch_image.shape)
            print("处理第" + str(i) + "个batch,维度信息为" + str(np.array(image).shape))
            spatial_feature = net_pose.feed_forward_features(image)
            spatial_feature_list_train.append(np.array(spatial_feature))
            i += 1
        # 所有的训练集视频帧的pose特征向量提取完毕

        # 验证集的处理方式
        # spatial_feature_list_val = []
        # val_img,val_label = self.company_data_process(self.valset_dir,'val')
        # print("生成验证集数据的空间pose特征向量")
        # i_=0
        # for batch_image_ in val_img:
        #     # print(batch_image.shape)
        #     print("处理第"+str(i_)+"个batch,维度信息为"+str(np.array(batch_image_).shape))
        #     spatial_feature_ = net_pose.feed_forward_features(batch_image_)
        #     print(spatial_feature_.shape)
        #     spatial_feature_list_val.append(np.array(spatial_feature_))
        #     i_+=1
        # 返回所有的特征供下一个模型使用

        return spatial_feature_list_train, label
import numpy as np
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
from scipy.misc import imresize, imread

from human_pose_nn import HumanPoseIRNetwork

net_pose = HumanPoseIRNetwork()
net_pose.restore('/home/pank/Project/gait-recognition/MPII+LSP.ckpt')
#images/dummy.jpg
img = imread('/home/pank/Project/gait-recognition/L.jpg')
img = imresize(img, [299, 299])
img_batch = np.expand_dims(img, 0)

y, x, a = net_pose.estimate_joints(img_batch)
y, x, a = np.squeeze(y), np.squeeze(x), np.squeeze(a)

joint_names = [
    'right ankle ', 'right knee ', 'right hip', 'left hip', 'left knee',
    'left ankle', 'pelvis', 'thorax', 'upper neck', 'head top', 'right wrist',
    'right elbow', 'right shoulder', 'left shoulder', 'left elbow',
    'left wrist'
]

# Print probabilities of each estimation
for i in range(16):
    print('%s: %.02f%%' % (joint_names[i], a[i] * 100))

# Create image
colors = [
def dummyposetrain():
    import numpy as np
    import matplotlib as mpl
    mpl.use('TkAgg')
    import matplotlib.pyplot as plt
    import os
    import cv2
    from scipy.misc import imresize, imread
    from human_pose_nn import HumanPoseIRNetwork
    from scipy.spatial import distance
    from scipy.fftpack import fft, ifft
    net_pose = HumanPoseIRNetwork()
    net_pose.restore('models/MPII+LSP.ckpt')
    """def plotting(p,t,s):
        x = [i for i in range(1, len(all_file))]
        p=fft(p)
        t=fft(t)
        p=[i.real for i in p]
        plt.axis("off")
        #t=[i.real for i in p]
        #print(p,t)
        plt.plot(p, "r",label="rknee")
        
        
        # plt.legend()
        plt.show()"""
    def skeleton(ipath):
        img = imread(ipath)
        # img2 = imread('white.png')
        img = imresize(img, [299, 299])
        # img2 = imresize(img2, [299, 299])
        img_batch = np.expand_dims(img, 0)

        y, x, a = net_pose.estimate_joints(img_batch)
        y, x, a = np.squeeze(y), np.squeeze(x), np.squeeze(a)

        # checking unique features for a person
        """elbow = (x[11], y[11], 0)
        wrist = (x[10], y[10], 0)
        shoulder = (x[12], y[12], 0)
        hip = (x[2], y[2], 0)
        knee = (x[1], y[1], 0)"""
        rhip = y[2]
        lhip = y[3]
        rwrist = y[10]
        lwrist = y[15]
        rknee = y[1]
        lknee = y[4]
        pelvis = y[6]
        head = y[9]
        """elbow_wrist = distance.euclidean(elbow, wrist)
        shoulder_elbow = distance.euclidean(elbow, shoulder)
        hip_knee = distance.euclidean(hip, knee)
        ewlist.append(elbow_wrist)
        shellist.append(shoulder_elbow)
        hiknlist.append(hip_knee)"""
        rhipl.append(rhip)
        lhipl.append(lhip)

        lwristl.append(lwrist)
        rwristl.append(rwrist)

        lkneel.append(lknee)
        rkneel.append(rknee)

        pelvisl.append(pelvis)

        headl.append(head)

        # ylist.append(str(y[1])) # only for right knee , value is in string.For comparing,convert to int

        joint_names = [
            'right ankle ', 'right knee ', 'right hip', 'left hip',
            'left knee', 'left ankle', 'pelvis', 'thorax', 'upper neck',
            'head top', 'right wrist', 'right elbow', 'right shoulder',
            'left shoulder', 'left elbow', 'left wrist'
        ]

        # Print probabilities of each estimation
        """for i in range(16):
            print('%s: %.02f%%' % (joint_names[i], a[i] * 100))"""

        # Create image
        """colors = ['r', 'r', 'b', 'm', 'm', 'y', 'g', 'g', 'b', 'c', 'r', 'r', 'b', 'm', 'm', 'c']
        for i in range(16):
            if i < 15 and i not in {5, 9}:
                plt.plot([x[i], x[i + 1]], [y[i], y[i + 1]], color=colors[i], linewidth=3)
        plot_img(img2, ipath)"""

    # change the directory to images folder to store the frames obtained from the training videos.
    #if not present create a new directory in the same folder as the program.
    os.chdir(r"images")
    img_dir = os.getcwd()
    image_list, rhipl,lhipl,rkneel,lkneel,rwristl,lwristl,headl,pelvisl=[],[],[],[],[],[],[],[],[]

    jointll = [rhipl, lhipl, rkneel, lkneel, rwristl, lwristl, headl, pelvisl]
    strjoint = [
        "rhipl", "lhipl", "rkneel", "lkneel", "rwristl", "lwristl", "headl",
        "pelvisl"
    ]

    all_file = os.listdir(img_dir)

    for file in all_file:
        if file.endswith(".jpg"):
            skeleton(file)
    #print(ranklelist,lanklelist)
    # Plotting the unique points/lengths
    # Making a folder 'traindata' which stores the data of new people who data is given to train.
    os.mkdir("TrainData/" + str(inputValue))
    print("Processing fft..")
    for i in range(len(jointll)):
        jointll[i] = [x.real for x in fft(jointll[i])]
        print("Creating " + strjoint[i] + ".txt")
        txtfile = open(
            "TrainData/" + str(inputValue) + "/" + strjoint[i] + ".txt", "w")
        txtfile.write(str(jointll[i]))
        txtfile.close()
    for i in all_file:
        os.remove(i)
    print("Finished...!")
def dummyposetest():
    import numpy as np
    import matplotlib as mpl
    mpl.use('TkAgg')
    import matplotlib.pyplot as plt
    import os
    import cv2
    from scipy.misc import imresize, imread
    from human_pose_nn import HumanPoseIRNetwork
    from scipy.spatial import distance
    from scipy.fftpack import fft, ifft
    net_pose = HumanPoseIRNetwork()
    net_pose.restore('models/MPII+LSP.ckpt')
    """def plotting(p,t,s):
        x = [i for i in range(1, len(all_file))]
        p=fft(p)
        t=fft(t)
        p=[i.real for i in p]
        plt.axis("off")
        #t=[i.real for i in p]
        #print(p,t)
        plt.plot(p, "r",label="rknee")
        
        
        # plt.legend()
        plt.show()"""
    def skeleton(ipath):
        img = imread(ipath)
        # img2 = imread('white.png')
        img = imresize(img, [299, 299])
        # img2 = imresize(img2, [299, 299])
        img_batch = np.expand_dims(img, 0)

        y, x, a = net_pose.estimate_joints(img_batch)
        y, x, a = np.squeeze(y), np.squeeze(x), np.squeeze(a)

        # checking unique features for a person
        """elbow = (x[11], y[11], 0)
        wrist = (x[10], y[10], 0)
        shoulder = (x[12], y[12], 0)
        hip = (x[2], y[2], 0)
        knee = (x[1], y[1], 0)"""
        rhip = y[2]
        lhip = y[3]
        rwrist = y[10]
        lwrist = y[15]
        rknee = y[1]
        lknee = y[4]
        pelvis = y[6]
        head = y[9]
        """elbow_wrist = distance.euclidean(elbow, wrist)
        shoulder_elbow = distance.euclidean(elbow, shoulder)
        hip_knee = distance.euclidean(hip, knee)
        ewlist.append(elbow_wrist)
        shellist.append(shoulder_elbow)
        hiknlist.append(hip_knee)"""
        rhipl.append(rhip)
        lhipl.append(lhip)

        lwristl.append(lwrist)
        rwristl.append(rwrist)

        lkneel.append(lknee)
        rkneel.append(rknee)

        pelvisl.append(pelvis)

        headl.append(head)

        # ylist.append(str(y[1])) # only for right knee , value is in string.For comparing,convert to int

        joint_names = [
            'right ankle ', 'right knee ', 'right hip', 'left hip',
            'left knee', 'left ankle', 'pelvis', 'thorax', 'upper neck',
            'head top', 'right wrist', 'right elbow', 'right shoulder',
            'left shoulder', 'left elbow', 'left wrist'
        ]

    # Changing the directory again to images folder so that frames from the testing videos can be saved.
    #if not present create a new directory in the same folder as the program.
    os.chdir(r"images")
    img_dir = os.getcwd()
    image_list, rhipl,lhipl,rkneel,lkneel,rwristl,lwristl,headl,pelvisl=[],[],[],[],[],[],[],[],[]

    jointll = [headl, lhipl, lkneel, lwristl, pelvisl, rhipl, rkneel, rwristl]
    strjoint = [
        "headl", "lhipl", "lkneel", "lwristl", "pelvisl", "rhipl", "rkneel",
        "rwristl"
    ]

    all_file = os.listdir(img_dir)
    for file in all_file:
        if file.endswith(".jpg"):

            skeleton(file)
            print("WORKING")
    #print(ranklelist,lanklelist)
    # Plotting the unique points/lengths
    for i in range(len(jointll)):
        jointll[i] = [x.real for x in fft(jointll[i])]
    for i in all_file:
        os.remove(i)
    print("Finished...!")

    return jointll
예제 #6
0
import os
import cv2 as cv
import numpy as np
import pandas
from human_pose_nn import HumanPoseIRNetwork
from gait_nn import GaitNetwork

path = 'datasets/WalkingVideos'

videos = os.listdir(path)
videos.sort()

# Initialize computational graphs of both sub-networks
net_pose = HumanPoseIRNetwork()

# net_gait = GaitNetwork(recurrent_unit = 'GRU', rnn_layers = 2)

# Load pre-trained models
net_pose.restore('models/MPII+LSP.ckpt')
# net_gait.restore('models/H3.6m-GRU-1.ckpt')


def get_spatial_features(vid_path):
    _frames = []
    cap = cv.VideoCapture(vid_path)
    success, _frame = cap.read()
    # count = 0
    success = True
    while success:
        _frame = cv.resize(_frame, (299, 299))
        _frames.append(_frame)
예제 #7
0
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from scipy.misc import imresize, imread
import cv2

from utils import read_video2array
from gait_nn import GaitNetwork
from human_pose_nn import HumanPoseIRNetwork

mpl.use('Agg')

#
net_pose = HumanPoseIRNetwork()
net_gait = GaitNetwork(recurrent_unit='GRU', rnn_layers=2)
net_pose.restore('models/MPII+LSP.ckpt')
net_gait.restore('models/H3.6m-GRU-1.ckpt')

# read image data
# img = imread('images/dummy.jpg')
# img = imresize(img, [299, 299])
# img_batch = np.expand_dims(img, 0)

# read feames in shape (TIME, HEIGHT, WIDTH, CHANNELS)
frames_arr = read_video2array('data/test/062-nm-04-126.avi', 1)

# Create features from input frames in shape (TIME, HEIGHT, WIDTH, CHANNELS)
spatial_features = net_pose.feed_forward_features(frames_arr)

# Process spatial features and generate identification vector
identification_vector = net_gait.feed_forward(spatial_features)
예제 #8
0
파일: main.py 프로젝트: coffee19850519/gait
import numpy as np
import matplotlib as mpl

mpl.use('Agg')
import matplotlib.pyplot as plt
from scipy.misc import imresize, imread

from human_pose_nn import HumanPoseIRNetwork

# 恢复模型方法
net_pose = HumanPoseIRNetwork()
net_pose.restore('./models_pose/MPII+LSP.ckpt')

for j in range(1, 2):
    img = imread('./image/wy/rx.jpg')
    img = imresize(img, [299, 299])
    img_batch = np.expand_dims(img, 0)

    y, x, a = net_pose.estimate_joints(img_batch)
    # print("拿到的三个张量,在输出")
    # print(x)
    # print(y)
    # print(a)
    y, x, a = np.squeeze(y), np.squeeze(x), np.squeeze(a)

    joint_names = [
        'right ankle ', 'right knee ', 'right hip', 'left hip', 'left knee',
        'left ankle', 'pelvis', 'thorax', 'upper neck', 'head top',
        'right wrist', 'right elbow', 'right shoulder', 'left shoulder',
        'left elbow', 'left wrist'
    ]
예제 #9
0
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from scipy.misc import imresize, imread

from human_pose_nn import HumanPoseIRNetwork
mpl.use('Agg')

net_pose = HumanPoseIRNetwork()
net_pose.restore('../Thesis_solution/models/MPII+LSP.ckpt')

img = imread('Abc.jpeg')
img = imresize(img, [299, 299])
img_batch = np.expand_dims(img, 0)

y, x, a = net_pose.estimate_joints(img_batch)
y, x, a = np.squeeze(y), np.squeeze(x), np.squeeze(a)

joint_names = [
    'right ankle ', 'right knee ', 'right hip', 'left hip', 'left knee',
    'left ankle', 'pelvis', 'thorax', 'upper neck', 'head top', 'right wrist',
    'right elbow', 'right shoulder', 'left shoulder', 'left elbow',
    'left wrist'
]

# Print probabilities of each estimation
for i in range(16):
    print('%s: %.02f%%' % (joint_names[i], a[i] * 100))

colors = [
    'r', 'r', 'b', 'm', 'm', 'y', 'g', 'g', 'b', 'c', 'r', 'r', 'b', 'm', 'm',