将一个摄影机提要显示在两个TextureViews上

时间:2019-01-08 10:59:51

标签: java android tensorflow

TensorFlow Android Demo使用cameraConnectionFragment DetectorActivity将PreviewRequest注册到适当的构建器上。据我所知,这里已经注册了TextureView。

如何在那里注册第二个视图?

我已经找到了一些线程和指南,但是我只是经验不足,无法将他们的解决方案转移到像tensorflow Demo这样的大型项目中。

  • 我尝试在FirstView.SurfaceTextureListener onSurfaceTextureUpdated方法期间设置第二个View(结果:绘制了元素,但表面是绿色的)

  • 我尝试为第二个View注册第二个SurfaceTextureListener(结果:未绘制任何视图)

  • 我尝试在createCameraPreviewSession()方法中将textureView1的SurfaceTexture设置为textureView2的SurfaceTexture(结果:GLConsumer已附加到新SurfaceTexture的上下文中)

  • 我尝试了(as said here)从TextureView分离GL上下文。 (结果:即使直接将其绑定到另一个TextureView,我也会得到类似的视图:未附加视图)

  • 我试图将第二个TextureView的Target()添加到PreviewRequestBuilder(这是一个Capturerequest.Builder)

我有20个相关的课程,在经过两周的深入分析之后,我仍然不完全知道哪个课程确实在做什么,所以我只说明第二个View可能出现的位置:

CameraConnectionFragment.java的LOC 522

cameraDevice.createCaptureSession(
  Arrays.asList(textureViewSurface, previewReader.getSurface()),
    new CameraCaptureSession.StateCallback() {

      @Override
      public void onConfigured(final CameraCaptureSession cameraCaptureSession) {
          // When the session is ready, we start displaying the preview.
          captureSession = cameraCaptureSession;
          try {
            // Auto focus should be continuous for camera preview.
            previewRequestBuilder.set(
                CaptureRequest.CONTROL_AF_MODE,
                CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
            // Flash is automatically enabled when necessary.
            previewRequestBuilder.set(
                CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);

            // Finally, we start displaying the camera preview.
            previewRequest = previewRequestBuilder.build();
            captureSession.setRepeatingRequest(
                previewRequest, captureCallback, backgroundHandler);

          } catch (final CameraAccessException e) {
            LOGGER.e(e, "Exception!");
          }
        }

        @Override
        public void onConfigureFailed(final CameraCaptureSession cameraCaptureSession) {
          showToast("Failed");
        }
      },
      null);
} catch (final CameraAccessException e) {
  LOGGER.e(e, "Exception!");
}

CameraActivity.java的LOC 154

@Override
public void onImageAvailable(final ImageReader reader) {
  //We need wait until we have some size from onPreviewSizeChosen
  if (previewWidth == 0 || previewHeight == 0) {
    return;
  }
  if (rgbBytes == null) {
    rgbBytes = new int[previewWidth * previewHeight];
  }
  try {
    final Image image = reader.acquireLatestImage();

    if (image == null) {
      return;
    }

    if (isProcessingFrame) {
      image.close();
      return;
    }
    isProcessingFrame = true;
    Trace.beginSection("imageAvailable");
    final Plane[] planes = image.getPlanes();
    fillBytes(planes, yuvBytes);
    yRowStride = planes[0].getRowStride();
    final int uvRowStride = planes[1].getRowStride();
    final int uvPixelStride = planes[1].getPixelStride();

    imageConverter =
        new Runnable() {
          @Override
          public void run() {
            ImageUtils.convertYUV420ToARGB8888(
                yuvBytes[0],
                yuvBytes[1],
                yuvBytes[2],
                previewWidth,
                previewHeight,
                yRowStride,
                uvRowStride,
                uvPixelStride,
                rgbBytes);
          }
        };

我尝试在同一屏幕上同时显示2个相机供稿预览,就像一个类似VR的视图一样。它只是将一个TextureView的输出复制到另一个上,但是一旦我干扰了任何部分的进度,就一无所有了

0 个答案:

没有答案