Java Code Examples for com.google.android.gms.vision.Frame#Metadata

The following examples show how to use com.google.android.gms.vision.Frame#Metadata . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SafeFaceDetector.java    From face-detection-ane with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 2
Source File: SafeFaceDetector.java    From face-detection-ane with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new frame based on the original frame, with additional height on the bottom to
 * increase the size to avoid the bug in the underlying face detector.
 */
private Frame padFrameBottom( Frame originalFrame, int newHeight ) {
	Frame.Metadata metadata = originalFrame.getMetadata();
	int width = metadata.getWidth();
	int height = metadata.getHeight();

	Log.i( TAG, "Padded image from: " + width + "x" + height + " to " + width + "x" + newHeight );

	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( width * newHeight );
	int paddedOffset = paddedBuffer.arrayOffset();
	byte[] paddedBytes = paddedBuffer.array();
	Arrays.fill( paddedBytes, (byte) 0 );

	// Copy the image content from the original, without bothering to fill in the padded bottom
	// part.
	for( int y = 0; y < height; ++y ) {
		int origStride = origOffset + y * width;
		int paddedStride = paddedOffset + y * width;
		System.arraycopy( origBytes, origStride, paddedBytes, paddedStride, width );
	}

	return new Frame.Builder()
			.setImageData( paddedBuffer, width, newHeight, ImageFormat.NV21 )
			.setId( metadata.getId() )
			.setRotation( metadata.getRotation() )
			.setTimestampMillis( metadata.getTimestampMillis() )
			.build();
}
 
Example 3
Source File: SafeFaceDetector.java    From android-vision with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example 4
Source File: SafeFaceDetector.java    From android-vision with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new frame based on the original frame, with additional height on the bottom to
 * increase the size to avoid the bug in the underlying face detector.
 */
private Frame padFrameBottom(Frame originalFrame, int newHeight) {
    Frame.Metadata metadata = originalFrame.getMetadata();
    int width = metadata.getWidth();
    int height = metadata.getHeight();

    Log.i(TAG, "Padded image from: " + width + "x" + height + " to " + width + "x" + newHeight);

    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(width * newHeight);
    int paddedOffset = paddedBuffer.arrayOffset();
    byte[] paddedBytes = paddedBuffer.array();
    Arrays.fill(paddedBytes, (byte) 0);

    // Copy the image content from the original, without bothering to fill in the padded bottom
    // part.
    for (int y = 0; y < height; ++y) {
        int origStride = origOffset + y * width;
        int paddedStride = paddedOffset + y * width;
        System.arraycopy(origBytes, origStride, paddedBytes, paddedStride, width);
    }

    return new Frame.Builder()
            .setImageData(paddedBuffer, width, newHeight, ImageFormat.NV21)
            .setId(metadata.getId())
            .setRotation(metadata.getRotation())
            .setTimestampMillis(metadata.getTimestampMillis())
            .build();
}