Android 4 - Camera White Balancing stops after autoFocus - android

In my current application, I've got a class holding an instance of a Camera object and trying to do the following:
1) Wait for a specified time, e.g. nothing (this is done via a TimerTask)
2) Request to focus via autoFocus
3) In autoFocus callback, request OneShotPreviewCallback
4) In preview callback, save image
5) Repeat
While the white balancing is working fine prior to the first autoFocus, it stops after the first focussing has been done. Well, of course I looked up the API, and there is one interesting statement in the autoFocus description.
But auto-focus routine may stop auto-exposure and auto-white balance transiently during focusing.
But it seems it is non stopped only transiently, but permantly. Funny enough, with the subsequent call of autoFocus, the camera tries to ajust the whitening again, but the correct value is mostly only with the second or third autoFocus.
I also tried to set the white balancing in code, but it didn't change anything.
setWhiteBalance(Camera.Parameters.WHITE_BALANCE_AUTO);
Does anyone else know this issue, or am I missing some point ? I know that I could permanently call autoFocus to force the white balancing, but that doesn't seem the optimal way for me, because prior to the first call auf autoFocus, it works perfectly fine.
P.S.: I'm testing on a Samsung Galaxy S2 with Android 4.0.3.

I have ran into similar issue on Samsung Galaxy 2 Duos 2. In this case, the auto exposure settings have stopped working instead of the WB. I tried to cycle (on/off) the auto exposure param and it worked for me.
mCamera.autoFocus(new Camera.AutoFocusCallback() {
#Override
public void onAutoFocus(boolean b, Camera camera) {
Camera.Parameters params = camera.getParameters();
if (params.isAutoExposureLockSupported()) {
params.setAutoExposureLock(true);
camera.setParameters(params);
params = camera.getParameters();
params.setAutoExposureLock(false);
camera.setParameters(params);
}
}
});

I've got the similar problem on Samsung Galaxy Ace - after first autofocus, camera white balancing turns off and does not turn on again, no matter how much I do autofocus after.
As there are no API methods to tell camera to resume white balancing, and resetting the camera parameters in autofocus callback doesn't do the trick, my guess is that it is a bug in camera driver in Samsung phones - I've tried my application with different phones and only on this Samsung Galaxy Ace (GT-S5830; updated to Android 2.3.3), camera white balancing does not resume after autofocusing.
Maybe we should issue a bug ticket on developer.samsung.com?

It seems that
mCamera.stopPreview();
mCamera.startPreview();
in AutoFocusCallback can enable auto exposure again, but bringing a very short pause on the preview as side effect.

Related

Android camera : Set metering spot position

I'm trying to implement tap to focus on a Samsung Xcover4 for an industrial application (specific to this device).
The idea is to have the device stuffed into a kind of box with a hole where the camera is, and to use it to scan cards with qr codes on it.
So the "scan zone" is always the same, and should be set when the app start with a tap. Once it's done, camera should always focus on that zone and compute exposure on that spot
I'm using Xzing library, so I hacked the CameraManager manager class a little and it's working ok for the fixed focus zone.
I found the "spot" metering value by dumping native camera parameters, but one thing I can't figure out is how to set its position. I guess it can be done, since samsung does it in the native camera app.
ArrayList<Camera.Area> focusAreas = new ArrayList<Camera.Area>();
focusAreas.add(new Camera.Area(focusArea, 1000));
cameraParameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
cameraParameters.setFocusAreas(focusAreas);
cameraParameters.setMeteringAreas(focusAreas);
cameraParameters.setZoom(0);
cameraParameters.set("metering", "spot");
camera.setParameters(cameraParameters);
camera.autoFocus(autoFocusManager);
Below is the list of natvie camera paremeters.
3dnr=false;
Infinity=Infinity;
antibanding=50hz;
antibanding-values=auto,50hz;
auto-exposure-lock-supported=true;
auto-whitebalance-lock-supported=true;
best-capture=0;
brightness=0;
brightness-max=2;
brightness-min=-2;
burst-capture=0;
burstshot-fps-values=(4,4);
constant-growth-rate-zoom-supported=true;
contrast=auto;
drc=false;
dual_mode=-1;
dualrecording-hint=-1;
dynamic-range-control=off;
effect=none;
effect-available-fps-values=(10000,15000);
effect-values=none,mono,negative,sepia,posterize;
effectrecording-hint=0;
exposure-compensation=0;
exposure-compensation-step=0.1;
fast-fps-mode=-1;
flash-mode=off;
flash-mode-values=off,auto,on,torch;
fnumber-value-denominator=10;
fnumber-value-numerator=19;
focal-length=3.70;
focallength-35mm-value=28;
focallength-value-denominator=100;
focallength-value-numerator=370;
focus-areas=(257,416,263,422,1000);
focus-distances=0.10,1.20,Infinity;
focus-mode=auto;
focus-mode-values=auto,macro,continuous-video,continuous-picture;
hdr-mode=0;
horizontal-view-angle=62.2;
hue=0;
hue-max=2;
hue-min=-2;
imageuniqueid-value=V13LLIA02PM V13LLKB16SA
;
intelligent-mode=-1;
iso=auto;
iso-values=auto,100,200,400,800;
jpeg-quality=96;
jpeg-thumbnail-height=384;
jpeg-thumbnail-quality=100;
jpeg-thumbnail-size-values=512x384,512x288,384x384,320x240,0x0;
jpeg-thumbnail-width=512;
max-exposure-compensation=20;
max-num-detected-faces-hw=16;
max-num-detected-faces-sw=0;
max-num-focus-areas=1;
max-num-metering-areas=0;
max-zoom=30;
maxaperture-value-denominator=100;
maxaperture-value-numerator=185;
metering=center;
metering-areas=;
metering-values=matrix,center,spot;
min-exposure-compensation=-20;
odc=false;
phase-af=off;
phase-af-values=off;
picture-format=jpeg;
picture-format-values=jpeg;
picture-size=4128x3096;
picture-size-values=4128x3096,4128x2322,3264x2448,3264x1836,3088x3088,2160x2160,2048x1536,2048x1152,1920x1080,1440x1080,1280x720,960x720,640x480,320x240;
preferred-preview-size-for-video=1280x720;
preview-format=yuv420sp;
preview-format-values=yuv420sp,yuv420p;
preview-fps-range=15000,30000;
preview-fps-range-values=(15000,15000),(24000,24000),(15000,30000),(30000,30000);
preview-frame-rate=30;
preview-frame-rate-values=15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30;
preview-size=1280x720;
preview-size-values=1280x720,1056x704,960x720,880x720,720x720,720x480,640x480,352x288,320x240,176x144;
rotation=0;
rt-hdr=off;
rt-hdr-values=off;
saturation=0;
saturation-max=2;
saturation-min=-2;
scene-mode=auto;
scene-mode-values=auto,action,portrait,landscape,night,night-portrait,theatre,beach,snow,sunset,steadyphoto,fireworks,sports,party,candlelight;
sharpness=0;
sharpness-max=2;
sharpness-min=-2;
smooth-zoom-supported=false;
vertical-view-angle=39.4;
video-frame-format=nv21;
video-size=1920x1080;
video-size-values=1920x1080,1440x1080,1072x1072,1280x720,960x720,800x450,720x480,640x480,480x320,352x288,320x240,176x144;
video-snapshot-supported=true;
video-stabilization-supported=false;
vrmode=-1;
wdr=0;
whitebalance=auto;
whitebalance-values=auto,incandescent,fluorescent,daylight,cloudy-daylight;
zoom=0;
zoom-ratios=100,104,109,114,120,125,131,138,144,151,158,166,174,182,190,200,209,219,229,240,251,263,276,289,303,317,332,348,364,381,400;
zoom-supported=true
Thank you.

stopPreview/takePhoto stops freezing image after setPictureSize to camera parameters

So I am making an application where you can take some pictures.
I had everything working as it should besides of the PictureSize.
After you take a picture, the preview is supposed to freeze with the last image taken, just like TakePhoto usually do for you. This works as it should until i do parameters.setPictureSize in this method:
public void setupCameraParameters() {
Camera.Parameters parameters = mCamera.getParameters();
Camera.Size preSize = determineBestPreviewSize(parameters);
Camera.Size picSize = determineBestPictureSize(parameters);
parameters.setPreviewSize(preSize.width, preSize.height);
parameters.setPictureSize(picSize.width, picSize.height);
parameters.setRotation(90);
mCamera.setParameters(parameters);
}
This gives my pictures the correct sizes, however what happends now is that my preview doesn't freeze after TakePhoto is called, it just keeps feeding from my camera.
I have even tried doing mCamera.stopPreviewing() without any freezing images. If i release the camera, the image gets black as it should do so I really am working on the right camera-instance as well.
Is there any documentation I have missed? Have someone else entered this problem before.
EDIT:
So I got back my xperia z3 compact from repair and checked this issue again. On z3 this never is an issue, the code will take a picture and then freeze the preview like I want it to. My other phone was a HTC one (m7).

Android auto focus when continuous auto focus modes are not supported

I have a camera in my app and I want to make it auto focus continuously in the same way that the phone's camera does it. I found the modes FOCUS_MODE_CONTINUOUS_VIDEO and FOCUS_MODE_CONTINUOUS_PICTURE, but they are not supported by some of the HTC Gingerbread phones I'm testing on.
This is what I'm doing to determine whether I can use these modes:
Camera.Parameters parameters = mCamera.getParameters();
List<String> supportedFocusModes = parameters.getSupportedFocusModes();
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH &&
supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
}
else if (supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
}
else if (supportedFocusModes.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
// auto focus on request only
parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
}
Running on several different Gingerbread HTC phones I don't get the continuous modes back, but I get "auto". This lets me auto focus on demand (when I call mCamera.autoFocus(null), but the camera will not refocus if the user moves the camera.
I cannot set the focus mode to anything the camera does not support, and if I do it shows up blank.
One solution that I tried is to call mCamera.autoFocus(null) on a timer. This causes the camera to refocus continuously, even if it is already in focus.
Is there a way to implement a continuous auto focus experience on these phones? When I look at HTCs camera app on these phones it does have continuous auto focus - as you move around the camera refocuses and does not keep refocusing once the picture is in focus.
We had a requirement to support a very wide range of phones. My solution in the end was to handle each case differently.
For the scenario of phones without continuous auto-focus support I implemented a utility to listen to the accelerometer using SensorManager and trigger mCamera.autoFocus(...) whenever the user moves the camera.
There were also some older tablets that only supported fixed focus (who would use such a thing!), in that case the picture needed to be taken immediately - not on the focus callback.
For most modern phones the code snippet above was fine to use FOCUS_MODE_CONTINUOUS_PICTURE.
I got a similar pb on my samsung S4 and I solved it with:
camera.setParameters(parameters);
camera.autoFocus(null);
This is suggest in the Google doc here.
To make the camera parameters take effect, your application has to call setParameters(Camera.Parameters).

Strange android camera behaviour when torch is on

I have following android code (written here in pseudocode):
mCamera = configAndInitialize(); //all I want to do before taking picture
mCamera.startPreview();
mCamera.torchOn(); //setting parameters with flash mode torch
onClick(){
mCamera.stopPreview();
mCamera.takePicture();
mCamera.torchOff();
}
Sometimes (often when phone was recently restarted and camera wasn't in use until this app) this code ends with error 100 Camera server died. If camera took successfully picture before it usually works.
I was debugging it for great amount of time and I found out it works when I comment out lines with torch. I can see torch working in both cases when taking pictures works or not.
Code of torchOn is following:
if(mCamera != null){
mCamera.stopPreview();
Camera.Parameters p = mCamera.getParameters();
List<String> supported = p.getSupportedFlashModes();
if (supported.contains(Camera.Parameters.FLASH_MODE_TORCH)) {
p.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
}
mCamera.setParameters(p);
mCamera.startPreview();
}
Is there any reason why taking picture could not work because of torch? I observed it happend on Motorola Razr and Samsung Galaxy SIII.
I installed on my device two version of this app (with different name and so on). And I do following:
Restart device
Tried app-with-torch
If app-with-torch does work back in point 1.
Tried app-without-torch
Tried app-with-torch
And the results are followings:
App-without-torch works always
App-with-torch in about 80% of tries doesn't work at point 2. (after restart)
App-with-torch works always at point 5. (after app-without-torch was used)
My app start working even if I add torchOff() just before taking picture.
We could call this the " Monty Python Dead Parrot Log.d answer " :-P I wish I had a solution for you - do have some suggestions though. Heisenbugs are difficult to catch.
Does the torch have an isOn() test ?
Similarly (I don't recall), does the camera have an isReady() test ?
Can you tell from the logs if the camera dies before, during, or after mCamera.torchOn() or .torchOff() ?
What would happen if you stretch out the time span between calls ? This wouldn't be useable for the real app, but might help you monitor and catch what's happening. Say something like this in pseudo code:
try {
// Log.d ("cam", "here 1") ;
mCamera = configAndInitialize();
// Log.d ("cam", "here 2");
if ( mCamera.isReady() ) { // or isConfigured / initialized
// Log.d ("cam", "here 2");
Camera.startPreview();
// Log.d ("cam", "here 2");
thisThread.setDelay (200); // millisecs. try even up to 2000 ms !
// Log.d ("cam", "here 4");
mCamera.torchOn();
// Log.d ("cam", "here 5");
thisThread.setDelay (200); // again up to 2000 ms
// Log.d ("cam", "here 6");
}
} catch (Exception e) {
Log.d ("oops!", e.toString() );
}
The other thing to monitor, or make sure of, is that the camera and torch really are ready before that onClick can fire. Sprinkle some delays like the Log.d's all around and see. It might need a call back (mCamera.isReady() then enable onClick ).
Another thing to do is see if you can dig up the camera's source code (or the torch's) and GREP for error 100 - or is that a generic android 100 ?
I'm sure you're well aware of how much stuff happens when that camera gets fired up - seems like hundreds of calls. Since some of these low level items are async (cam is hardware after all), I suspect you're getting a NPE or a insufficiently initialized object. Not all NPE's etc get trapped, so it might just die on one that would not be there if delayed or syncronized sequences are used.
( HTH - I feel your pain, ari, I had to do a lot of camera stuff recently. Debugging on Samsung SIII is prohibitively time consuming. )
[EDIT] you've probably already found this link, but just in case:
How to turn on camera flash light programmatically in Android?
I think this is related to each OEM's implementation of the Android camera HAL (Hardware Abstraction Layer). This problem has also happened to me, I'm not sure but I suspect most camera HALs' torch mode works only in video capture, as that's where it's most used anyways. Try recording a video with the torch on to check it out.
One possible workaround would be to set your camera's flash mode to FLASH_MODE_ON just before taking the picture and then returning to FLASH_MODE_TORCH after the pic is taken if you need it again.

Setting Parameters.FLASH_MODE_TORCH doesn't work on Droid X 2.3

I am writing an app that sets the flash mode to torch. I have been testing the application on my Droid X, and the LED light does not come on. I tried it on a Droid Incredible and it worked fine. I can't figure out what the problem is. Here is part of my code for turning on torch mode.
Camera mCamera = Camera.open();
Camera.Parameters params = mCamera.getParameters();
if(params.getFlashMode() != null){
params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
}
mCamera.setParameters(params);
I have added mCamera.startPreview(); because I read that should make a difference, but it doesn't. I also made a list of available flash modes and displayed them to the screen to make sure that my Droid X does have torch mode, and it was in the list. I even created a new application from code I found online that turns the LED flash on and off with a button. Again it worked fine on the Droid Incredible but not the Droid X. Is there something I am missing to get this to run on the Droid X, or could it be something with Gingerbread? The Droid X is running Gingerbread and the Droid Incredible is running FroYo.
There are quite a few quirks when setting FLASH_MODE_TORCH.
Often you need to start a camera preview:
Camera mCamera = Camera.open();
mCamera.startPreview();
Camera.Parameters params = mCamera.getParameters();
if(params.getFlashMode() != null){
params.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
}
mCamera.setParameters(params);
That may resolve it on some phones, other phones also require the preview to be drawn to a SurfaceView. This can be done by implementing SurfaceHolder.Callback interface in your activity.
See an example here.
It could be that the Droid X doesn't support Torch Mode. Try something like this:
List<String> pList = camera.getParameters().getSupportedFlashModes();
if (pList.contains(Parameters.FLASH_MODE_TORCH))
parameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
camera.setParameters(parameters);
Refer to Issue 191453:
SurfaceTexture mDummy = new SurfaceTexture(1); // any int argument will do
camera.setPreviewTexture(mDummy);
camera.startPreview();
The only thing I found that works on the Droid X is the code presented by Siddhpura Amit part way down the page in this answer Use camera flashlight in Android. He checks the manufacturer and checks to see if it contains the string "motorola." If so, he has special code that can switch the camera Flash LED on or off. I can verify that it does work as I have a Motorola Droid X.

Categories

Resources