Example usage for java.nio ShortBuffer get

List of usage examples for java.nio ShortBuffer get

Introduction

In this page you can find the example usage for java.nio ShortBuffer get.

Prototype

public abstract short get();

Source Link

Document

Returns the short at the current position and increases the position by 1.

Usage

From source file:TrackerPanel.java

private void hideBackground(int[] cameraPixels) {
    depthMD = depthGen.getMetaData();//from   w  w w  .j ava 2s . c om

    ShortBuffer usersBuf = sceneMD.getData().createShortBuffer();
    int userCount = 0;
    int maxUserCount = 0;
    int userCountMaxRow = 0;
    int maxY = 0;
    int row = 0;
    int rowCount = 0;

    while (usersBuf.remaining() > 0) {
        int pos = usersBuf.position();
        short userID = usersBuf.get();
        if (userID == 0) {
            // if not a user (i.e. is part of the background)
            cameraPixels[pos] = hideBGPixel; // make pixel transparent
        } else {
            userCount++;
            int y = imHeight - row;
            if (y > maxY) {
                maxY = y;
            }
        }
        rowCount++;
        if (rowCount == imWidth) {
            if (userCount > maxUserCount) {
                maxUserCount = userCount;
                userCountMaxRow = row;
            }
            row++;
            rowCount = 0;
            userCount = 0;
        }
    }
    int startPoint = imWidth * (imHeight - maxY);
    int finalPoint = startPoint + imWidth;
    if (maxY != 0) {
        printLine(startPoint, finalPoint, Color.YELLOW.getRGB());
    }
    startPoint = imWidth * (userCountMaxRow);
    finalPoint = startPoint + imWidth;
    if (userCountMaxRow != 0) {
        SimpleHTTPPOSTRequester httpPost = new SimpleHTTPPOSTRequester();
        try {
            httpPost.makeHTTPPOSTRequest(userCountMaxRow);
        } catch (ParseException e1) {
            e1.printStackTrace();
        }
        Util.insertLastPoint(userCountMaxRow);
        int response = Util.analyzeLastFivePoints();

        if (response == Util.NOT_READY) {
            printLine(startPoint, finalPoint, Color.RED.getRGB());
        } else if (response == Util.READY) {
            printLine(startPoint, finalPoint, Color.WHITE.getRGB());
        } else if (response == Util.GOING_UP) {
            printLine(startPoint, finalPoint, Color.GREEN.getRGB());
        } else if (response == Util.GOING_DOWN) {
            printLine(startPoint, finalPoint, Color.PINK.getRGB());
        }

    }
}