Class AnylineYuvImage
-
- All Implemented Interfaces:
-
java.lang.Cloneable
public class AnylineYuvImage implements Cloneable
A helper class to deal with yuv images. (currently only NV21!!) It helps with conversion to OpenCV Mat and deals with the problem that the camera always returns a landscape image.
-
-
Field Summary
Fields Modifier and Type Field Description public final inttargetWidthpublic final inttargetHeightpublic final intoriginalWidthpublic final intoriginalHeightpublic final Array<byte>datapublic final booleanisGreyOnlypublic final inttargetOrientationpublic intformat
-
Constructor Summary
Constructors Constructor Description AnylineYuvImage(int format, int width, int height, int targetOrientation)Construct a yuv image with empty data. AnylineYuvImage(int format, int width, int height, Array<byte> data, int targetOrientation, boolean isGreyOnly)Construct a yuv image with the given byte data. AnylineYuvImage(Image image, int targetOrientation, int cropX, int cropY, int cropWidth, int cropHeight, boolean isGreyOnly)Construct a YUV image from the given image buffer cropped to the given bounds.
-
Method Summary
Modifier and Type Method Description intgetTargetWidth()intgetTargetHeight()intgetOriginalWidth()intgetOriginalHeight()Array<byte>getData()The image data in the format returned by getFormat. booleanisGreyOnly()intgetTargetOrientation()Get the target orientation of the image. intgetFormat()Get the format the image is stored in the byte data (see getData). voidsetTo(@NonNull() Array<byte> data)Set the data of this image to the given value. AnylineYuvImagecrop(int cropX, int cropY, int cropWidth, int cropHeight, boolean isGreyOnly)Returns a new image cropped to the given bounds. AnylineYuvImageclone()-
-
Constructor Detail
-
AnylineYuvImage
AnylineYuvImage(int format, int width, int height, int targetOrientation)
Construct a yuv image with empty data.- Parameters:
format- the format (currently only NV21 is supported)width- the target width of the imageheight- the target height of the imagetargetOrientation- the degree the raw data has to be rotated to be oriented as desired (usually what getCameraDisplayRotation returns)
-
AnylineYuvImage
AnylineYuvImage(int format, int width, int height, Array<byte> data, int targetOrientation, boolean isGreyOnly)
Construct a yuv image with the given byte data.- Parameters:
format- the format (currently only NV21 is supported)width- the target width of the imageheight- the target height of the imagedata- the image data in landscape format (like received from the camera)targetOrientation- the degree the raw data has to be rotated to be oriented as desired (usually what getCameraDisplayRotation returns)isGreyOnly- true if given data only contains the Y component (and therefor is grey only)
-
AnylineYuvImage
AnylineYuvImage(Image image, int targetOrientation, int cropX, int cropY, int cropWidth, int cropHeight, boolean isGreyOnly)
Construct a YUV image from the given image buffer cropped to the given bounds.- Parameters:
image- the image to copy the data fromtargetOrientation- the degree the raw data has to be rotated to be oriented as desired (usually what getCameraDisplayRotation returns)cropX- the distance from the left (must be EVEN for color images)cropY- the distance from the top (must be EVEN for color images)cropWidth- the target width (must be EVEN for color images)cropHeight- the target height (must be EVEN for color images)isGreyOnly- true if a grey image is desired (faster), false if color is required too
-
-
Method Detail
-
getTargetWidth
int getTargetWidth()
- Returns:
the width (in the target orientation)
-
getTargetHeight
int getTargetHeight()
- Returns:
the height (in the target orientation)
-
getOriginalWidth
int getOriginalWidth()
- Returns:
original width of the image in the rotation as received from the sensor
-
getOriginalHeight
int getOriginalHeight()
- Returns:
original height of the image in the rotation as received from the sensor
-
getData
Array<byte> getData()
The image data in the format returned by getFormat.
Note: if isGreyOnly is true, the format is always Y8 (regardless of what getFormat returns).
- Returns:
the data in the format returned by getFormat
-
isGreyOnly
boolean isGreyOnly()
- Returns:
true if image is grey only (true also means that the format is Y8)
-
getTargetOrientation
int getTargetOrientation()
Get the target orientation of the image. (The amount the raw data has to be rotated to be oriented as in the preview)
- Returns:
the target orientation
-
getFormat
int getFormat()
Get the format the image is stored in the byte data (see getData). The format is one of the constants in ImageFormat. (Currently only NV21 or YUV_420_888 are possible here, but more formats may be added in the future)
- Returns:
the image format used in the byte data (see getData)
-
setTo
void setTo(@NonNull() Array<byte> data)
Set the data of this image to the given value. (MUST be of same size as the current data)
- Parameters:
data- the data to set this image to.
-
crop
AnylineYuvImage crop(int cropX, int cropY, int cropWidth, int cropHeight, boolean isGreyOnly)
Returns a new image cropped to the given bounds.
The given sizes must be EVEN for color images, because of how the YUV format stores color information.
- Parameters:
cropX- the distance from the left in the target orientation (must be EVEN for color images)cropY- the distance from the top in the target orientation (must be EVEN for color images)cropWidth- the crop width in the target orientation (must be EVEN for color images)cropHeight- the crop height in the target orientation (must be EVEN for color images)isGreyOnly- true if a grey image is desired (faster), false if color is required too- Returns:
a new image cropped to the given bounds.
-
clone
AnylineYuvImage clone()
- Returns:
a deep copy of the image
-
-
-
-