android.hardware.camera2.CameraCharacteristics Java Examples

The following examples show how to use android.hardware.camera2.CameraCharacteristics. 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: VIACamera.java    From VIA-AI with MIT License 8 votes vote down vote up
@TargetApi(21)
public static Size[] querySupportResolution(Context context, int index) {
    CameraManager manager =
            (CameraManager)context.getSystemService(CAMERA_SERVICE);
    try {
        CameraCharacteristics chars
                = manager.getCameraCharacteristics(index+"");

        StreamConfigurationMap configurationMap = chars.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);

        return configurationMap.getOutputSizes(ImageFormat.YUV_420_888);

    } catch(CameraAccessException e){
        e.printStackTrace();
    }
    return null;
}
 
Example #2
Source File: CameraMetadataNative.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private <T> Integer getMaxRegions(Key<T> key) {
    final int AE = 0;
    final int AWB = 1;
    final int AF = 2;

    // The order of the elements is: (AE, AWB, AF)
    int[] maxRegions = getBase(CameraCharacteristics.CONTROL_MAX_REGIONS);

    if (maxRegions == null) {
        return null;
    }

    if (key.equals(CameraCharacteristics.CONTROL_MAX_REGIONS_AE)) {
        return maxRegions[AE];
    } else if (key.equals(CameraCharacteristics.CONTROL_MAX_REGIONS_AWB)) {
        return maxRegions[AWB];
    } else if (key.equals(CameraCharacteristics.CONTROL_MAX_REGIONS_AF)) {
        return maxRegions[AF];
    } else {
        throw new AssertionError("Invalid key " + key);
    }
}
 
Example #3
Source File: Camera2Helper.java    From CameraCompat with MIT License 6 votes vote down vote up
@Override
protected List<PreviewSize> getSupportedSize() {
    try {
        CameraCharacteristics characteristics = mCameraManager.getCameraCharacteristics(
                getCurrentCameraId());
        StreamConfigurationMap map =
                characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
        if (map == null) {
            return Collections.singletonList(new PreviewSize(mPreviewWidth, mPreviewHeight));
        }
        Size[] supportedSize = map.getOutputSizes(SurfaceTexture.class);
        if (supportedSize == null || supportedSize.length == 0) {
            return Collections.singletonList(new PreviewSize(mPreviewWidth, mPreviewHeight));
        }
        List<PreviewSize> results = new ArrayList<>();
        for (Size size : supportedSize) {
            results.add(new PreviewSize(size.getWidth(), size.getHeight()));
        }
        return results;
    } catch (CameraAccessException e) {
        throw new CameraAccessError();
    }
}
 
Example #4
Source File: Camera2OneCameraManagerImpl.java    From Camera2 with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the ID of the first camera facing the given direction.
 */
private String findFirstCameraIdFacing(int facing)
{
    try
    {
        String[] cameraIds = mCameraManager.getCameraIdList();
        for (String cameraId : cameraIds)
        {
            CameraCharacteristics characteristics = mCameraManager
                    .getCameraCharacteristics(cameraId);
            if (characteristics.get(CameraCharacteristics.LENS_FACING) == facing)
            {
                return cameraId;
            }
        }
    } catch (CameraAccessException ex)
    {
        Log.w(TAG, "Unable to get camera ID", ex);
    }
    return null;
}
 
Example #5
Source File: Camera2Source.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 6 votes vote down vote up
public boolean isCamera2Native() {
    try {
        if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            return false;
        }
        manager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
        mCameraId = manager.getCameraIdList()[mFacing];
        CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraId);
        //CHECK CAMERA HARDWARE LEVEL. IF CAMERA2 IS NOT NATIVELY SUPPORTED, GO BACK TO CAMERA1
        Integer deviceLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
        return deviceLevel != null && (deviceLevel != CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY);
    } catch (CameraAccessException ex) {
        return false;
    } catch (NullPointerException e) {
        return false;
    } catch (ArrayIndexOutOfBoundsException ez) {
        return false;
    }
}
 
Example #6
Source File: CameraXUtil.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@RequiresApi(21)
public static int getLowestSupportedHardwareLevel(@NonNull Context context) {
  @SuppressLint("RestrictedApi") CameraManager cameraManager = CameraManagerCompat.from(context).unwrap();

  try {
    int supported = maxHardwareLevel();

    for (String cameraId : cameraManager.getCameraIdList()) {
      CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
      Integer               hwLevel         = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);

      if (hwLevel == null || hwLevel == CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY) {
        return CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY;
      }

      supported = smallerHardwareLevel(supported, hwLevel);
    }

    return supported;
  } catch (CameraAccessException e) {
    Log.w(TAG, "Failed to enumerate cameras", e);

    return CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY;
  }
}
 
Example #7
Source File: CustomVideoCapturerCamera2.java    From opentok-android-sdk-samples with MIT License 6 votes vote down vote up
private Range<Integer> selectCameraFpsRange(String camId, final int fps) throws CameraAccessException {
    for (String id : cameraManager.getCameraIdList()) {
        if (id.equals(camId)) {
            CameraCharacteristics info = cameraManager.getCameraCharacteristics(id);
            List<Range<Integer>> fpsLst = new ArrayList<>();
            Collections.addAll(fpsLst,
                    info.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES));
            /* sort list by error from desired fps *
             * Android seems to do a better job at color correction/avoid 'dark frames' issue by
             * selecting camera settings with the smallest lower bound on allowed frame rate
             * range. */
            return Collections.min(fpsLst, new Comparator<Range<Integer>>() {
                @Override
                public int compare(Range<Integer> lhs, Range<Integer> rhs) {
                    return calcError(lhs) - calcError(rhs);
                }

                private int calcError(Range<Integer> val) {
                    return val.getLower() + Math.abs(val.getUpper() - fps);
                }
            });
        }
    }
    return null;
}
 
Example #8
Source File: Camera2.java    From TikTok with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the internal state of auto-focus to {@link #mAutoFocus}.
 */
void updateAutoFocus() {
    if (mAutoFocus) {
        int[] modes = mCameraCharacteristics.get(
                CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES);
        // Auto focus is not supported
        if (modes == null || modes.length == 0 ||
                (modes.length == 1 && modes[0] == CameraCharacteristics.CONTROL_AF_MODE_OFF)) {
            mAutoFocus = false;
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                    CaptureRequest.CONTROL_AF_MODE_OFF);
        } else {
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                    CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        }
    } else {
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                CaptureRequest.CONTROL_AF_MODE_OFF);
    }
}
 
Example #9
Source File: TorchService.java    From GravityBox with Apache License 2.0 6 votes vote down vote up
private String getCameraId() {
    if (mCameraId == null) {
        try {
            String[] ids = mCameraManager.getCameraIdList();
            for (String id : ids) {
                CameraCharacteristics c = mCameraManager.getCameraCharacteristics(id);
                Boolean flashAvailable = c.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
                Integer lensFacing = c.get(CameraCharacteristics.LENS_FACING);
                if (flashAvailable != null && flashAvailable && lensFacing != null &&
                        lensFacing == CameraCharacteristics.LENS_FACING_BACK) {
                    mCameraId = id;
                }
            }
            if (DEBUG) Log.d(TAG, "getCameraId: " + mCameraId);
        } catch (Exception e) {
            e.printStackTrace();
            mTorchStatus = TORCH_STATUS_ERROR;
            broadcastStatus();
            stopSelf();
        }
    }
    return mCameraId;
}
 
Example #10
Source File: Camera2Helper.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
/**
 * カメラID に対応したカメラデバイスがサポートしている写真サイズのリストを取得します.
 *
 * @param cameraManager カメラマネージャ
 * @param cameraId カメラID
 * @return サポートしている写真サイズのリスト
 */
@NonNull
static List<Size> getSupportedPictureSizes(final CameraManager cameraManager, final String cameraId) {
    List<Size> pictureSizes = new ArrayList<>();
    try {
        CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
        StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
        if(map != null) {
            pictureSizes = Arrays.asList(map.getOutputSizes(ImageFormat.JPEG));
            Collections.sort(pictureSizes, SizeComparator);
        }
    } catch (CameraAccessException e) {
        // ignore.
    }
    return pictureSizes;
}
 
Example #11
Source File: MainActivity.java    From Android-9-Development-Cookbook with MIT License 6 votes vote down vote up
private String getCameraId() {
    try {
        String[] ids = mCameraManager.getCameraIdList();
        for (String id : ids) {
            CameraCharacteristics c = mCameraManager.getCameraCharacteristics(id);
            Boolean flashAvailable = c.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
            Integer facingDirection = c.get(CameraCharacteristics.LENS_FACING);
            if (flashAvailable != null
                    && flashAvailable
                    && facingDirection != null
                    && facingDirection == CameraCharacteristics.LENS_FACING_BACK) {
                return id;
            }
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #12
Source File: CameraInfo.java    From MobileInfo with Apache License 2.0 6 votes vote down vote up
private static String getLevel(Integer level) {
    if (level == null) {
        return UNKNOWN;
    }
    switch (level) {
        case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY:
            return "LEGACY";
        case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_3:
            return "LEVEL_3";
        case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_EXTERNAL:
            return "EXTERNAL";
        case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_FULL:
            return "FULL";
        case CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED:
            return "LIMITED";
        default:
            return UNKNOWN + "-" + level;
    }
}
 
Example #13
Source File: Camera2Helper.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
/**
 * カメラID に対応したカメラデバイスがサポートしているプレビューサイズのリストを取得します.
 *
 * @param cameraManager カメラマネージャ
 * @param cameraId カメラID
 * @return サポートしているプレビューサイズのリスト
 */
@NonNull
static List<Size> getSupportedPreviewSizes(final CameraManager cameraManager, final String cameraId) {
    List<Size> previewSizes = new ArrayList<>();
    try {
        CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
        StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
        if (map != null) {
            previewSizes = Arrays.asList(map.getOutputSizes(SurfaceTexture.class));
            Collections.sort(previewSizes, SizeComparator);
        }
    } catch (CameraAccessException e) {
        // ignore.
    }
    return previewSizes;
}
 
Example #14
Source File: CameraImplV2.java    From habpanelviewer with GNU General Public License v3.0 6 votes vote down vote up
private void findCameraFacing(int direction) throws CameraAccessException {
    for (String camId : mCamManager.getCameraIdList()) {
        CameraCharacteristics characteristics = mCamManager.getCameraCharacteristics(camId);
        Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);

        if (facing != null && facing == direction) {
            mCameraId = camId;

            Integer orientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
            if (orientation != null) {
                mCameraOrientation = orientation;
            }

            Log.v(TAG, "found " + (direction == CameraCharacteristics.LENS_FACING_FRONT ? "front" : "back")
                    + "-facing camera with id " + camId + " and orientation " + mCameraOrientation);
        }
    }
}
 
Example #15
Source File: Camera2ApiManager.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 6 votes vote down vote up
@SuppressLint("MissingPermission")
public void openCameraId(Integer cameraId) {
  this.cameraId = cameraId;
  if (prepared) {
    HandlerThread cameraHandlerThread = new HandlerThread(TAG + " Id = " + cameraId);
    cameraHandlerThread.start();
    cameraHandler = new Handler(cameraHandlerThread.getLooper());
    try {
      cameraManager.openCamera(cameraId.toString(), this, cameraHandler);
      CameraCharacteristics cameraCharacteristics =
          cameraManager.getCameraCharacteristics(Integer.toString(cameraId));
      running = true;
      isFrontCamera =
          (LENS_FACING_FRONT == cameraCharacteristics.get(CameraCharacteristics.LENS_FACING));
      if (cameraCallbacks != null) {
        cameraCallbacks.onCameraChanged(isFrontCamera);
      }
    } catch (CameraAccessException | SecurityException e) {
      Log.e(TAG, "Error", e);
    }
  } else {
    Log.e(TAG, "Camera2ApiManager need be prepared, Camera2ApiManager not enabled");
  }
}
 
Example #16
Source File: CameraMetadataNative.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private boolean setAvailableFormats(int[] value) {
    int[] availableFormat = value;
    if (value == null) {
        // Let setBase() to handle the null value case.
        return false;
    }

    int[] newValues = new int[availableFormat.length];
    for (int i = 0; i < availableFormat.length; i++) {
        newValues[i] = availableFormat[i];
        if (availableFormat[i] == ImageFormat.JPEG) {
            newValues[i] = NATIVE_JPEG_FORMAT;
        }
    }

    setBase(CameraCharacteristics.SCALER_AVAILABLE_FORMATS, newValues);
    return true;
}
 
Example #17
Source File: Camera2.java    From cameraview with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the internal state of auto-focus to {@link #mAutoFocus}.
 */
void updateAutoFocus() {
    if (mAutoFocus) {
        int[] modes = mCameraCharacteristics.get(
                CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES);
        // Auto focus is not supported
        if (modes == null || modes.length == 0 ||
                (modes.length == 1 && modes[0] == CameraCharacteristics.CONTROL_AF_MODE_OFF)) {
            mAutoFocus = false;
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                    CaptureRequest.CONTROL_AF_MODE_OFF);
        } else {
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                    CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        }
    } else {
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                CaptureRequest.CONTROL_AF_MODE_OFF);
    }
}
 
Example #18
Source File: Camera2Proxy.java    From CameraDemo with Apache License 2.0 6 votes vote down vote up
private int getRotation() {
    int displayRotation = mActivity.getWindowManager().getDefaultDisplay().getRotation();
    switch (displayRotation) {
        case Surface.ROTATION_0:
            displayRotation = 90;
            break;
        case Surface.ROTATION_90:
            displayRotation = 0;
            break;
        case Surface.ROTATION_180:
            displayRotation = 270;
            break;
        case Surface.ROTATION_270:
            displayRotation = 180;
            break;
    }
    int sensorOrientation = mCameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
    mDisplayRotate = (displayRotation + sensorOrientation + 270) % 360;
    return mDisplayRotate;
}
 
Example #19
Source File: CameraMetadataNative.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private LensShadingMap getLensShadingMap() {
    float[] lsmArray = getBase(CaptureResult.STATISTICS_LENS_SHADING_MAP);
    Size s = get(CameraCharacteristics.LENS_INFO_SHADING_MAP_SIZE);

    // Do not warn if lsmArray is null while s is not. This is valid.
    if (lsmArray == null) {
        return null;
    }

    if (s == null) {
        Log.w(TAG, "getLensShadingMap - Lens shading map size was null.");
        return null;
    }

    LensShadingMap map = new LensShadingMap(lsmArray, s.getHeight(), s.getWidth());
    return map;
}
 
Example #20
Source File: Camera2.java    From TikTok with Apache License 2.0 5 votes vote down vote up
/**
 * <p>Collects some information from {@link #mCameraCharacteristics}.</p>
 * <p>This rewrites {@link #mPreviewSizes}, {@link #mPictureSizes}, and optionally,
 * {@link #mAspectRatio}.</p>
 */
private void collectCameraInfo() {
    StreamConfigurationMap map = mCameraCharacteristics.get(
            CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
    if (map == null) {
        throw new IllegalStateException("Failed to get configuration map: " + mCameraId);
    }
    mPreviewSizes.clear();
    for (android.util.Size size : map.getOutputSizes(mPreview.getOutputClass())) {
        int width = size.getWidth();
        int height = size.getHeight();
        if (width <= MAX_PREVIEW_WIDTH && height <= MAX_PREVIEW_HEIGHT) {
            mPreviewSizes.add(new Size(width, height));
        }
    }
    mPictureSizes.clear();
    collectPictureSizes(mPictureSizes, map);
    for (AspectRatio ratio : mPreviewSizes.ratios()) {
        if (!mPictureSizes.ratios().contains(ratio)) {
            mPreviewSizes.remove(ratio);
        }
    }

    if (!mPreviewSizes.ratios().contains(mAspectRatio)) {
        mAspectRatio = mPreviewSizes.ratios().iterator().next();
    }
}
 
Example #21
Source File: Camera2OneCameraManagerImpl.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the ID of the first front-facing camera.
 */
private String findFirstFrontCameraId()
{
    Log.d(TAG, "Getting First FRONT Camera");
    String cameraId = findFirstCameraIdFacing(CameraCharacteristics.LENS_FACING_FRONT);
    if (cameraId == null)
    {
        Log.w(TAG, "No front-facing camera found.");
    }
    return cameraId;
}
 
Example #22
Source File: Camera2Controller.java    From pixelvisualcorecamera with Apache License 2.0 5 votes vote down vote up
/** Retrieves the maximum digital zoom as a scale factor. */
public double getMaxZoom(String cameraId) {
  CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
  try {
    // Extract characteristics for the current camera.
    CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
    maxDigitalZoom = characteristics.get(SCALER_AVAILABLE_MAX_DIGITAL_ZOOM);
  } catch (CameraAccessException e) {
    Log.w(TAG, e);
  }
  Log.d(TAG, String.format("getMaxZoom(%s) -> %.2f", cameraId, maxDigitalZoom));
  return maxDigitalZoom;
}
 
Example #23
Source File: AutoFocusHelper.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
/**
 * Calculates sensor crop region for a zoom level (zoom >= 1.0).
 *
 * @return Crop region.
 */
public static Rect cropRegionForZoom(CameraCharacteristics characteristics, float zoom)
{
    Rect sensor = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE);
    int xCenter = sensor.width() / 2;
    int yCenter = sensor.height() / 2;
    int xDelta = (int) (0.5f * sensor.width() / zoom);
    int yDelta = (int) (0.5f * sensor.height() / zoom);
    return new Rect(xCenter - xDelta, yCenter - yDelta, xCenter + xDelta, yCenter + yDelta);
}
 
Example #24
Source File: Camera2Helper.java    From CameraCompat with MIT License 5 votes vote down vote up
private void operateFlash(boolean isOpen) throws CameraAccessException, SecurityException {
    CameraCharacteristics characteristics =
            mCameraManager.getCameraCharacteristics(mBackCameraId);
    Boolean available = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
    boolean flashSupported = available == null ? false : available;
    if (!flashSupported) {
        return;
    }
    mCameraController.onSettingsChanged(mCameraDevice, mCaptureSession, mOutputTargets, isOpen,
            mCamera2Handler);
}
 
Example #25
Source File: Camera2Helper.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * 指定された facing に対応するカメラIDを取得します.
 * <p>
 * facing に対応したカメラが発見できない場合には null を返却します。
 * </p>
 * @param cameraManager カメラマネージャ
 * @param facing カメラの向き
 * @return カメラID
 * @throws CameraAccessException カメラの操作に失敗した場合に発生
 */
public static String getCameraId(final CameraManager cameraManager, final int facing) throws CameraAccessException {
    for (String cameraId : cameraManager.getCameraIdList()) {
        CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
        Integer supportFacing = characteristics.get(CameraCharacteristics.LENS_FACING);
        if (supportFacing != null && supportFacing == facing) {
            return cameraId;
        }
    }
    return null;
}
 
Example #26
Source File: Camera2Helper.java    From CameraCompat with MIT License 5 votes vote down vote up
private void initCameraIds() throws CameraAccessException {
    for (String cameraId : mCameraManager.getCameraIdList()) {
        CameraCharacteristics characteristics =
                mCameraManager.getCameraCharacteristics(cameraId);

        Integer facing = characteristics.get(CameraCharacteristics.LENS_FACING);
        if (facing != null) {
            if (facing == CameraCharacteristics.LENS_FACING_FRONT) {
                mFrontCameraId = cameraId;
            } else if (facing == CameraCharacteristics.LENS_FACING_BACK) {
                mBackCameraId = cameraId;
            }
        }
    }
}
 
Example #27
Source File: Camera2ApiManager.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 5 votes vote down vote up
@Nullable
public CameraCharacteristics getCameraCharacteristics() {
  try {
    return cameraId != -1 ? cameraManager.getCameraCharacteristics(String.valueOf(cameraId))
        : null;
  } catch (CameraAccessException e) {
    Log.e(TAG, "Error", e);
    return null;
  }
}
 
Example #28
Source File: OneCameraZslImpl.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
/**
 * @see com.android.camera.one.OneCamera#triggerFocusAndMeterAtPoint(float,
 * float)
 */
@Override
public void triggerFocusAndMeterAtPoint(float nx, float ny)
{
    int sensorOrientation = mCharacteristics.get(
            CameraCharacteristics.SENSOR_ORIENTATION);
    mAERegions = AutoFocusHelper.aeRegionsForNormalizedCoord(nx, ny, mCropRegion, sensorOrientation);
    mAFRegions = AutoFocusHelper.afRegionsForNormalizedCoord(nx, ny, mCropRegion, sensorOrientation);

    startAFCycle();
}
 
Example #29
Source File: Camera2Source.java    From Camera2Vision with Apache License 2.0 5 votes vote down vote up
public boolean isCamera2Native() {
    try {
        if (ContextCompat.checkSelfPermission(mContext, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {return false;}
        manager = (CameraManager) mContext.getSystemService(Context.CAMERA_SERVICE);
        mCameraId = manager.getCameraIdList()[mFacing];
        CameraCharacteristics characteristics = manager.getCameraCharacteristics(mCameraId);
        //CHECK CAMERA HARDWARE LEVEL. IF CAMERA2 IS NOT NATIVELY SUPPORTED, GO BACK TO CAMERA1
        Integer deviceLevel = characteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
        return deviceLevel != null && (deviceLevel != CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY);
    }
    catch (CameraAccessException ex) {return false;}
    catch (NullPointerException e) {return false;}
    catch (ArrayIndexOutOfBoundsException ez) {return false;}
}
 
Example #30
Source File: Camera2.java    From SimpleVideoEditor with Apache License 2.0 5 votes vote down vote up
/**
 * Captures a still picture.
 */
void captureStillPicture() {
    try {
        CaptureRequest.Builder captureRequestBuilder = mCamera.createCaptureRequest(
                CameraDevice.TEMPLATE_STILL_CAPTURE);
        captureRequestBuilder.addTarget(mImageReader.getSurface());
        captureRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                mCaptureRequestBuilder.get(CaptureRequest.CONTROL_AF_MODE));
        updateFlashLightState();
        // Calculate JPEG orientation.
        @SuppressWarnings("ConstantConditions")
        int sensorOrientation = mCameraCharacteristics.get(
                CameraCharacteristics.SENSOR_ORIENTATION);
        captureRequestBuilder.set(CaptureRequest.JPEG_ORIENTATION,
                (sensorOrientation +
                        mDisplayOrientation * (mConfig.getCurrentFacing() == Constants.CAMERA_FACING_FRONT ? 1 : -1) +
                        360) % 360);
        // Stop preview and capture a still picture.
        mCaptureSession.stopRepeating();
        mCaptureSession.capture(captureRequestBuilder.build(),
                new CameraCaptureSession.CaptureCallback() {
                    @Override
                    public void onCaptureCompleted(@NonNull CameraCaptureSession session,
                                                   @NonNull CaptureRequest request,
                                                   @NonNull TotalCaptureResult result) {
                        unlockFocus();
                    }
                }, null);
    } catch (CameraAccessException e) {
        Log.e(TAG, "Cannot capture a still picture.", e);
    }
}