title: Can an android.hardware.camera2.CaptureRequest be used with OpenCV?
body: <p>I've worked on this for days now. I have an OpenCV/JavaCameraView-based project I am trying to integrate with an Android <code>android.hardware.camera2.CaptureRequest</code> object I use to control the camera's sensitivity to light. </p>
  
  <p>The <code>CameraBridgeViewBase.CvCameraViewListener2/JavaCameraView</code> project works (I can see an image on the screen), and the <code>CaptureRequest</code> project works (see this, too), but combining the two technologies in a single project has proved a big problem. </p>
  
  <p>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. </p>
  
  <p>To control the camera, I can use something like this: </p>
  
  <pre><code>        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();
                          }
                      }
  </code></pre>
  
  <p>To filter the image stream, I can use something like this: </p>
  
  <pre><code>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;
  }
  </code></pre>
  
  <p>Thanks in advance. </p>