react-native-vision-camera icon indicating copy to clipboard operation
react-native-vision-camera copied to clipboard

❓ Should useCameraDevices always return the "default" device? Front camera in black and white

Open jladuval opened this issue 3 years ago • 4 comments

Question

I'm not sure if this is a bug. I'm using a Pixel 4 and the default front camera appears to be the infrared camera (it's grainy and in black and white). When using the back camera I seem to get the "default" camera. I say default because it's the same one other apps seem to use or other libraries return.

Should useCameraDevices return the "default" front and back cameras? It seems like that' would make the most sense otherwise you'd have to be filtering cameras for each device. I've looked through the other issues and I can't see anyone else hitting this. Is this something I'm doing wrong?

What I tried

const Foo = () => {
   const devices = useCameraDevices()
   const device = devices.front
   return (
       <Camera
          ref={(ref) => (cameraRef.current = ref)}
          device={device}
          isActive={true}
        />
    )
}

VisionCamera Version

2.12.2

Additional information

jladuval avatar Mar 14 '22 12:03 jladuval

Lol that's definitely a bug. You could try filtering devices yourself, it's pretty straight forward:


useEffect(() => {
  const devices = await Camera.getAvailableDevices()
  // ...
}, []

mrousavy avatar Mar 14 '22 16:03 mrousavy

Ha ok good to know. It's a relatively niche feature for my app so I think Pixel 4 users will just have to deal with their new black and white selfie feature :smile:

jladuval avatar Mar 15 '22 09:03 jladuval

Also facing this issue, front camera only records in black / white, back camera fine

dylan-westbury avatar May 18 '22 21:05 dylan-westbury

It appears the "wide-angle-camera" is black and white for the front camera on pixels.

We resolved by filtering for the "ultra-wide-angle-camera"

const availableDevices = await Camera.getAvailableCameraDevices();
const frontDevices = availableDevices.filter((dev) => dev.position === "front");

 const wideAngleCamera = frontDevices.filter((dev) =>
    dev.devices.includes("ultra-wide-angle-camera")
  );

dylan-westbury avatar May 26 '22 04:05 dylan-westbury

Black and white photos for us on huawei P20 and huawei P20 Pro. Seems to be with back wide-angle camera

MorvanL avatar Nov 15 '22 14:11 MorvanL

We met the exact issue in Google Pixel 4, it seems the issue might partially be caused by Camera.getAvailableCameraDevices()'s result is not consistent.

As the following screenshot:

  1. in react-native-vision-camera/src/hooks/useCameraDevices.ts the Camera.getAvailableCameraDevices() sorts 'wide-angle-camera' first, so useCameraDevices() would use this one as front camera.
  2. while in our app, the Camera.getAvailableCameraDevices() sorts 'ultra-wide-angle-camera' first

image

image

terryatgithub avatar Jan 20 '23 04:01 terryatgithub

sorts first

No one said that Camera.getAvailableDevices does do any sorting. You are responsible for sorting that list.

mrousavy avatar Jan 20 '23 21:01 mrousavy

This should be now fixed with the all new Devices API in V3! 🥳

mrousavy avatar Sep 30 '23 09:09 mrousavy