在Raspberry Pi 3 Android上使用Camera2 createCaptureSession时配置失败

时间:2018-07-12 08:03:27

标签: android raspberry-pi raspberry-pi3

当前在Android Things(Oreo 8.1)上使用我的设备Raspberry pi model 3

首先,我尝试打开相机设备,然后单击“捕获”按钮, 获取相机预览jpg文件。

我的来源

private CameraDevice mCameraDevice;
private CameraCaptureSession mCaptureSession;
private ImageReader mImageReader;
private CaptureRequest.Builder captureBuilder;

private final TextureView.SurfaceTextureListener mSurfaceTextureListener = new TextureView.SurfaceTextureListener() {

   @Override 
   public void onSurfaceTextureAvailable(SurfaceTexture texture, int width, int height) {
        openCamera(width, height);
    }
   ...
}

private void openCamera(int width, int height) {
    //camera open ...
    CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);

    mImageReader = ImageReader.newInstance(320, 240, ImageFormat.JPEG, 1);
    manager.openCamera(cameraId, mStateCallback, mBackgroundHandler);
}

//Camera preview check
private final CameraDevice.StateCallback mStateCallback = new CameraDevice.StateCallback() {
    @Override
    public void onOpened(CameraDevice cameraDevice) {
        mCameraDevice = cameraDevice;
        createCameraPreviewSession();
    }
    ...

};

//create a new CameraCaptureSession for camera preview
private void createCameraPreviewSession() {
   try {
       SurfaceTexture texture = mTextureView.getSurfaceTexture();
       assert texture != null;

       // We configure the size of default buffer to be the size of camera preview we want.
        texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());

        // This is the output Surface we need to start preview.
        Surface surface = new Surface(texture);

        // We set up a CaptureRequest.Builder with the output Surface.
        mPreviewRequestBuilder
                = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        mPreviewRequestBuilder.addTarget(surface);

        mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()), new CameraCaptureSession.StateCallback() {
             @Override
             public void onConfigured(CameraCaptureSession cameraCaptureSession) {
                 mCaptureSession = cameraCaptureSesssion;
                 updatePreview();
             }

             @Override
             public void onConfiguredFailed(CameraCaptureSession cameraCaptureSession) {
             }
          }, null);
     } catch (CameraAccessException e) {
     }
 }

此来源是成功的摄像机预览和在三星银河8设备上的摄像机捕获。

但是树莓派3无法打开相机预览并捕获失败。

树莓派始终在createCameraPreviewSession上调用onConfigureFailed

日志

 W/CameraDevice-JV-0: Stream configuration failed due to: endConfigure:372: Camera 0: Unsupported set of inputs/outputs provided
 E/CameraCaptureSession: Session 0: Failed to create capture session; configuration failed

所以我更改了这部分

mCameraDevice.createCaptureSession(Arrays.asList(surface, mImageReader.getSurface()), new CameraCaptureSession.StateCallback() {

->更改

mCameraDevice.createCaptureSession(Arrays.asList(surface), new CameraCaptureSession.StateCallback() {

此来源是在树莓派上打开的相机。但不能捕获工作。

如何在树莓派3的Android设备上捕获相机预览?

如果您知道,请告诉我

谢谢。

0 个答案:

没有答案