Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 MinZoom Problem in some devices (0,5) #3345

Open
4 of 5 tasks
dorakadri opened this issue Dec 31, 2024 · 9 comments
Open
4 of 5 tasks

🐛 MinZoom Problem in some devices (0,5) #3345

dorakadri opened this issue Dec 31, 2024 · 9 comments
Labels
🐛 bug Something isn't working

Comments

@dorakadri
Copy link

What's happening?

in some devices the min zoom is always 1 even tho its supposed to be 0,5 and that the physical device shows as ultra wide range

Reproduceable Code

const devices = Camera.getAvailableCameraDevices()

  const device = getCameraDevice(devices, 'back', {
    physicalDevices: ['ultra-wide-angle-camera', 'wide-angle-camera', 'telephoto-camera']
  })
  const zoom = useSharedValue(device?.neutralZoom)
  const format = useCameraFormat(device, Templates.Snapchat)
  const zoomOffset = useSharedValue(0)
  const [zoomState, setZoomState] = useState(device?.neutralZoom || 1)


  console.log()
  useDerivedValue(() => {
    if (!zoom.value) return
    runOnJS(setZoomState)(zoom.value)
    return zoom.value
  }, [zoom.value])
  const gesture = Gesture.Pinch()
    .onBegin(() => {
      if (zoom.value) {
        zoomOffset.value = zoom.value
      }
    })
    .onUpdate(event => {
      const z = zoomOffset.value * event.scale
      if (device) {
        zoom.value = interpolate(z, [1, 10], [device.minZoom, device.maxZoom], Extrapolation.CLAMP)
      }
    })



<ReanimatedCamera
          ref={cameraRef}
          outputOrientation='preview'
          style={isInitialized ? StyleSheet.absoluteFill : styles.noSize}
          onTouchEnd={focus}
          onShutter={playShutterSound}
          device={device}
          isActive={isActive}
          format={format}
          animatedProps={animatedProps}
          photo
          onError={console.warn}
          onLayout={event => {
            const { layout } = event.nativeEvent
            setCameraLayout(layout)
          }}
          onInitialized={() => {
            setTimeout(() => {
              if (
                device.physicalDevices.includes('ultra-wide-angle-camera') ||
                  device.physicalDevices.includes('wide-angle-camera') ||
                  device.physicalDevices.includes('telephoto-camera')
              ) {
                setWideRangeAvailable(true)
              }
              setIsInitialized(true)
            }, 10)
          }}

Relevant log output

no relevant log only the json ill show before

Camera Device

{
  "id": "2",
  "devices": [
    "ultra-wide-angle-camera"
  ],
  "formats": [{...},{...},{...},{...},{...},{...},{...},{...},{...},{...},{...},{...},{...},{...},{...},],
  "hardwareLevel": "limited",
  "hasFlash": false,
  "hasTorch": false,
  "isMultiCam": false,
  "minZoom": 1,
  "neutralZoom": 1,
  "maxZoom": 8,
  "name": " 2 (BACK) androidx.camera.camera2",
  "position": "back",
  "supportsFocus": true,
  "supportsLowLightBoost": false,
  "supportsRawCapture": false
}

Device

Samsung Galaxy a73 5g

VisionCamera Version

4.5.1 / 4.6.1

Can you reproduce this issue in the VisionCamera Example app?

Yes, I can reproduce the same issue in the Example app here

Additional information

@dorakadri dorakadri added the 🐛 bug Something isn't working label Dec 31, 2024
Copy link

Guten Tag, Hans here! 🍻

Thank you for providing detailed information about ze issue with ze min zoom setting. It seems like you might be facing a valid bug, but we need more information to help mrousavy troubleshoot ze problem effectively.

Could you please provide some relevant logs from ze device? For Android, you can gather logs using adb logcat while replicating ze issue. This will help us understand what is happening internally.

Also, if you find ze project helpful, consider sponsoring mrousavy here to help keep ze development going!

Looking forward to your response!

Note: If you think I made a mistake, please ping @mrousavy to take a look.

@wadiasalem
Copy link

I have the same issue

@prakashpro3
Copy link

prakashpro3 commented Jan 16, 2025

I have same issue. My device(Android) supports 0.6x zoom but this shows "minZoom": 1 in devices.

[
  {
    "sensorOrientation": "landscape-left",
    "hardwareLevel": "full",
    "maxZoom": 10,
    "minZoom": 1,
    "maxExposure": 18,
    "supportsLowLightBoost": false,
    "neutralZoom": 1,
    "physicalDevices": [
      "wide-angle-camera"
    ],
    "supportsFocus": true,
    "supportsRawCapture": false,
    "isMultiCam": false,
    "minFocusDistance": 0,
    "minExposure": -18,
    "name": "0 (BACK) androidx.camera.camera2",
    "hasFlash": true,
    "hasTorch": true,
    "position": "back",
    "id": "0"
  },
  {
    "sensorOrientation": "landscape-right",
    "hardwareLevel": "full",
    "maxZoom": 4,
    "minZoom": 1,
    "maxExposure": 12,
    "supportsLowLightBoost": false,
    "neutralZoom": 1,
    "physicalDevices": [
      "wide-angle-camera"
    ],
    "supportsFocus": true,
    "supportsRawCapture": false,
    "isMultiCam": false,
    "minFocusDistance": 0,
    "minExposure": -12,
    "name": "1 (FRONT) androidx.camera.camera2",
    "hasFlash": false,
    "hasTorch": false,
    "position": "front",
    "id": "1"
  }
]

@dorakadri
Copy link
Author

@prakashpro3 well i've talked with the support of android and it seems like the problem is in some devices but they left a snippet of code that maybe can help but it need to be done inside the package maybe @mrousavy is interested ill leave the link here maybe it will give you some clarity https://groups.google.com/a/android.com/g/camerax-developers/c/N4YtXK-6-CU

@ugar0ff
Copy link

ugar0ff commented Jan 19, 2025

I encountered the same issue. I have an ultra-wide-angle camera with 0.5x, minZoom = 1, naturalZoom = 1, and maxZoom = 8. When I compare the result with the native camera app, I see that when my zoom is set to 1, the result is the same as in the native camera app with zoom set to 0.5. From what I’ve read in the documentation, I expected to see naturalZoom = 2.
Could you tell me if I should "recalculate" the interval [1, 8] to [0.5, 8]?

@mrousavy
Copy link
Owner

hey - hm this actually seems like a CameraX inconsistency. Thanks for creating the bug report in the CameraX issue tarcker @dorakadri ! :)

@mrousavy
Copy link
Owner

I think the snippet Scott shared in the CameraX issue tracker does not apply here. VisionCamera already grabs all Cameras, so you can select the one you want. This is not the same issue if I read this correctly

@mrousavy
Copy link
Owner

From what I’ve read in the documentation, I expected to see naturalZoom = 2.

@ugar0ff min/neutral/max zoom are factors. Max zoom of 8 means you can zoom in 8x of the default view.

@ugar0ff
Copy link

ugar0ff commented Jan 20, 2025

I continue testing,
✅ on iOS everything worked as expected according to the documentation. Here is the camera I selected:
"maxZoom": 123.75, "minZoom": 1, "neutralZoom": 2, "physicalDevices": ['ultra-wide-angle-camera', 'wide-angle-camera', 'telephoto-camera'], "position": "back"

As a result, on the UI, I display the zoom range from 0.5 to 15, but I send twice the value to the library (from 1 to 30). The neutralZoom: 2 is displayed on the UI as 1.

However,
❌ on Android, there are several issues. I tested on three different Android devices (1 Xiaomi and 2 Samsung), and I can say the issues are common:

  1. The physicalDevices array always contains only one value.
  2. The neutralZoom is always 1, even for the ultra-wide-angle camera, even though in this case, a zoom of 1 is ultra-wide and gives the same result as the native camera at 0.5.
  3. The maxZoom is smaller than what the native camera can achieve.

Example of all "back" cameras from my Samsung:

"id": "0", "physicalDevices": ["wide-angle-camera"], "position": "back", "minZoom": 1, "neutralZoom": 1, "maxZoom": 8
"id": "2", "physicalDevices": ["ultra-wide-angle-camera"], "position": "back", "minZoom": 1, "neutralZoom": 1, "maxZoom": 8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants