gpt4 book ai didi

android - 如何在 Android 上更改相机曝光?

转载 作者:搜寻专家 更新时间:2023-11-01 09:27:26 25 4
gpt4 key购买 nike

我想用 OpenCV 和 android 进行图像处理。在第一步中,我需要更改分辨率、曝光等相机属性。通过使用 OpenCV,我只能更改分辨率(mOpenCvCameraView.setMaxFrameSize(320,240);) 而不能更改曝光。

通过使用 OpenCV 和 camera2 当我运行它时,它崩溃了(此代码:pastebin.com/3XgvKGQN)。
如何更改相机曝光?

package com.williams.drew.opencvtest;

import android.graphics.Paint;
import android.hardware.camera2.CameraDevice;
import android.hardware.camera2.CameraMetadata;
import android.hardware.camera2.CaptureRequest;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.SurfaceView;
import android.view.WindowManager;

import org.opencv.android.JavaCameraView;
import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;


public class MainActivity extends AppCompatActivity implements CvCameraViewListener2 {

//Prefixes for logging success and failure messages
private static final String TAG = "OCVSample::Activity";

//Loads camera view of OpenCV for us to use. This lets us see using OpenCV
private CameraBridgeViewBase mOpenCvCameraView;

//Preview Builder which changes exposure (i think)
private CaptureRequest.Builder mPreviewRequestBuilder;
private CaptureRequest mPreviewRequest;
private long exposureTime = 1000,frameDuration = 1000;
private int sensitivity = 200;

//OPENCV Variables
Mat matRGBA;

public MainActivity() {
Log.i(TAG, "Instantiated new " + this.getClass());
}

@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "called onCreate");
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.show_camera);

mOpenCvCameraView = (JavaCameraView) findViewById(R.id.show_camera_activity_java_surface_view);
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
mOpenCvCameraView.setCvCameraViewListener(this);
}

@Override
public void onPause() {
super.onPause();

if(mOpenCvCameraView != null) {
mOpenCvCameraView.disableView();
}
}

@Override
public void onResume() {
super.onResume();

if(!OpenCVLoader.initDebug()) {
Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for init");
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_1_0, this, mLoaderCallback);
}
else {
Log.d(TAG, "OpenCV library found inside package. Using it!");
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
}
}

@Override
public void onDestroy() {
super.onDestroy();

if(mOpenCvCameraView != null) {
mOpenCvCameraView.disableView();
}
}

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();
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};

@Override
public void onCameraViewStarted(int width, int height) {
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
mPreviewRequestBuilder.set(CaptureRequest.SENSOR_EXPOSURE_TIME, Long.valueOf(exposureTime));
mPreviewRequestBuilder.set(CaptureRequest.SENSOR_SENSITIVITY, Integer.valueOf(sensitivity));
mPreviewRequestBuilder.set(CaptureRequest.SENSOR_FRAME_DURATION, Long.valueOf(frameDuration));
matRGBA = new Mat(width, height, CvType.CV_8UC4);
}

@Override
public void onCameraViewStopped() {
matRGBA.release();
}

@Override
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
matRGBA = inputFrame.rgba();
return matRGBA;
}
}

感谢您的回答。

最佳答案

是的,OpenCV 没有公开所有相机参数。可以修改JavaCameraView并添加调用 setExposureCompensation() 的函数。

你想像这样调用那个函数:

    Camera mCamera;
mCamera = Camera.open();
Camera.Parameters params = mCamera.getParameters();
params.setExposureCompensation(0);

关于android - 如何在 Android 上更改相机曝光?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49691541/

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