Can an android.hardware.camera2.CaptureRequest be used with OpenCV?

那年仲夏 提交于 2021-02-18 20:26:55

问题


I've worked on this for days now. I have an OpenCV/JavaCameraView-based project I am trying to integrate with an Android android.hardware.camera2.CaptureRequest object I use to control the camera's sensitivity to light.

The CameraBridgeViewBase.CvCameraViewListener2/JavaCameraView project works (I can see an image on the screen), and the CaptureRequest project works (see this, too), but combining the two technologies in a single project has proved a big problem.

Has anyone gotten these two technologies to work together? My goal is to have the camera under the control of the CaptureRequest (limited SENSOR_SENSITIVITY + SENSOR_EXPOSURE_TIME), but for the screen to show a streaming image filtered through an OpenCV shared library I've written.

To control the camera, I can use something like this:

        mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()),
                new CameraCaptureSession.StateCallback() {
                    @Override
                    public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
                        // The camera is already closed
                        if (null == mCameraDevice) {
                            return;
                        }
                        long exposureTime = 66259688,frameDuration = 1000;
                        int sensitivity = 1512;

                        mCaptureSession = cameraCaptureSession;
                        try {

                            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                                    CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);

                            setAutoFlash(mPreviewRequestBuilder);
                            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));

                            mPreviewRequest = mPreviewRequestBuilder.build();
                            mCaptureSession.setRepeatingRequest(mPreviewRequest,
                                    mCaptureCallback, mBackgroundHandler);


                        } catch (CameraAccessException e) {
                            e.printStackTrace();
                        }catch (Exception e) {
                            e.printStackTrace();
                        }
                    }

To filter the image stream, I can use something like this:

public class MyCoolScanner extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener2 {
...
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    mRgba = inputFrame.rgba();

    OpenCVNative.myCoolLibrary(mRgba.getNativeObjAddr(),mGray.getNativeObjAddr());
    return mGray;
}

Thanks in advance.


回答1:


Please find implementation of open CV with Android , it may help you .

Camera calibration With OpenCV

Camera calibration - opencv 2.3.1 android

https://groups.google.com/forum/#!topic/android-opencv/xXtUvdA1E4M

https://fossies.org/dox/opencv-3.2.0/CameraCalibrationActivity_8java_source.html




回答2:


I believe OpenCV does not natively support use with android.camera2




回答3:


The answer is no, OpenCV will not work with android.camera2, not without some kind of convoluted work around.



来源:https://stackoverflow.com/questions/42225931/can-an-android-hardware-camera2-capturerequest-be-used-with-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!