Get camera ISO / shutter speed using CameraX or Camera2 - android

I'm trying to get the current preview's shutter speed and ISO settings.
I cannot find a way to do this using CameraX or Camera2. Is this not something that is available?
Failing that, is there a way to get the settings that were used to take a photo?

For Camera2, this information is available in the CaptureResult objects you get for every captured image, via onCaptureCompleted. However, not all devices support listing this information; only devices that list the READ_SENSOR_SETTINGS capability will do this. That includes all devices that list hardware level FULL or better, and may include some devices at the LIMITED level.
Specifically, you want to look at SENSOR_SENSITIVITY for ISO and SENSOR_EXPOSURE_TIME for shutter speed.
If you want the values used for a JPEG capture, look at the CaptureResult that comes from the CaptureRequest you used to request the JPEG.

I also was able to GET only the ISO settings using Jetpack/CameraX API through the Camera2CameraInfo.from and then getCameraCharacteristic. But it seems there is no way to set them (using CameraX).

In the latest releases of Jetpack/CameraX it is also possible to set the ISO/ShutterSpeed.
The below example sets the ISO for preview (written in C# language, but it is similar to Java):
var builder = new Preview.Builder();
var ext1 = new Camera2Interop.Extender(builder)
.SetCaptureRequestOption(CaptureRequest.ControlAeMode, (int)ControlAEMode.Off)
.SetCaptureRequestOption(CaptureRequest.SensorSensitivity, 3200);
var preview = builder.SetTargetName("PREVIEW").Build();
preview.SetSurfaceProvider(sfcPreview.SurfaceProvider);

Related

How to achieve Google Duo app's low light mode using Camera2 API?

I'm working on an Android app that streams video with another party, and currently looking at brightening the image in low light scenes.
I noticed that on Google Duo app, the low light mode does it really well.
Is it achievable using just Camera2 API? The reason I am not using CameraX API is because my app is also utilising Vonage (formerly TokBox) SDK for two way video call and it's SDK sample code currently uses Camera2 API and haven't migrated to CameraX yet.
What I tried is to set CONTROL_AE_MODE (Auto Exposure) to CONTROL_AE_MODE_ON, this helps a bit but the image quality is no where as near as Google Duo app's. I'm looking to decrease the Camera FPS next but what else can I do to brighten the image?
If you set CaptureRequest.CONTROL_AE_MODE to CaptureRequest.CONTROL_AE_MODE_OFF then you can control ISO CaptureRequest.SENSOR_SENSITIVITYand exposure time CaptureRequest.SENSOR_EXPOSURE_TIME manually.
You can read the available range of sensorSensitivity (ISO) like this val sensorSensitivityRange = cameraCharacteristics?.get(CameraCharacteristics.SENSOR_INFO_SENSITIVITY_RANGE) as Range<Int>? as this will vary from device to device / camera to camera.
So in low-light mode you could control the brightness yourself, and in normal mode, you let the camera do it automatically.
More information here:
https://developer.android.com/reference/android/hardware/camera2/CaptureRequest

Android 10 (api 29) how to enable HDR and Nigh Mode

I'm building a camera up designed to work exclusively on Pixel 3 XL. I'm using camera2 API and would like to take a picture using front facing camera with HDR and/or Night Mode enabled. This is a code snipped where I setup my capture request:
final CaptureRequest.Builder captureBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
captureBuilder.addTarget(mStillImageReader.getSurface());
captureBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_HDR);
captureBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_AUTO);
captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON);
captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CameraMetadata.CONTROL_AF_MODE_AUTO);
captureBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_SCENE_MODE_NIGHT);
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, 0);
...
mCaptureSession.capture(captureBuilder.build(), CaptureCallback, mBackgroundHandler);
I was hoping to get something close to what Android's native camera app is doing when it's set to shoot in Night Mode or HDR+. Does anybody know if I need to do more than just setting flags in capture request to get the desired behavior?
In Android the image processing algorithms can be implemented at HAL level as well as at application level. Android framework sits between HAL and application and provide an interface to interact with camera. When you call the set method:
captureBuilder.set(
CaptureRequest.CONTROL_SCENE_MODE,
CameraMetadata.CONTROL_SCENE_MODE_HDR);
You request the HAL to perform HDR before returning the image to application. Note that: HAL is implemented by OEMs (or the vendors) (can consider Pixel to be an OEM) and it's upto the implementer to implement different CONTROL_SCENE_MODES. You can and should query the available control modes using:
// Get the camera charecteristics for current camera
CameraCharacteristics cameraCharacteristics = getCameraCharecteristics(cameraFacing);
int[] modes = cameraCharacteristics.get(
CameraCharacteristics.CONTROL_AVAILABLE_SCENE_MODES);
// Check if the modes array has the SCENE MODE you wish to apply
// ... by iterating through the list.
If you run this on Pixel 3 XL, you may not get HDR supported. Correct me if I am wrong.
If you do not wish to write your own algorithms for HDR and Night Mode, you'd have to rely on available scene modes, and for that best would be to query and validate. Alternatively you can request YUV or RAW image from camera 2 and run them through HDR or Night Mode algorithms at application level.
TL;DR;
The Google Pixel's native camera is most likely doing more image processing on top of image returned by camera2 and hence it cannot be replicated by leveraging camera2 alone by setting any configurations.
HDR+ / HDR does not seem supported on Google's own Pixel phones, even with CameraX (and of course not with Camera2)
Myabe worth trying CameraX with a 3rd party extension, like this.
Problem is, CameraX is in a (very) alpha state as of now, and its fate is not clear either.

Querying Camera Params for Android Camera2 in Real-Time

I'm writing an application in which I'd like to retrieve the real-time values of various camera parameters (ie. ISO, shutter speed, aperture, but most importantly ISO). I am using the Android camera2 (and eventually camera1) API's.
I've found some links on stack overflow on retrieving those values for camera1 (though that functionality itself has limited support) and have looked through camera2 documentation, but haven't found a way to get those values (most importantly ISO) in real time. Any instructions on how to retrieve these values in real time/examples of such would be much appreciated!
On devices that support camera status output, those values are all available via CaptureResult, which is produced for each frame via onCaptureCompleted.
All devices that support the READ_SENSOR_SETTINGS capability will have the necessary values present, such as SENSOR_SENSITIVITY.

android.hardware.camera preview : How to manually set exposure time, shutter speed, aperture, and iso

I am working on an app where I have a camera preview and I take pictures in dark settings. Therefore, I need a way to manually control the exposure time of the camera and the settings of shutter speed, aperture, and iso.
I know it must be possible because the application Long Exposure Camera 2 (by AAASDream) has a way to manually change the exposure time and it works perfectly. I am not referring to the exposurecompensation which I already tried but was not sufficient enough.
Based off of this post, I tried setting
Camera.Parameters params = camera1.getParameters();
params.set("mode", "m");
params.set("aperture", 80);
params.set("shutter-speed", 9);
params.set("iso", 1600);
But this did not work at all.
Is there any hidden API or setting that I can use or any third party library I can use to accomplish this.
All help is appreciated, thanks.
I think there is no way to manually set the above mentioned values in android.hardware.camera. But it looks like the new version android.hardware.camera2 supports those functionalities.
Yes, it isn't possible to manually set one of the two mentioned parameters directly via the Camera 1 API. Neither the characteristics can be queried via a standardized method, because it isn't supported.
Of course there is a way around, to query or to set such properties via special methods, as relime9 currently mentioned:
// query all the settings you camera support (API 1)
mCamera.getParameters().flatten();
// set parameters - e.g. aperture
mCamera.getParameters().set("aperture", "80");
Additionally the specific device must support such a setting, which vary from device to device. On some devices there can be set certain values and with other you can't and can only use the ''auto'' mode.
For this reason they developed the Camera 2 API, which is more standardized and supports such functionalities.

How to get Video Encoding Parameters details of an Android device?

I wanted to know if there is any API that provides supported video encoding parameters of an Android device. I have gone through the link http://developer.android.com/guide/appendix/media-formats.html. The link mentions the supported formats but different devices may have different parameters support. I want to get those parameters in order to let the user know before hand that whether their device would be able to play back the videos within the app or not.
For example, HD feature may not be available on every device so if there is any API that provides that information then user can be informed that the device do not support it. Similarly, for other encoding parameters such as bitrate, frame rate, video resolution.
You may take a look at the answer I provided here:
Detect max video resolution support for a mobile device on responsive website
It explains the solution in detail and is currently the only one unfortunately.

Categories

Resources