Java Code Examples for android.hardware.camera2.CameraCharacteristics#LENS_FACING_FRONT
The following examples show how to use
android.hardware.camera2.CameraCharacteristics#LENS_FACING_FRONT .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CameraFragment.java From io2015-codelabs with Apache License 2.0 | 6 votes |
/** * Translates from the device orientation given by the Android sensor APIs to the * orientation for a JPEG image. */ private int getJpegOrientation(CameraCharacteristics c, int deviceOrientation) { Log.d(TAG, "getJpegOrientation: "); if (deviceOrientation == android.view.OrientationEventListener.ORIENTATION_UNKNOWN) return 0; int sensorOrientation = c.get(CameraCharacteristics.SENSOR_ORIENTATION); // Round device orientation to a multiple of 90 deviceOrientation = (deviceOrientation + 45) / 90 * 90; // Reverse device orientation for front-facing cameras boolean facingFront = c.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT; if (facingFront) deviceOrientation = -deviceOrientation; // Calculate desired JPEG orientation relative to camera orientation to make // the image upright relative to the device orientation int jpegOrientation = (sensorOrientation + deviceOrientation + 360) % 360; return jpegOrientation; }
Example 2
Source File: CameraFragment.java From io2015-codelabs with Apache License 2.0 | 6 votes |
/** * Translates from the device orientation given by the Android sensor APIs to the * orientation for a JPEG image. */ private int getJpegOrientation(CameraCharacteristics c, int deviceOrientation) { Log.d(TAG, "getJpegOrientation: "); if (deviceOrientation == android.view.OrientationEventListener.ORIENTATION_UNKNOWN) return 0; int sensorOrientation = c.get(CameraCharacteristics.SENSOR_ORIENTATION); // Round device orientation to a multiple of 90 deviceOrientation = (deviceOrientation + 45) / 90 * 90; // Reverse device orientation for front-facing cameras boolean facingFront = c.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT; if (facingFront) deviceOrientation = -deviceOrientation; // Calculate desired JPEG orientation relative to camera orientation to make // the image upright relative to the device orientation int jpegOrientation = (sensorOrientation + deviceOrientation + 360) % 360; return jpegOrientation; }
Example 3
Source File: Camera2RawFragment.java From android-Camera2Raw with Apache License 2.0 | 6 votes |
/** * Rotation need to transform from the camera sensor orientation to the device's current * orientation. * * @param c the {@link CameraCharacteristics} to query for the camera sensor * orientation. * @param deviceOrientation the current device orientation relative to the native device * orientation. * @return the total rotation from the sensor orientation to the current device orientation. */ private static int sensorToDeviceRotation(CameraCharacteristics c, int deviceOrientation) { int sensorOrientation = c.get(CameraCharacteristics.SENSOR_ORIENTATION); // Get device orientation in degrees deviceOrientation = ORIENTATIONS.get(deviceOrientation); // Reverse device orientation for front-facing cameras if (c.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT) { deviceOrientation = -deviceOrientation; } // Calculate desired JPEG orientation relative to camera orientation to make // the image upright relative to the device orientation return (sensorOrientation - deviceOrientation + 360) % 360; }
Example 4
Source File: CustomVideoCapturerCamera2.java From opentok-android-sdk-samples with MIT License | 5 votes |
public CameraInfoCache(CameraCharacteristics info) { info = info; /* its actually faster to cache these results then to always look them up, and since they are queried every frame... */ frontFacing = info.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics.LENS_FACING_FRONT; sensorOrientation = info.get(CameraCharacteristics.SENSOR_ORIENTATION).intValue(); }
Example 5
Source File: BaseCameraActivity.java From fritz-examples with MIT License | 5 votes |
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); Log.i(TAG, "Camera API lv2?: " + useCamera2API); return cameraId; } } catch (CameraAccessException e) { Log.e(TAG, "Not allowed to access camera: " + e); } return null; }
Example 6
Source File: CameraFragment.java From io2015-codelabs with Apache License 2.0 | 5 votes |
private boolean shouldUseCamera(int lensFacing) { Log.d(TAG, "shouldUseCamera: "); if (getArguments().getBoolean(EXTRA_USE_FRONT_FACING_CAMERA)) { return lensFacing == CameraCharacteristics.LENS_FACING_FRONT; } else { return lensFacing == CameraCharacteristics.LENS_FACING_BACK; } }
Example 7
Source File: BaseCameraActivity.java From fritz-examples with MIT License | 5 votes |
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); Log.i(TAG, "Camera API lv2?: " + useCamera2API); return cameraId; } } catch (CameraAccessException e) { Log.e(TAG, "Not allowed to access camera: " + e); } return null; }
Example 8
Source File: BaseCameraActivity.java From fritz-examples with MIT License | 5 votes |
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); Log.i(TAG, "Camera API lv2?: " + useCamera2API); return cameraId; } } catch (CameraAccessException e) { Log.e(TAG, "Not allowed to access camera: " + e); } return null; }
Example 9
Source File: Camera2Manager.java From phoenix with Apache License 2.0 | 5 votes |
@Override public void initializeCameraManager(CameraConfigProvider cameraConfigProvider, Context context) { super.initializeCameraManager(cameraConfigProvider, context); final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); final Display display = windowManager.getDefaultDisplay(); final Point size = new Point(); display.getSize(size); mWindowSize = new Size(size.x, size.y); mCameraManager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); try { final String[] ids = mCameraManager.getCameraIdList(); mNumberOfCameras = ids.length; for (String id : ids) { final CameraCharacteristics characteristics = mCameraManager.getCameraCharacteristics(id); final int orientation = characteristics.get(CameraCharacteristics.LENS_FACING); if (orientation == CameraCharacteristics.LENS_FACING_FRONT) { mFaceFrontCameraId = id; mFaceFrontCameraOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); mFrontCameraCharacteristics = characteristics; } else { mFaceBackCameraId = id; mFaceBackCameraOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); mBackCameraCharacteristics = characteristics; } } } catch (Exception e) { Log.e(TAG, "Error during camera initialize"); } }
Example 10
Source File: BaseCameraActivity.java From fritz-examples with MIT License | 5 votes |
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); Log.i(TAG, "Camera API lv2?: " + useCamera2API); return cameraId; } } catch (CameraAccessException e) { Log.e(TAG, "Not allowed to access camera: " + e); } return null; }
Example 11
Source File: BaseCameraActivity.java From fritz-examples with MIT License | 5 votes |
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); Log.i(TAG, "Camera API lv2?: " + useCamera2API); return cameraId; } } catch (CameraAccessException e) { Log.e(TAG, "Not allowed to access camera: " + e); } return null; }
Example 12
Source File: RotationHelper.java From FastBarcodeScanner with Apache License 2.0 | 5 votes |
private static boolean isFrontFacing(Activity activity, String cameraId) { try { CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); int facing = characteristics.get(CameraCharacteristics.LENS_FACING); return facing == CameraCharacteristics.LENS_FACING_FRONT; } catch (android.hardware.camera2.CameraAccessException e) { Log.e(TAG, "CameraAccessException"); throw new UnsupportedOperationException("CameraAccessException"); } }
Example 13
Source File: Camera2Controller.java From pixelvisualcorecamera with Apache License 2.0 | 5 votes |
/** Fetches the camera characteristics for the current camera. */ private boolean initCameraCharacteristics() { CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); try { // Extract characteristics for the current camera. CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); activeArraySize = characteristics.get(SENSOR_INFO_ACTIVE_ARRAY_SIZE); maxDigitalZoom = characteristics.get(SCALER_AVAILABLE_MAX_DIGITAL_ZOOM); // Require a stream configuration map. Don't know why there wouldn't be one. StreamConfigurationMap map = characteristics.get( CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); if (map == null) { throw new CameraAccessException(CameraAccessException.CAMERA_ERROR); } int facing = characteristics.get(CameraCharacteristics.LENS_FACING); boolean lensFacingFront = (facing == CameraCharacteristics.LENS_FACING_FRONT); int sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); outputOrientation = Orientation.getOutputOrientation( lensFacingFront, displayRotationCode, sensorOrientation); return true; } catch (CameraAccessException | NullPointerException e) { // NPE's can be thrown when unboxing some of the characteristics. This should never happen // on Pixel{1,2}. Log.w(TAG, "Failed to inspect camera characteristics", e); } return false; }
Example 14
Source File: Camera2Proxy.java From CameraDemo with Apache License 2.0 | 5 votes |
private int getJpegOrientation(int deviceOrientation) { if (deviceOrientation == android.view.OrientationEventListener.ORIENTATION_UNKNOWN) return 0; int sensorOrientation = mCameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); // Round device orientation to a multiple of 90 deviceOrientation = (deviceOrientation + 45) / 90 * 90; // Reverse device orientation for front-facing cameras boolean facingFront = mCameraCharacteristics.get(CameraCharacteristics.LENS_FACING) == CameraCharacteristics .LENS_FACING_FRONT; if (facingFront) deviceOrientation = -deviceOrientation; // Calculate desired JPEG orientation relative to camera orientation to make // the image upright relative to the device orientation int jpegOrientation = (sensorOrientation + deviceOrientation + 360) % 360; Log.d(TAG, "jpegOrientation: " + jpegOrientation); return jpegOrientation; }
Example 15
Source File: AndroidSensorsDriver.java From sensorhub with Mozilla Public License 2.0 | 5 votes |
@SuppressWarnings("deprecation") protected void createCameraOutputs(Context androidContext) throws SensorException { if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.LOLLIPOP+2) { CameraManager cameraManager = (CameraManager)androidContext.getSystemService(Context.CAMERA_SERVICE); try { String[] camIds = cameraManager.getCameraIdList(); for (String cameraId: camIds) { log.debug("Detected camera " + cameraId); int camDir = cameraManager.getCameraCharacteristics(cameraId).get(CameraCharacteristics.LENS_FACING); if ( (camDir == CameraCharacteristics.LENS_FACING_BACK && config.activateBackCamera) || (camDir == CameraCharacteristics.LENS_FACING_FRONT && config.activateFrontCamera)) { useCamera2(new AndroidCamera2Output(this, cameraManager, cameraId, config.camPreviewSurfaceHolder), cameraId); } } } catch (CameraAccessException e) { throw new SensorException("Error while accessing cameras", e); } } else { for (int cameraId = 0; cameraId < android.hardware.Camera.getNumberOfCameras(); cameraId++) { android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); android.hardware.Camera.getCameraInfo(cameraId, info); if ( (info.facing == android.hardware.Camera.CameraInfo.CAMERA_FACING_BACK && config.activateBackCamera) || (info.facing == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT && config.activateFrontCamera)) { useCamera(new AndroidCameraOutput(this, cameraId, config.camPreviewSurfaceHolder), cameraId); } } } }
Example 16
Source File: Camera2WrapperManager.java From DeviceConnect-Android with MIT License | 5 votes |
/** * サポートしているカメラのタイプ一覧を取得します. * * @param context コンテキスト * @return カメラのタイプ一覧 */ public static List<Integer> supportCameraIds(Context context) { CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); if (manager == null) { throw new UnsupportedOperationException("Not supported a Camera."); } List<Integer> list = new ArrayList<>(); try { for (String cameraId : manager.getCameraIdList()) { CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING); if (facing != null) { switch (facing) { case CameraCharacteristics.LENS_FACING_BACK: list.add(CameraCharacteristics.LENS_FACING_BACK); break; case CameraCharacteristics.LENS_FACING_FRONT: list.add(CameraCharacteristics.LENS_FACING_FRONT); break; default: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { list.add(CameraCharacteristics.LENS_FACING_EXTERNAL); } break; } } } } catch (CameraAccessException e) { // ignore. } return list; }
Example 17
Source File: CameraInfo.java From MobileInfo with Apache License 2.0 | 5 votes |
private static String getFacing(Integer facing) { if (facing == null) { return UNKNOWN; } switch (facing) { case CameraCharacteristics.LENS_FACING_FRONT: return "FRONT"; case CameraCharacteristics.LENS_FACING_BACK: return "BACK"; case CameraCharacteristics.LENS_FACING_EXTERNAL: return "EXTERNAL"; default: return UNKNOWN + "-" + facing; } }
Example 18
Source File: Camera2Utils.java From libcommon with Apache License 2.0 | 4 votes |
/** * 指定した条件に合うカメラを探す * @param manager * @param preferedFace カメラの方向、対応するカメラがなければ異なるfaceのカメラが選択される * @return * @throws CameraAccessException */ public static CameraConst.CameraInfo findCamera( @NonNull final CameraManager manager, @CameraConst.FaceType final int preferedFace) throws CameraAccessException { if (DEBUG) Log.v(TAG, "findCamera:preferedFace=" + preferedFace); CameraConst.CameraInfo info = null; int targetFace; final String[] cameraIds = manager.getCameraIdList(); if ((cameraIds != null) && (cameraIds.length > 0)) { final int face = (preferedFace == FACING_BACK ? CameraCharacteristics.LENS_FACING_BACK : CameraCharacteristics.LENS_FACING_FRONT); boolean triedAllCameras = false; targetFace = face; String cameraId = null; int orientation = 0; cameraLoop: for (; !triedAllCameras ;) { for (final String id: cameraIds) { final CameraCharacteristics characteristics = manager.getCameraCharacteristics(id); if (characteristics.get(CameraCharacteristics.LENS_FACING) == targetFace) { final StreamConfigurationMap map = characteristics.get( CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); cameraId = id; orientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); break cameraLoop; } } if ((cameraId == null) && (targetFace == face)) { targetFace = (face == CameraCharacteristics.LENS_FACING_BACK ? CameraCharacteristics.LENS_FACING_FRONT : CameraCharacteristics.LENS_FACING_BACK); } else { triedAllCameras = true; } } if (!TextUtils.isEmpty(cameraId)) { info = new CameraConst.CameraInfo(cameraId, face, orientation, CameraConst.DEFAULT_WIDTH, CameraConst.DEFAULT_HEIGHT); } } return info; }
Example 19
Source File: CameraUtils.java From SimpleSmsRemote with MIT License | 4 votes |
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public static MyCameraInfo CreateFromCameraCharacteristics(String cameraId, CameraCharacteristics characteristics) { StreamConfigurationMap configMap = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); Size[] outputSizes = configMap.getOutputSizes(ImageFormat.JPEG); List<int[]> outputResolutions = new ArrayList<>(); for (Size outputSize : outputSizes) { outputResolutions.add(new int[]{outputSize.getWidth(), outputSize.getHeight()}); } MyCameraInfo cameraInfo = new MyCameraInfo(cameraId, outputResolutions); // supported functionality depends on the supported hardware level switch (characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL)) { case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_3: case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL: case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED: cameraInfo.setAutofocusSupport(true); case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY: // only supports camera 1 api features break; } int[] ints = characteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_MODES); if (characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE)) cameraInfo.setFlashlightSupport(true); Integer lensFacing = characteristics.get(CameraCharacteristics.LENS_FACING); if (lensFacing != null) { if (lensFacing == CameraCharacteristics.LENS_FACING_BACK) cameraInfo.setLensFacing(LensFacing.BACK); else if (lensFacing == CameraCharacteristics.LENS_FACING_FRONT) cameraInfo.setLensFacing(LensFacing.FRONT); else if (lensFacing == CameraCharacteristics.LENS_FACING_EXTERNAL) cameraInfo.setLensFacing(LensFacing.EXTERNAL); } /* jpeg is always supported boolean isSupported = configMap.isOutputSupportedFor(0x100); */ //TODO add more info return cameraInfo; }
Example 20
Source File: OBCameraManager.java From GLEXP-Team-onebillion with Apache License 2.0 | 4 votes |
private int getCameraCharacteristic(int cameraLoc) { return cameraLoc == CAMERA_BACK ? CameraCharacteristics.LENS_FACING_BACK : CameraCharacteristics.LENS_FACING_FRONT; }