Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 454
Brian Avatar asked Feb 14 '17 12:02

Brian


1 Answers

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

like image 142
Chetan Joshi Avatar answered Sep 27 '22 16:09

Chetan Joshi