我正在编写一个持续处理预览帧的相机应用程序,当它检测到感兴趣的主体时,会自动拍摄一张全尺寸照片,并将焦点/测光参数设置为感兴趣的区域。
除了三星Galaxy S4 GT-I9500,Android版本4.4.2外,它在我必须测试的所有设备上运行良好。
此设备上的问题是传递给mCamera.autoFocus(Camera.AutoFocusCallback callback)
的回调有时会被调用两次
还有其他人遇到类似的问题吗?任何想法如何解决这个问题?
示例代码:
mCamera.autoFocus(new Camera.AutoFocusCallback() {
private volatile boolean firstTime = true;
@Override
public void onAutoFocus(boolean success, Camera camera) {
if (firstTime) {
firstTime = false;
Log.d(LOG_TAG, "Autofocus success ? " + success);
if (success) {
takePicture();
} else {
if (!postDelayed(new Runnable() {
@Override
public void run() {
Log.w(LOG_TAG, "Failed auto-focus, retrying...");
handleTakePicture();
}
}, 300)) {
handleTakePicture();
}
}
} else {
Log.d(LOG_TAG, "Bogus devicius!");
}
}
});
日志:
05-13 16:34:52.761 1311-1311/SimpleCameraImagingSampler: surfaceCreated main
05-13 16:34:52.761 1311-1311/SimpleCameraImagingSampler: openCamera main
05-13 16:34:52.796 1311-1311/SimpleCameraImagingSampler: Detected optimalPreviewSize: W 800 x H 480
05-13 16:34:52.796 1311-1311/SimpleCameraImagingSampler: optimalPictureSize: W 4128 x H 3096
05-13 16:34:52.801 1311-1311/SimpleCameraImagingSampler: attachCamera main
05-13 16:34:52.801 1311-1311/SimpleCameraImagingSampler: surfaceChanged main
05-13 16:34:52.801 1311-1311/SimpleCameraImagingSampler: re-attachCamera main
05-13 16:34:54.346 1311-1311/SimpleCameraImagingSampler: Focus/metering set to: focus=true, metering true : -200 -201 200 600
05-13 16:34:54.351 1311-1311/SimpleCameraImagingSampler: Performing initial autofocus
05-13 16:34:55.426 1311-2204/SimpleCameraImagingSampler: Start detailed sampling
05-13 16:34:55.426 1311-2204/SimpleCameraImagingSampler: handleTakePicture()
05-13 16:34:55.431 1311-2204/SimpleCameraImagingSampler: Applying ROIs: -668 -559 637 404
05-13 16:34:55.441 1311-2204/SimpleCameraImagingSampler: Focus/metering set to: focus=true, metering true :-668 -559 637 404
05-13 16:34:55.626 1311-1311/SimpleCameraImagingSampler: Autofocus success ? true
05-13 16:34:55.631 1311-1311/SimpleCameraImagingSampler: takePicture() ; Camera.Parameters==preferred-preview-size-for-video=1920x1080;sharpness-max=2;hue-min=-2;focallength-value-denominator=100;zoom=0;intelligent-mode=-1;hue=0;max-num-detected-faces-hw=16;video-stabilization=false;zoom-supported=true;sharpness-min=-2;sharpness=0;contrast=auto;whitebalance=auto;scene-mode=auto;jpeg-quality=90;focallength-value-numerator=420;preview-format-values=yuv420sp,yuv420p;rotation=0;jpeg-thumbnail-quality=100;preview-format=yuv420sp;metering-areas=(-200,-201,200,600,1);video-size-values=1920x1080,1440x1080,1280x720,960x720,800x450,720x480,640x480,480x320,352x288,320x240,176x144;preview-size=800x480;focal-length=4.20;iso=auto;fast-fps-mode=-1;flash-mode-values=off,auto,on,torch;preview-frame-rate-values=7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30;contextualtag-cityid=0;max-num-metering-areas=32;preview-frame-rate=30;focus-mode-values=auto,macro,continuous-picture,continuous-video,;jpeg-thumbnail-width=512;video-size=1920x1080;scene-mode-values=auto,action,portrait,landscape,night,night-portrait,theatre,beach,snow,sunset,steadyphoto,fireworks,sports,party,candlelight;preview-fps-range-values=(15000,30000),(30000,30000);vtmode=0;jpeg-thumbnail-size-values=512x384,512x288,480x320,320x240,320x180,0x0;zoom-ratios=100,110,120,130,140,150,160,170,180,190,200,210,220,230,240,250,260,270,280,290,300,310,320,330,340,350,360,370,380,390,400;preview-size-values=1920x1080,1440x1080,1280x960,1280x720,1056x864,1024x768,1008x566,800x600,800x480,800x450,720x480,640x480,528x432,480x320,480x270,352x288,320x240,176x144;maxaperture-value-denominator=100;dual_mode=-1;picture-size-values=4128x3096,4128x2322,4096x3072,4096x2304,3264x2448,3264x1836,3200x2400,3072x1728,2592x1944,2592x1936,2560x1920,2048x1536,2048x1152,2032x1142,1920x1080,1600x1200,1440x1080,1280x960,1280x720,1024x768,1008x566,800x600,800x480,800x450,720x480,640x480,512x384,512x288,480x320,320x240,320x180;preview-fps-range=15000,30000;min-exposure-compensation=-4;brightness-min=-2;antibanding=50hz;max-num-focus-areas=1;saturation-min=-2;vertical-view-angle=39.4;brightness-max=2;horizontal-view-angle=51.2;imageuniqueid-value=S13L0SAGJ01;brightness=0;video-stabilization-supported=true;maxaperture-value-numerator=227;jpeg-thumbnail-height=384;smooth-zoom-supported=false;focus-mode=auto;focallength-35mm-value=31;auto-whitebalance-lock-supported=true;video-frame-format=yuv420sp;max-num-detected-faces-sw=0;picture-format-values=jpeg;saturation-max=2;max-exposure-compensation=4;focus-areas=(-668,-559,637,404,1);video-snapshot-supported=true;exposure-compensation=0;exposure-compensation-step=0.5;flash-mode=torch;effect-values=none,mono,negative,solarize,sepia,posterize,whiteboard,blackboard,aqua;fnumber-value-numerator=22;picture-size=4128x3096;max-zoom=30;effect=none;saturation=0;dualrecording-hint=-1;whitebalance-values=auto,incandescent,fluorescent,daylight,cloudy-daylight,;picture-format=jpeg;focus-distances=0.10,1.20,Infinity;fnumber-value-denominator=10;Infinity=Infinity;wdr=0;auto-exposure-lock-supported=true;hue-max=2;antibanding-values=50hz
05-13 16:34:56.521 1311-1311/SimpleCameraImagingSampler: Bogus devicius!
05-13 16:34:59.971 1311-1311/SimpleCameraImagingSampler: surfaceDestroyed main
05-13 16:34:59.971 1311-1311/SimpleCameraImagingSampler: stopCameraPreview main
05-13 16:35:00.371 1311-1311/SimpleCameraImagingSampler: Releasing camera! main