gpt4 book ai didi

java - 拍照时如何通过Java从Android手机相机获取曝光补偿级别?

转载 作者:搜寻专家 更新时间:2023-10-30 21:33:21 26 4
gpt4 key购买 nike

如何从Android手机拍照时获取AutoExposureCompensation级别(亮度)?

我可以拍照。我可以访问相机的参数,包括曝光补偿(检查时始终为零),但我需要在拍摄照片时获得 AE 补偿级别,而不是之前和之后。

背景:我希望在特定时间拍摄的所有照片都使用与拍摄照片相同的 AE 补偿级别。我不希望 Android 相机通常对曝光级别或白平衡进行数百次调整。我想获得一次,并为所有后续照片设置相同的设置。

我尝试过对图片、OpenCV、 fragment 等使用“intents”。我似乎无法使用其中任何一个获得 AE 补偿设置。这是我尝试过的最新代码,从扩展版本的 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);
}
}

下面是使用上述类的 Android View 中的一些代码:

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;
}

最佳答案

我认为 camera2 API ( https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html) 可以满足您的需求。

Source: https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html#CONTROL_AE_LOCK

Since the camera device has a pipeline of in-flight requests, thesettings that get locked do not necessarily correspond to the settingsthat were present in the latest capture result received from thecamera device, since additional captures and AE updates may haveoccurred even before the result was sent out. If an application isswitching between automatic and manual control and wishes to eliminateany flicker during the switch, the following procedure is recommended:

  1. Starting in auto-AE mode:
  2. Lock AE
  3. Wait for the first result to be output that has the AE locked
  4. Copy exposure settings from that result into a request, set the request to manual AE
  5. Submit the capture request, proceed to run manual AE as desired.

也根据AE模式的描述(同源)

When set to any of the ON modes, the values chosen by the cameradevice auto-exposure routine for the overridden fields for a givencapture will be available in its CaptureResult.

因此,一旦您发出第一个 CaptureRequest,就可以使用来自以下回调的 TotalCaptureResult:

void onCaptureCompleted (CameraCaptureSession session, 
CaptureRequest request,
TotalCaptureResult result)
{
int aecompensationlevel = result.get(CaptureResult.CONTROL_AE_EXPOSURE_COMPENSATION)
}

关于java - 拍照时如何通过Java从Android手机相机获取曝光补偿级别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41934633/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com