def use_filter(x):
    structure = skeletalModel.getSkeletalModelStructure()

    inputSequence_2D = x

    # Decomposition of the single matrix into three matrices: x, y, w (=likelihood)
    X = inputSequence_2D
    Xx = X[0:X.shape[0], 0:(X.shape[1]):3]
    Xy = X[0:X.shape[0], 1:(X.shape[1]):3]
    Xw = X[0:X.shape[0], 2:(X.shape[1]):3]

    # Normalization of the picture (x and y axis has the same scale)
    Xx, Xy = pose2D.normalization(Xx, Xy)

    # Delete all skeletal models which have a lot of missing parts.
    Xx, Xy, Xw = pose2D.prune(Xx, Xy, Xw, (0, 1, 2, 3, 4, 5, 6, 7), 0.3, dtype)

    # Preliminary filtering: weighted linear interpolation of missing points.
    Xx, Xy, Xw = pose2D.interpolation(Xx, Xy, Xw, 0.99, dtype)

    # Initial 3D pose estimation
    lines0, rootsx0, rootsy0, rootsz0, anglesx0, anglesy0, anglesz0, Yx0, Yy0, Yz0 = pose2Dto3D.initialization(
        Xx,
        Xy,
        Xw,
        structure,
        0.001,  # weight for adding noise
        randomNubersGenerator,
        dtype,
        percentil=0.5,
    )

    # Backpropagation-based filtering
    Yx, Yy, Yz = pose3D.backpropagationBasedFiltering(
        lines0,
        rootsx0,
        rootsy0,
        rootsz0,
        anglesx0,
        anglesy0,
        anglesz0,
        Xx,
        Xy,
        Xw,
        structure,
        dtype,
        nCycles=100,
    )

    return convList2Array([Yx, Yy, Yz])
예제 #2
0
    f = h5py.File("data/demo-sequence.h5", "r")
    inputSequence_2D = numpy.array(f.get("20161025_pocasi"))
    f.close()

    # Decomposition of the single matrix into three matrices: x, y, w (=likelihood)
    X = inputSequence_2D
    Xx = X[0:X.shape[0], 0:(X.shape[1]):3]
    Xy = X[0:X.shape[0], 1:(X.shape[1]):3]
    Xw = X[0:X.shape[0], 2:(X.shape[1]):3]

    # Normalization of the picture (x and y axis has the same scale)
    Xx, Xy = pose2D.normalization(Xx, Xy)
    save("data/demo1.txt", [Xx, Xy, Xw])

    # Delete all skeletal models which have a lot of missing parts.
    Xx, Xy, Xw = pose2D.prune(Xx, Xy, Xw, (0, 1, 2, 3, 4, 5, 6, 7), 0.3, dtype)
    save("data/demo2.txt", [Xx, Xy, Xw])

    # Preliminary filtering: weighted linear interpolation of missing points.
    Xx, Xy, Xw = pose2D.interpolation(Xx, Xy, Xw, 0.99, dtype)
    save("data/demo3.txt", [Xx, Xy, Xw])

    # Initial 3D pose estimation
    lines0, rootsx0, rootsy0, rootsz0, anglesx0, anglesy0, anglesz0, Yx0, Yy0, Yz0 = pose2Dto3D.initialization(
        Xx,
        Xy,
        Xw,
        structure,
        0.001,  # weight for adding noise
        randomNubersGenerator,
        dtype)
예제 #3
0
def main(argv):
    dtype = "float32"
    randomNubersGenerator = numpy.random.RandomState(1234)

    # This demo shows converting a result of 2D pose estimation into a 3D pose.

    # Getting our structure of skeletal model.
    # For customizing the structure see a definition of getSkeletalModelStructure.
    structure = skeletalModel.getSkeletalModelStructure()

    # Getting 2D data
    # The sequence is an N-tuple of
    #   (1sf point - x, 1st point - y, 1st point - likelihood, 2nd point - x, ...)
    # a missing point should have x=0, y=0, likelihood=0
    f = h5py.File("./pipelineDemo/keypoints.h5", "r")
    # todo change the location or folder name later
    inputSequence_2D = numpy.array(f.get(argv[1]))
    #inputSequence_2D = numpy.array(f.get("sample_2d_openpose"))
    f.close()
    # Decomposition of the single matrix into three matrices: x, y, w (=likelihood)
    X = inputSequence_2D
    Xx = X[0:X.shape[0], 0:150:3]
    Xy = X[0:X.shape[0], 1:150:3]
    Xw = X[0:X.shape[0], 2:150:3]

    Face_Xx = X[0:X.shape[0], 150::3]
    Face_Xy = X[0:X.shape[0], 150::3]
    Face_Xw = X[0:X.shape[0], 150::3]

    # Normalization of the picture (x and y axis has the same scale)
    Xx, Xy = pose2D.normalization(Xx, Xy)
    Face_Xx, Face_Xy = pose2D.normalization(Face_Xx, Face_Xy)
    save("Temp_Data/" + argv[1] + "_demo1.txt", [Xx, Xy, Xw])

    # Delete all skeletal models which have a lot of missing parts.
    Xx, Xy, Xw = pose2D.prune(Xx, Xy, Xw, (0, 1, 2, 3, 4, 5, 6, 7), 0.3, dtype)
    save("Temp_Data/" + argv[1] + "_demo2.txt", [Xx, Xy, Xw])

    # Preliminary filtering: weighted linear interpolation of missing points.
    Xx, Xy, Xw = pose2D.interpolation(Xx, Xy, Xw, 0.99, dtype)
    save("Temp_Data/" + argv[1] + "_demo3.txt", [Xx, Xy, Xw])

    # Initial 3D pose estimation
    lines0, rootsx0, rootsy0, rootsz0, anglesx0, anglesy0, anglesz0, Yx0, Yy0, Yz0 = pose2Dto3D.initialization(
        Xx,
        Xy,
        Xw,
        structure,
        0.001,  # weight for adding noise
        randomNubersGenerator,
        dtype)
    save("Temp_Data/" + argv[1] + "_demo4.txt", [Yx0, Yy0, Yz0])

    # Backpropagation-based filtering
    Yx, Yy, Yz = pose3D.backpropagationBasedFiltering(
        lines0,
        rootsx0,
        rootsy0,
        rootsz0,
        anglesx0,
        anglesy0,
        anglesz0,
        Xx,
        Xy,
        Xw,
        structure,
        dtype,
    )
    data = numpy.asarray(noNones([
        numpy.hstack((Yx, Face_Xx)),
        numpy.hstack((Yy, Face_Xy)),
        numpy.hstack((Yz, Face_Xw))
    ]),
                         dtype="float32")
    save("Training_Data_3D/" + argv[1] + ".txt", data)
    hf = h5py.File("Training_Data_3D_h5/" + argv[1] + ".h5", "w")
    hf.create_dataset(argv[1], data=data, dtype="float32")

    hf.close()