final int kMinDimension = 147; final int kDimensionLower = 640; int width = frame.getMetadata().getWidth(); int height = frame.getMetadata().getHeight();
/** * Creates a new frame based on the original frame, with additional width on the right to * increase the size to avoid the bug in the underlying face detector. */ private Frame padFrameRight(Frame originalFrame, int newWidth) { Frame.Metadata metadata = originalFrame.getMetadata(); int width = metadata.getWidth(); int height = metadata.getHeight(); Log.i(TAG, "Padded image from: " + width + "x" + height + " to " + newWidth + "x" + height); ByteBuffer origBuffer = originalFrame.getGrayscaleImageData(); int origOffset = origBuffer.arrayOffset(); byte[] origBytes = origBuffer.array(); // This can be changed to just .allocate in the future, when Frame supports non-direct // byte buffers. ByteBuffer paddedBuffer = ByteBuffer.allocateDirect(newWidth * height); int paddedOffset = paddedBuffer.arrayOffset(); byte[] paddedBytes = paddedBuffer.array(); Arrays.fill(paddedBytes, (byte) 0); for (int y = 0; y < height; ++y) { int origStride = origOffset + y * width; int paddedStride = paddedOffset + y * newWidth; System.arraycopy(origBytes, origStride, paddedBytes, paddedStride, width); } return new Frame.Builder() .setImageData(paddedBuffer, newWidth, height, ImageFormat.NV21) .setId(metadata.getId()) .setRotation(metadata.getRotation()) .setTimestampMillis(metadata.getTimestampMillis()) .build(); }
Frame.Metadata metadata = originalFrame.getMetadata(); int width = metadata.getWidth(); int height = metadata.getHeight(); ByteBuffer origBuffer = originalFrame.getGrayscaleImageData(); int origOffset = origBuffer.arrayOffset(); byte[] origBytes = origBuffer.array();