相机自动对焦回调未发生
我在 Android 上使用相机 API,并让我的代码可以在多个平台上运行,包括 Samsung Galaxies 和 HTC Desire。到目前为止,我只在 HTC Desire Z 上遇到了问题,该问题是间歇性的。
在我的代码中,我正在调用以下说明,
camera.startPreview();
camera.autoFocus(autoFocusCallback);
其中我已经创建了所需的 autoFocusCallback 类。我想再次强调,这段代码适用于手机,包括我遇到问题的手机,所以不要仔细检查代码。 :) 调用回调后,我的代码将继续拍摄照片,但该部分目前无关紧要。
间歇性问题是,对于某张随机图片(20-100次发生一次),回调不发生。我已经用我自己的 Log.i() 验证了这是执行的最后一个命令(即代码没有到达回调)。调试也显示没有报错。
为了让您放心,我的回调看起来像这样
AutoFocusCallback autoFocusCallback = new AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
Log.i("tag","this ran");
...
...
}
};
成功运行的 Logcat 结果看起来像这样
07-12 10:17:50.564: DEBUG/QualcommCameraHardware(1223): startPreview X
07-12 10:17:50.564: DEBUG/QualcommCameraHardware(1223): autoFocus E
07-12 10:17:50.564: DEBUG/QualcommCameraHardware(1223): autoFocus X
07-12 10:17:50.564: DEBUG/QualcommCameraHardware(1223): runAutoFocus E
07-12 10:17:50.564: DEBUG/QualcommCameraHardware(1223): af start (fd 49)
07-12 10:17:51.184: DEBUG/QualcommCameraHardware(1223): native_set_afmode: ctrlCmd.status == 0
07-12 10:17:51.184: DEBUG/QualcommCameraHardware(1223): af done: 1
07-12 10:17:51.184: DEBUG/QualcommCameraHardware(1223): runAutoFocus X
07-12 10:17:51.184: DEBUG/QualcommCameraHardware(1223): takePicture(479)
但有问题的运行是这样的
07-12 10:17:52.194: DEBUG/QualcommCameraHardware(1223): startPreview X
07-12 10:17:52.194: DEBUG/QualcommCameraHardware(1223): autoFocus E
07-12 10:17:52.194: DEBUG/QualcommCameraHardware(1223): autoFocus X
07-12 10:17:52.194: DEBUG/QualcommCameraHardware(1223): runAutoFocus E
07-12 10:17:52.194: DEBUG/QualcommCameraHardware(1223): af start (fd 49)
,然后它挂起。
我想知道是否有人对这个问题有任何想法,或者您是否经历过类似的事情? 我只在网上找到了一个有类似问题的线程,这里是 http://groups.google.com/group/android-developers/browse_thread/thread/75ecb8db0ae02bdb
I am using the Camera API on the Android and gotten my code to work on several platforms including the Samsung Galaxies and HTC Desire. So far I'm only experiencing a problem on the HTC Desire Z, which is intermittent.
in my code I'm calling the following instructions
camera.startPreview();
camera.autoFocus(autoFocusCallback);
where I have already created the autoFocusCallback class required. I'd like to stress again that this code works on the phones, including the one I'm having problems with, so don't go scrutinizing the code. :) After the callback is called, my code then goes on to take the picture, but that part is irrelevant for now.
The intermittent problem is that for a certain random picture (happens one out of 20-100 times), the callback does not happen. I have verified with my own Log.i()'s that this is the last command performed (i.e. the code does not get to the callback). Debug also shows that no errors are reported.
Just to set your mind at ease, my callback looks something like this
AutoFocusCallback autoFocusCallback = new AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
Log.i("tag","this ran");
...
...
}
};
The Logcat results for a successful run looks something like this
07-12 10:17:50.564: DEBUG/QualcommCameraHardware(1223): startPreview X
07-12 10:17:50.564: DEBUG/QualcommCameraHardware(1223): autoFocus E
07-12 10:17:50.564: DEBUG/QualcommCameraHardware(1223): autoFocus X
07-12 10:17:50.564: DEBUG/QualcommCameraHardware(1223): runAutoFocus E
07-12 10:17:50.564: DEBUG/QualcommCameraHardware(1223): af start (fd 49)
07-12 10:17:51.184: DEBUG/QualcommCameraHardware(1223): native_set_afmode: ctrlCmd.status == 0
07-12 10:17:51.184: DEBUG/QualcommCameraHardware(1223): af done: 1
07-12 10:17:51.184: DEBUG/QualcommCameraHardware(1223): runAutoFocus X
07-12 10:17:51.184: DEBUG/QualcommCameraHardware(1223): takePicture(479)
But the problematic run is like this
07-12 10:17:52.194: DEBUG/QualcommCameraHardware(1223): startPreview X
07-12 10:17:52.194: DEBUG/QualcommCameraHardware(1223): autoFocus E
07-12 10:17:52.194: DEBUG/QualcommCameraHardware(1223): autoFocus X
07-12 10:17:52.194: DEBUG/QualcommCameraHardware(1223): runAutoFocus E
07-12 10:17:52.194: DEBUG/QualcommCameraHardware(1223): af start (fd 49)
and then it hangs.
I'd like to know if anyone has any ideas about this problem, or if you have experienced something similar?
I've only managed to find one thread on the net with similar problems, here it is http://groups.google.com/group/android-developers/browse_thread/thread/75ecb8db0ae02bdb
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
自动对焦调用没有超时。我遇到过一些设备,自动对焦调用偶尔无法回调(即使在完美的条件下)。相同的代码在其他设备上运行得很好。
我的解决方案是推出自己的自动对焦超时机制。我是在预定的未来完成的,但最佳的超时实现可能取决于您的具体用例。
Autofocus calls do not have a timeout. I've encountered some devices where autofocus calls sporadically fail to callback (even in perfect conditions). Where the same code runs just fine on other devices.
My solution was to roll my own timeout mechanism for autofocus. I did it with a scheduled future, but the best timeout implementation may depend on your specific use case.
不是针对您的特定问题的解决方案,但一般问题是您可能会在开始预览之前调用自动对焦。在这种情况下,打开预览时也不会发生自动对焦。
来自文档
“此方法仅在预览处于活动状态时有效(在
startPreview()
之间和stopPreview()
之前)。”Not a solution to your specific problem but the question in general is that you might call autofocus before startpreview. In this case also no autofocus is happening when the preview is turned on.
From the documentation
"This method is only valid when preview is active (between
startPreview()
and beforestopPreview()
)."