前置摄像头无法自动对焦或手动对焦 [英] Front Facing Camera does not Auto Focus or Manually Focus

查看:1389
本文介绍了前置摄像头无法自动对焦或手动对焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前行为

我在iPad/iPhone上使用 react-native-camera 并且我使用前置摄像头扫描条形码(Code39,Code128,QR等).但是,使用前置摄像头时,它不会聚焦在条形码或我稍微靠近摄像头的任何物体上.后置摄像头绝对完美,但前置摄像头却无法正常工作.

I'm using react-native-camera with iPads/iPhones and I use the front-facing camera to scan barcodes (Code39, Code128, QR, etc..) However when using the front-facing camera, it does not focus on the barcode or anything I put mildly close to the camera. The rear camera works absolutely perfectly however the front camera does not.

我无法测试android,因为我不是纯粹为iOS而为android构建的.我似乎找不到有关使前置摄像头聚焦的任何信息.

I have not been able to test android as I'm not building for android purely just iOS. I can't seem to find any information on getting the front camera to focus.

如果我要站在背景中,将我的Code39靠近相机,但在底部留一个小缝隙,它将不会尝试聚焦在卡片上,而是将注意力集中在背景上.

If I was to stand in the background, hold up my Code39 close to the camera but leave a small gap at the bottom, it would not try focus on the card however stay focused on me in the background.

我还在这里提出了问题在其GitHub页面上,但来到这里是为了查看是否有人之前曾遇到过这种情况,是否有过解决方法等.

I've also raised an issue here on their GitHub page, but came here to see if anyone has ran in to this before, has a work around etc.

预期行为

我希望摄像机看到的代码比我占用的屏幕更多,请专注于它,阅读代码,然后继续运行代码onBarCodeRead

I expect the camera to see the code is taking up a lot more of the screen than I am, focus on it, read the code and proceed to run the code onBarCodeRead

我试图解决什么?

  • 禁用autoFocus,因为这是Android的修复程序,在这里没有运气.
  • 手动设置focusDepth.
  • 手动将autoFocusPointOfInterest设置到屏幕中央.
  • zoom更改为0.2,然后慢慢增加到开始显得愚蠢的程度.
  • onGoogleVisionBarcodesDetected设置为console.log,这是android的另一个修复程序.
  • 更新react-native-camera@2.6.0
  • 更新到react-native-camera@git+https://git@github.com/react-native-community/react-native-camera.git的master分支
  • Disable the autoFocus as this was a fix for Android, no luck here.
  • Manually set the focusDepth.
  • Manually set autoFocusPointOfInterest to center of screen.
  • Change the zoom to 0.2 and slowly increase to the point of where it starts to look silly.
  • Set onGoogleVisionBarcodesDetected to just console.log something as this was another fix for android.
  • Update react-native-camera@2.6.0
  • Update to master branch at react-native-camera@git+https://git@github.com/react-native-community/react-native-camera.git

如何重新创建它?

  • 创建新的本机项目
  • yarn add react-native-camera/npm install react-native-camera --save
  • 设置type={RNCamera.Constants.Type.front}以使用前置摄像头.
  • 设置autoFocus={RNCamera.Constants.AutoFocus.on}(无论如何,默认情况下它是打开的,这只是确保了这一点.
  • 设置onBarCodeRead={() => alert('barcode found')}
  • 尝试扫描Code39/Code128-(在此处创建)
  • 尝试扫描它,您会发现相机不会聚焦在它上,而是聚焦在背景上.如果您用手指遮盖相机,也是如此,当您拉开手指时,您会期望相机对背景不清晰,然后尝试重新对焦.情况并非如此,它将集中在中/远距离.
  • Create new react-native project
  • yarn add react-native-camera / npm install react-native-camera --save
  • set type={RNCamera.Constants.Type.front} to use the front camera.
  • set autoFocus={RNCamera.Constants.AutoFocus.on} (It's on by default anyway, this just ensures it.
  • set onBarCodeRead={() => alert('barcode found')}
  • Try to scan a Code39 / Code128 - (creatable here)
  • Try to scan it and you'll find the camera will not focus on it however stay focused on the background. This is also true if you cover the camera with your finger, when you pull your finger away you expect the camera to be out of focus to the background and try and re-focus. This is not the case, it will stay focused at a medium / long distance.

使用的软件和软件;版本

  • iOS:12.1.4
  • 本机相机:^ 2.1.1/2.6.0
  • 本机:0.57.7
  • 反应:16.6.1

代码

我在 react-native-modal 中渲染照相机,已将我的代码放在下面.

I render the camera in a react-native-modal and I've put my code below.

<RNCamera 
  style={styles.camera}
  type={RNCamera.Constants.Type.front}
  flashMode={RNCamera.Constants.FlashMode.off}
  autoFocus={RNCamera.Constants.AutoFocus.on}
  captureAudio={false}
  onBarCodeRead={(barcode) => {
    if (this.state.isModalVisible) {
      this.setState({
        isModalVisible : false
      }, () => this.captureQR(barcode.data));
    }
}}>

相关软件包代码

我发现了一些似乎相关的代码:

I found some code that seems relevant:

RNCamera.m

更具体地说,这里仅此部分:

More specifically just this section here:

如果device.position == RNCameraTypeFront,只要不满足其他任何条件,它将返回.

If device.position == RNCameraTypeFront it will just return providing it doesn't meet any of the other criteria.

    if (device == nil || self.autoFocus < 0 || device.focusMode != RNCameraAutoFocusOff || device.position == RNCameraTypeFront) {
        return;
    }

推荐答案

IOS具有

AVCaptureFocusModeContinuousAutoFocus :相机根据需要连续自动对焦.

AVCaptureFocusModeContinuousAutoFocus: The camera continuously autofocuses as needed.

您使用 isFocusModeSupported 方法来确定设备是否支持给定的focus mode ,然后使用focusMode属性设置模式.

You use the isFocusModeSupported: method to determine whether a device supports a given focus mode, then set the mode using the focusMode property.

react-native-camera将在两种不同的情况下更改焦点(您可以在此行上使用xcode设置断点):

react-native-camera will change the focus in two different scenarios (you can set a breakpoint with xcode on this lines):

  1. <仅当您的前置摄像头支持isFocusPointOfInterestSupportedAVCaptureFocusModeContinuousAutoFocus
  2. 时,c23> 方法才会设置焦点.
  1. focusWithMode method will set the focus only if your frontcamera supports isFocusPointOfInterestSupported and AVCaptureFocusModeContinuousAutoFocus

仅当以下条件返回时,该方法才会将对焦模式[device setFocusMode:focusMode];更改为AVCaptureFocusModeContinuousAutoFocus

The method will change the focus mode [device setFocusMode:focusMode]; to AVCaptureFocusModeContinuousAutoFocus only if the following condition is returns true

[device isFocusPointOfInterestSupported] && [device isFocusModeSupported:focusMode]

如果条件返回false,则没有autofocus,图片可能专注于 ExposureMode

If the condition returns false, there is no autofocus, but the picture may be focused on ExposureMode [device setExposureMode:exposureMode];

  1. updateAutoFocusPointOfInterest 根据用户触摸的x, y坐标,在用户点击屏幕时更改焦点.
  1. updateAutoFocusPointOfInterest changes the focus when the user taps on the screen, based on the x, y coordinates of his touch.

有几篇文章(文章1 帖子3 isFocusModeSupported isFocusPointOfInterestSupported

As there are several posts (post 1, post 2, post 3, post 4) on stackoverflow stating that different iphone versions do not support all type of autofocus with the frontcamera, I suggest you to set breakpoints on those line of codes and check the value of isFocusModeSupported and isFocusPointOfInterestSupported

这篇关于前置摄像头无法自动对焦或手动对焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆