Android camera : Set metering spot position - android

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.

Related

Explicitly changing CameraX focus while the camera/preview is running? (Not just when building the camera.)

If you want to set the focus to a certain value (say, 10f) while building a CameraX camera, it's pretty easy ...
normally ...
previewBuilder = new Preview.Builder();
preview = previewBuilder.build();
launch camera with a fixed focus ...
previewBuilder = new Preview.Builder();
Camera2Interop.Extender x = new Camera2Interop.Extender(previewBuilder);
x.setCaptureRequestOption(CaptureRequest.CONTROL_AF_MODE, CameraMetadata.CONTROL_AF_MODE_OFF);
x.setCaptureRequestOption(CaptureRequest.LENS_FOCUS_DISTANCE, 10f);
preview = previewBuilder.build();
The camera and preview will now run, with the focus fixed at "10f".
But in CameraX how do you actually change the focus to some new value, say 5f
So for example using a slider to control the focus - while the camera is actually running.
I am aware you can tap to focus, but I wanna be able to give it a value, such as "5f".
BTW I tried changing the value, on the extended builder, while the camera is running (by hanging on to the builder), which wouldn't make any sense, but in fact you can't do it anyway, you just get an error.
I investigated FocusMeteringAction and it only allows for tap-to-focus; it does not have a "set the value" function.
Any ideas?

Android Camera2 API - Set AE-regions not working

In my Camera2 API project for Android, I want to set a region for my Exposure Calculation. Unfortunately it doesn't work. On the other side the Focus region works without any problems.
Device: Samsung S7 / Nexus 5
1.) Initial values for CONTROL_AF_MODE & CONTROL_AE_MODE
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
2.) Create the MeteringRectangle List
meteringFocusRectangleList = new MeteringRectangle[]{new MeteringRectangle(0,0,500,500,1000)};
3.) Check if it is supported by the device and set the CONTROL_AE_REGIONS (same for CONTROL_AF_REGIONS)
if (camera2SupportHandler.cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AE) > 0) {
camera2SupportHandler.mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_REGIONS, meteringFocusRectangleList);
}
4.) Tell the camera to start Exposure control
camera2SupportHandler.mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CameraMetadata.CONTROL_AE_PRECAPTURE_TRIGGER_START);
The CONTROL_AE_STATE is always in CONTROL_AE_STATE_SEARCHING, but doesn't use the configured regions...
After long testing & development I've found an answer.
The coordinate system - Camera 1 API VS Camera 2 API
RED = CAM1; GREEN = CAM2; As shown in the image below, the blue rect are the coordinates for a possible focus/exposure area for the Cam1. By using the Cam2 API, there must be firstly queried the max of the height and the width. Please find more info here.
Initial values for CONTROL_AF_MODE & CONTROL_AE_MODE: See in the question above.
Set the CONTROL_AE_REGIONS: See in the question above.
Set the CONTROL_AE_PRECAPTURE_TRIGGER.
// This is how to tell the camera to start AE control
CaptureRequest captureRequest = camera2SupportHandler.mPreviewRequestBuilder.build();
camera2SupportHandler.mCaptureSession.setRepeatingRequest(captureRequest, captureCallbackListener, camera2SupportHandler.mBackgroundHandler);
camera2SupportHandler.mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
camera2SupportHandler.mCaptureSession.capture(captureRequest, captureCallbackListener, camera2SupportHandler.mBackgroundHandler);
The ''captureCallbackListener'' gives feedback of the AE control (of course also for AF control)
So this configuration works for the most Android phones. Unfortunately it doesn't work for the Samsung S6/7. For this reason I've tested their Camera SDK, which can be found here.
After deep investigations I've found the config field ''SCaptureRequest.METERING_MODE''. By setting this to the value of ''SCaptureRequest.METERING_MODE_MANUAL'', the AE area works also the Samsung phones.
I'll add an example to github asap.
Recently I had the same problem and finally found a solution that helped me.
All I needed to do was to step 1 pixel from the edges of the active sensor rectangle. In your example instead of this rectangle:
meteringRectangleList = new MeteringRectangle[]{new MeteringRectangle(0,0,500,500,1000)};
I would use this:
meteringRectangleList = new MeteringRectangle[]{new MeteringRectangle(1,1,500,500,1000)};
and it started working as magic on both Samsung and Nexus 5!
(note that you should also step 1 pixel from right/bottom edges if you use maximum values there)
It seems that many vendors have poorly implemented this part of documentation
If the metering region is outside the used android.scaler.cropRegion returned in capture result metadata, the camera device will ignore the sections outside the crop region and output only the intersection rectangle as the metering region in the result metadata. If the region is entirely outside the crop region, it will be ignored and not reported in the result metadata.

Android Camera: fixed lens focus

I'm developing an Android application with a camera-related functionality feature.
First of all, I read a lot of stuff on SO, XDA and so on, then please don't redirect me to other useless posts.
I am trying to implement something like a "fixed focus mode", so that:
I start my application with FOCUS_MODE_AUTO (or something else);
bring into focus an object at an arbitrary distance;
fix the current focus;
move the camera on another object at a different distance which is out of focus.
I tried different solutions, i.e.:
mCamera.cancelAutoFocus() in the AutoFocusCallback to prevent the adjustment of the focus;
set a FocusArea: new Camera.Area(new Rect(-50, -50, 50, 50), 1000) to fix the focus on the current area.
I'm targeting API 20 and I'm working on a Samsung Galaxy S5. On this device, the supported focus modes are:
- auto
- infinity
- macro
- continuous-video
- continuous-picture
The suggestion that I found more frequently is to recompile Android...
"AUTO" mode doesn't mean that the camera continuously focuses - just that when you call the autoFocus command the focus is done automatically with no indication on what result you expect not like "Macro" or "Infinity".
http://developer.android.com/reference/android/hardware/Camera.html#autoFocus(android.hardware.Camera.AutoFocusCallback)
So if you don't have a loop that calls the autoFocus (as many examples do or call it again in the Callback) your focus should stay after it runs once.
If I understand, you want to focus keep the focus of the first object.
Have you tried to change the camera mode to FOCUS_MODE_FIXED after you focus the first object ?
Like that :
Camera.Parameters mParam = mCamera.getParameters();
mParam.setFocusMode(Camera.Parameters.FOCUS_MODE_FIXED);
mCamera.setParameters(mParam);

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).

Android Camera.takePicture - Possible to disable shutter sound and preview surface?

I am working on an app that will allow a user to take quick click and forget snapshots. Most of the app is done except for the camera working that way I would like. Right now I have the camera working but I can't seem to find a way to disable the shutter sound and I cant find a way to disable displaying the preview. I was able to cover the preview up with a control but I would rather just not have it displayed if possible.
To sum things up, these are the items that I would like to disable while utilizing the built in Camera controls.
Shutter sound
Camera screen display
Image preview onPictureTaken
Does anyone know of a resource that could point me in the right direction, I would greatly appreciate it. I have been following CommonsWare's example from this sample fairly closely.
Thank you.
This is actually a property in the build.prop of a phone. I'm unsure if its possible to change this. Unless you completely override it and use your own camera code. Using what you can that is available in the SDK.
Take a look at this:
CameraService.cpp
. . .
CameraService::Client::Client(const sp<CameraService>& cameraService,
const sp<ICameraClient>& cameraClient,
const sp<CameraHardwareInterface>& hardware,
int cameraId, int cameraFacing, int clientPid) {
mPreviewCallbackFlag = FRAME_CALLBACK_FLAG_NOOP;
mOrientation = getOrientation(0, mCameraFacing == CAMERA_FACING_FRONT);
mOrientationChanged = false;
cameraService->setCameraBusy(cameraId);
cameraService->loadSound();
LOG1("Client::Client X (pid %d)", callingPid)
}
void CameraService::loadSound() {
Mutex::Autolock lock(mSoundLock);
LOG1("CameraService::loadSound ref=%d", mSoundRef);
if (mSoundRef++) return;
mSoundPlayer[SOUND_SHUTTER] = newMediaPlayer("/system/media/audio/ui/camera_click.ogg");
mSoundPlayer[SOUND_RECORDING] = newMediaPlayer("/system/media/audio/ui/VideoRecord.ogg");
}
As can be noted, the click sound is started without your interaction.
This is the service used in the Gingerbread Source code.
The reason they DON'T allow this is because it is illegal is some countries. Only way to achieve what you want is to have a custom ROM.
Update
If what being said here: http://androidforums.com/t-mobile-g1/6371-camera-shutter-sound-effect-off.html
still applies, then you could write a timer that turns off the sound (Silent Mode) for a couple of seconds and then turn it back on each time you take a picture.
You may use the data from the preview callback using a function to save it at a picture on some type of trigger such as a button, using onclick listener. you could compress the image to jpeg or png. In this way, there no shutterCallback to be implemented. and therefore you can play any sound you want or none when taking a picture.
You can effectively hide the preview surface by giving it dimensions of 1p in the xml file (I found an example the said 0p but for some reason that was giving me errors).
It may be illegal to have a silent shutter in some places, but it doesn't appear that the US is such a place, as my HTC One gives me an option to silence it, and in fact, since Android 4.2 you can do this:
Camera.CameraInfo info=new Camera.CameraInfo();
if (info.canDisableShutterSound) {
camera.enableShutterSound(false);
}

Categories

Resources