Getting frames
Use the following override function to detect each new frame:
override fun setOnPreviewFrameListener(cameraInput: ByteArray) {
}Each new frame is presented as a new ByteArray. Because the headset automatically encodes video input, the output is a ByteArray containing data from both cameras in the default resolution of 1280*480p (combination of two frames with the resolution of 640*480p).
The ByteArray contains data in the NV21 image format. In order to convert the ByteArray into a bitmap you can use the following function where previewWidth and previewHeight depend on the chosen resolution implying that you must keep track of your current resolution:
//CameraResolution.SD
val previewWidth = 1280
val previewHeight = 480
//CameraResolution.MD
// val previewWidth = 2560
// val previewHeight = 720
//CameraResolution.HD
// val previewWidth = 3840
// val previewHeight = 1080
fun byteArrayToBitmap(byteArray: ByteArray?): Bitmap? {
val yuvImage = YuvImage(byteArray, ImageFormat.NV21, previewWidth, previewHeight, null)
val os = ByteArrayOutputStream()
yuvImage.compressToJpeg(Rect(0, 0, previewWidth, previewHeight), 100, os)
val jpegByteArray = os.toByteArray()
return BitmapFactory.decodeByteArray(jpegByteArray, 0, jpegByteArray.size)
}For simplified use and flexibility, the API enables you to work directly with the raw data contained in the ByteArray but also enables you to choose the camera input and resolution of the ARxWear Headset.