Skip to content

Inconsistencies in the return values (android) #43

@c-goettert

Description

@c-goettert

To verify / understand the content of the frames, I created a simple demo app that stores the content returned from the resize plugin and just draws it right below the original image (via react-native-skia).

The resize call within my frame processor looks like follows:

const data = resize(frame, {
  scale: {
    width: 320,
    height: 320
  },
  pixelFormat: 'rgb',
  dataType: 'uint8'
})
  
// Note: As I somehow failed to use the arraybuffer-values directly within my component.
// I found that storing the values in a separate array worked for me. So I reshape the frame data like this
// before I use it to draw my skia image:

const arrayData = new Array(width * height * 4).fill(255)
for (let i = 0, j = 0; i < data.length; i += 3,  j += 4) {
  arrayData[j] = data[i] // R
  arrayData[j+1] = data[i + 1] // G
  arrayData[j+2] = data[i + 2] // B
  arrayData[j+3] = 255 // A
}

My camera settings look like this:

  const format = useCameraFormat(device, [
    { videoResolution: { width: 640, height: 480 } },
    { fps: 30 },
    { videoStabilizationMode: 'auto' }
  ])

I can could verify my approach is generally working on iOS, where my test-frame is rendered correctly:

iPhone X:
ios

However, on my Android phone (Pixel 7A, Android 14), the frame seems to be rotated by -90°. Also, as you can see in the image below, the format is returned in bgr instead rgb..

Pixel 7A:
android1

Furthermore, I don't actually want to use the default centre-crop, but the upper square of the image. I have therefore adapted the resize call as follows:

const data = resize(frame, {
  scale: {
    width,
    height
  },
  crop: {
    y: 0,
    x: 0,
    width: frame.width,
    height: frame.width
  },
  pixelFormat: 'rgb',
  dataType: 'uint8'
})

This setting strangely cuts the result into 3 image-areas:
android2

To summarize the issues:

  • Everything runs as expected on iOS
  • On Android (Pixel 7A, Android 14) there are the following problems
    • The image is rotated
    • The image is bgr despite rgb was requested
    • The crop mechanism seems to have a glitch (possibly related to the rotation?)

I use the following configuration:

  • react-native: 0.73.4
  • react-native-vision-camera: 3.9.1
  • react-native-worklets-core: 0.3.0
  • vision-camera-resize-plugin: 2.0.1

If it helps to trace the issue I can gladly add my complete test component.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions