PoseDetection.java 1.78 KB
Newer Older
limm's avatar
limm committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import mmdeploy.PoseDetector;
import mmdeploy.PixelFormat;
import mmdeploy.DataType;
import mmdeploy.Mat;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.io.File;
import java.io.IOException;

/** @description: this is a class for PoseDetection java demo. */
public class PoseDetection {

    /** The main function for PoseDetection Java demo.
     * @param deviceName: the device name of the demo.
     * @param modelPath: the pose detection model path.
     * @param imagePath: the image path.
     */
    public static void main(String[] args) {
        // Parse arguments
        if (args.length != 3) {
            System.out.println("usage:\njava PoseDetection deviceName modelPath imagePath");
            return;
        }
        String deviceName = args[0];
        String modelPath = args[1];
        String imagePath = args[2];

        // create pose estimator
        PoseDetector poseEstimator = null;

        try {
            poseEstimator = new PoseDetector(modelPath, deviceName, 0);

            // load image
            Mat img = Utils.loadImage(imagePath);

            // apply pose estimator
            PoseDetector.Result[] result = poseEstimator.apply(img);

            // print results
            for (PoseDetector.Result value : result) {
                for (int i = 0; i < value.point.length; i++) {
                    System.out.printf("point %d, x: %d, y: %d\n", i, (int)value.point[i].x, (int)value.point[i].y);
                }
            }
        } catch (Exception e) {
            System.out.println("exception: " + e.getMessage());
        } finally {
            // release pose estimator
            if (poseEstimator != null) {
                poseEstimator.release();
            }
        }
    }
}