Search in sources :

Example 1 with WrapperStructFace

use of org.bytedeco.openpose.WrapperStructFace in project javacpp-presets by bytedeco.

the class openpose method main.

public static void main(String[] args) {
    // Parse command arguments
    boolean doHands = false;
    boolean doFace = false;
    String[] pargs = new String[2];
    int pargsIdx = 0;
    for (String arg : args) {
        if (arg.startsWith("-")) {
            if (arg.equals("--hands")) {
                doHands = true;
            }
            if (arg.equals("--face")) {
                doFace = true;
            } else {
                System.err.println("Usage: <openpose sample> [--hands] [--face] IMAGE_IN IMAGE_OUT");
                System.exit(-1);
            }
        } else {
            pargs[pargsIdx] = arg;
            pargsIdx += 1;
        }
    }
    // Configure OpenPose
    OpWrapper opWrapper = new OpWrapper(ThreadManagerMode.Asynchronous);
    opWrapper.disableMultiThreading();
    opWrapper.configure(mkWrapperStructPose());
    if (doFace) {
        WrapperStructFace face = new WrapperStructFace();
        face.enable(true);
        opWrapper.configure(face);
    }
    if (doHands) {
        WrapperStructHand hand = new WrapperStructHand();
        hand.enable(true);
        opWrapper.configure(hand);
    }
    // Start OpenPose
    opWrapper.start();
    Mat ocvIm = imread(pargs[0]);
    Matrix opIm = OP_CV2OPCONSTMAT(ocvIm);
    Datum dat = new Datum();
    dat.cvInputData(opIm);
    Datums dats = new Datums();
    dats.put(dat);
    opWrapper.emplaceAndPop(dats);
    dat = dats.get(0);
    // Print keypoints
    FloatArray poseArray = dat.poseKeypoints();
    IntPointer dimSizes = poseArray.getSize();
    int numPeople = dimSizes.get(0);
    int numJoints = dimSizes.get(1);
    for (int i = 0; i < numPeople; i++) {
        System.out.printf("Person %d\n", i);
        for (int j = 0; j < numJoints; j++) {
            System.out.printf("Limb %d\tx: %f\ty: %f\t: %f\n", j, poseArray.get(new int[] { i, j, 0 })[0], poseArray.get(new int[] { i, j, 1 })[0], poseArray.get(new int[] { i, j, 2 })[0]);
        }
    }
    // Save output
    Mat ocvMatOut = OP_OP2CVCONSTMAT(dat.cvOutputData());
    imwrite(pargs[1], ocvMatOut);
}
Also used : OpWrapper(org.bytedeco.openpose.OpWrapper) Mat(org.bytedeco.opencv.opencv_core.Mat) WrapperStructFace(org.bytedeco.openpose.WrapperStructFace) OpString(org.bytedeco.openpose.OpString) Matrix(org.bytedeco.openpose.Matrix) WrapperStructHand(org.bytedeco.openpose.WrapperStructHand)

Aggregations

Mat (org.bytedeco.opencv.opencv_core.Mat)1 Matrix (org.bytedeco.openpose.Matrix)1 OpString (org.bytedeco.openpose.OpString)1 OpWrapper (org.bytedeco.openpose.OpWrapper)1 WrapperStructFace (org.bytedeco.openpose.WrapperStructFace)1 WrapperStructHand (org.bytedeco.openpose.WrapperStructHand)1