【问题标题】:How to use front camera in tensorflow object detection api on android demo如何在 android demo 上的 tensorflow 对象检测 api 中使用前置摄像头
【发布时间】:2019-06-24 15:55:47
【问题描述】:

我想在tensorflow的android演示中使用前置摄像头,我应该在代码中更改什么,因为我对android不太熟悉。

这是我更改的代码,但没有解决问题

private String chooseCamera() {
    final CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
    try {
      for (final String cameraId : manager.getCameraIdList()) {
        final CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);

        // We don't use a front facing camera in this sample.
        final Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
        if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
          continue;
        }

        final StreamConfigurationMap map =
            characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);

        if (map == null) {
          continue;
        }

        // Fallback to camera1 API for internal cameras that don't have full support.
        // This should help with legacy situations where using the camera2 API causes
        // distorted or otherwise broken previews.
        useCamera2API = (facing == CameraCharacteristics.LENS_FACING_EXTERNAL)
            || isHardwareLevelSupported(characteristics, 
                                        CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL);
        LOGGER.i("Camera API lv2?: %s", useCamera2API);
        return cameraId;
      }
    } catch (CameraAccessException e) {
      LOGGER.e(e, "Not allowed to access camera");
    }

    return null;
  }

原来是 Lens_Facing_Back ,我做了 Lens_Facing_Front

【问题讨论】:

  • 到目前为止你尝试了什么?
  • 再次查看帖子,我添加了到目前为止我所做的事情。
  • 你设置了不改变相机选择的代码,和the tensorflow example一模一样。

标签: android tensorflow android-camera object-detection


【解决方案1】:

想通了。在legacyCameraConnectionFragment 中有一个名为getCameraID() 的函数。打开它的实现和改变 CAMERA_FACING_BACKCAMERA_FACING_FRONT

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多