How to get AutoExposureCompensation level (brightness) from Android phone when the picture is taken?
I can take a picture. I can access the Parameters of the Camera, including the Exposure Compensation (always zero when I check), but I need to get the AE Compensation level at the moment the picture is taken, not before and not afterward.
Background: I want all pictures, taken at a certain time, to use the same AE Compensation level the pictures are taken. I don't want those hundreds of adjustments to the exposure level, or the white balance, that Android cameras typically do. I want to get once, and set for all the succeeding photos, the same settings.
I have tried using "intents" for pictures, OpenCV, fragments, etc. I can't seem to get the AE compensation setting with any of these. Here's the latest code I've tried, starting with the an extended version of JavaCameraView:
import org.opencv.android.JavaCameraView;
import android.content.Context;
import android.hardware.Camera;
import android.hardware.Camera.PictureCallback;
import android.hardware.Camera.Size;
import android.util.AttributeSet;
import android.util.Log;
@SuppressWarnings("deprecation")
public class NewJavaCameraView extends JavaCameraView implements PictureCallback {
public int getExposureCompensation(){
return mCamera.getParameters().getExposureCompensation();
}
@SuppressWarnings("deprecation")
public void takePicture(final String fileName) {
Log.i(TAG, "Taking picture");
this.mPictureFileName = fileName;
Camera.Parameters params = mCamera.getParameters();
int exposureComp = params.getExposureCompensation();
mCamera.setPreviewCallback(null);
// PictureCallback is implemented by the current class
int otherexposureComp =this.getExposureCompensation();
mCamera.takePicture(null, null, this);
}
@SuppressWarnings("deprecation")
@Override
public void onPictureTaken(byte[] data, Camera camera) {
Camera.Parameters params = mCamera.getParameters();
int exposureComp = params.getExposureCompensation();
int otherexposureComp =this.getExposureCompensation();
mCamera.startPreview();
mCamera.setPreviewCallback(this);
// Write the image in a file (in jpeg format)
try {
FileOutputStream fos = new FileOutputStream(mPictureFileName);
fos.write(data);
fos.close();
} catch (java.io.IOException e) {
Log.e("Picture", "photoCallback", e);
}
}
Here's some of the code from the Android View that's using the abovementioned class:
public class DiscPhoto extends Activity implements CvCameraViewListener2, OnTouchListener {
private static final String TAG = "OCVSample::Activity";
private NewJavaCameraView mOpenCvCameraView;
private List<Size> mResolutionList;
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i(TAG, "OpenCV loaded successfully");
mOpenCvCameraView.enableView();
mOpenCvCameraView.setOnTouchListener(DiscPhoto.this);
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
public DiscPhoto() {
Log.i(TAG, "Instantiated new " + this.getClass());
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "called onCreate");
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_disc_photo);
mOpenCvCameraView = (NewJavaCameraView) findViewById(R.id.discPhotoPage);
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
mOpenCvCameraView.setCvCameraViewListener(this);
}
@SuppressLint("SimpleDateFormat")
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.i(TAG,"onTouch event");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
String currentDateandTime = sdf.format(new Date());
String fileName = Environment.getExternalStorageDirectory().getPath() +
"/sample_picture_" + currentDateandTime + ".jpg";
mOpenCvCameraView.takePicture(fileName);
Toast.makeText(this, fileName + " saved", Toast.LENGTH_SHORT).show();
return false;
}