如何在Android Demo上的Tensorflow对象检测API中使用前置摄像头

时间:2019-06-24 15:55:47

标签: android tensorflow android-camera object-detection

我想在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

1 个答案:

答案 0 :(得分:0)

弄清楚了。 getCameraID()中有一个名为legacyCameraConnectionFragment的函数。打开实施并进行更改 CAMERA_FACING_BACKCAMERA_FACING_FRONT