android.hardware.camera2.CameraMetadata Java Examples

The following examples show how to use android.hardware.camera2.CameraMetadata. 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: CameraWrapper.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
private static Integer choiceAutoFocusMode(final Context context,
                                           final CameraManager cameraManager,
                                           final String cameraId) throws CameraAccessException {
    PackageManager pkgMgr = context.getPackageManager();
    if (!pkgMgr.hasSystemFeature(PackageManager.FEATURE_CAMERA_AUTOFOCUS)) {
        return null;
    }

    CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
    int[] afModes = characteristics.get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES);
    if (afModes == null) {
        return null;
    }
    for (int i = 0; i < afModes.length; i++) {
        if (afModes[i] == CameraMetadata.CONTROL_AF_MODE_CONTINUOUS_PICTURE) {
            return afModes[i];
        }
    }
    return null;
}
 
Example #2
Source File: Camera2Session.java    From webrtc_android with MIT License 6 votes vote down vote up
private void start() {
    checkIsOnCameraThread();
    Logging.d(TAG, "start");

    try {
        cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraId);
    } catch (final CameraAccessException e) {
        reportError("getCameraCharacteristics(): " + e.getMessage());
        return;
    }
    cameraOrientation = cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);
    isCameraFrontFacing = cameraCharacteristics.get(CameraCharacteristics.LENS_FACING)
            == CameraMetadata.LENS_FACING_FRONT;

    findCaptureFormat();
    openCamera();
}
 
Example #3
Source File: CaptureDataSerializer.java    From Camera2 with Apache License 2.0 6 votes vote down vote up
/**
 * Generate a human-readable string of the given capture request and write
 * it to the given file.
 */
public static void toFile(String title, CameraMetadata<?> metadata, File file)
{
    try
    {
        // Will append if the file already exists.
        FileWriter writer = new FileWriter(file, true);
        if (metadata instanceof CaptureRequest)
        {
            dumpMetadata(title, (CaptureRequest) metadata, writer);
        } else if (metadata instanceof CaptureResult)
        {
            dumpMetadata(title, (CaptureResult) metadata, writer);
        } else
        {
            writer.close();
            throw new IllegalArgumentException("Cannot generate debug data from type "
                    + metadata.getClass().getName());
        }
        writer.close();
    } catch (IOException ex)
    {
        Log.e(TAG, "Could not write capture data to file.", ex);
    }
}
 
Example #4
Source File: LollipopCamera.java    From LiveMultimedia with Apache License 2.0 6 votes vote down vote up
/************************************************************************************************
* Unlock the focus. This method should be called when still image capture sequence is finished.
************************************************************************************************/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void unlockFocus() {
    try {
        // Reset the autofucos trigger
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                mBackgroundHandler);
        // After this, the camera will go back to the normal state of preview.
        mState = STATE_PREVIEW;
        mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
                mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #5
Source File: CameraFragment.java    From io2015-codelabs with Apache License 2.0 6 votes vote down vote up
/**
 * Lock the focus as the first step for a still image capture.
 */
private void lockFocus() {
    Log.d(TAG, "lockFocus: ");
    try {
        // This is how to tell the camera to lock focus.
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CameraMetadata.CONTROL_AF_TRIGGER_START);
        // Tell #mCaptureCallback to wait for the lock.
        mState = STATE_WAITING_LOCK;
        mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback,
                mBackgroundHandler);
    } catch (CameraAccessException e) {
        Log.e(TAG, "CameraAccessException: " + e);
        e.printStackTrace();
    }
}
 
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: CameraWrapper.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
private void setDefaultCaptureRequest(final CaptureRequest.Builder request,
                                      final boolean trigger) {
    if (hasAutoFocus()) {
        request.set(CaptureRequest.CONTROL_AF_MODE, mAutoFocusMode);
        if (trigger) {
            request.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
        }
    }
    if (hasAutoExposure()) {
        request.set(CaptureRequest.CONTROL_AE_MODE, mAutoExposureMode);
    }
    setWhiteBalance(request);
    // Light が ON の場合は、CONTROL_AE_MODE を CONTROL_AE_MODE_ON にする。
    if (mIsTouchOn) {
        mUseTouch = true;
        request.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON);
        request.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_TORCH);
    }
}
 
Example #8
Source File: OneCameraCharacteristicsImpl.java    From Camera2 with Apache License 2.0 6 votes vote down vote up
@Override
public List<FaceDetectMode> getSupportedFaceDetectModes()
{
    int[] modes = mCameraCharacteristics.get(
            CameraCharacteristics.STATISTICS_INFO_AVAILABLE_FACE_DETECT_MODES);

    List<FaceDetectMode> oneModes = new ArrayList<>(modes.length);

    for (int i = 0; i < modes.length; i++)
    {
        if (modes[i] == CameraMetadata.STATISTICS_FACE_DETECT_MODE_FULL)
        {
            oneModes.add(FaceDetectMode.FULL);
        }
        if (modes[i] == CameraMetadata.STATISTICS_FACE_DETECT_MODE_SIMPLE)
        {
            oneModes.add(FaceDetectMode.SIMPLE);
        }
        if (modes[i] == CameraMetadata.STATISTICS_FACE_DETECT_MODE_OFF)
        {
            oneModes.add(FaceDetectMode.NONE);
        }
    }

    return oneModes;
}
 
Example #9
Source File: OneCameraImpl.java    From Camera2 with Apache License 2.0 6 votes vote down vote up
/**
 * Request preview capture stream with AF_MODE_CONTINUOUS_PICTURE.
 *
 * @param tag
 * @return true if request was build and sent successfully.
 */
private boolean repeatingPreview(Object tag)
{
    try
    {
        CaptureRequest.Builder builder = mDevice.
                createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        builder.addTarget(mPreviewSurface);
        builder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
        addBaselineCaptureKeysToRequest(builder);
        mCaptureSession.setRepeatingRequest(builder.build(), mCaptureCallback, mCameraHandler);
        Log.v(TAG, String.format("Sent repeating Preview request, zoom = %.2f", mZoomValue));
        return true;
    } catch (CameraAccessException ex)
    {
        Log.e(TAG, "Could not access camera setting up preview.", ex);
        return false;
    }
}
 
Example #10
Source File: OneCameraImpl.java    From Camera2 with Apache License 2.0 6 votes vote down vote up
/**
 * Request preview capture stream with auto focus trigger cycle.
 */
private void sendAutoFocusTriggerCaptureRequest(Object tag)
{
    try
    {
        // Step 1: Request single frame CONTROL_AF_TRIGGER_START.
        CaptureRequest.Builder builder;
        builder = mDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        builder.addTarget(mPreviewSurface);
        builder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
        mControlAFMode = CameraMetadata.CONTROL_AF_MODE_AUTO;
        addBaselineCaptureKeysToRequest(builder);
        builder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_START);
        builder.setTag(tag);
        mCaptureSession.capture(builder.build(), mCaptureCallback, mCameraHandler);

        // Step 2: Call repeatingPreview to update mControlAFMode.
        repeatingPreview(tag);
        resumeContinuousAFAfterDelay(FOCUS_HOLD_MILLIS);
    } catch (CameraAccessException ex)
    {
        Log.e(TAG, "Could not execute preview request.", ex);
    }
}
 
Example #11
Source File: Camera2BasicFragment.java    From android-Camera2Basic with Apache License 2.0 6 votes vote down vote up
/**
 * Unlock the focus. This method should be called when still image capture sequence is
 * finished.
 */
private void unlockFocus() {
    try {
        // Reset the auto-focus trigger
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
        setAutoFlash(mPreviewRequestBuilder);
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                mBackgroundHandler);
        // After this, the camera will go back to the normal state of preview.
        mState = STATE_PREVIEW;
        mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
                mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #12
Source File: ScanQRActivity.java    From ScreenCapture with MIT License 6 votes vote down vote up
private void updatePreview() {
        Log.d("WOW", "update preview....");
        if (null == mCameraDevice) {
            return;
        }
        try {
            if (isAutoFocusSupported()) {
                mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                        CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE/*CONTROL_AF_MODE_AUTO*/);
                Log.d("WOW", "support autofocus");
            } else {
                mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                        CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
                Log.d("WOW", "not support autofocus");
            }

            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_MODE,
                    CameraMetadata.CONTROL_MODE_AUTO);
//            HandlerThread thread = new HandlerThread("CameraPreview");
//            thread.start();
            mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), null,
                    mBackgroundHandler);
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }
 
Example #13
Source File: ScanQRActivity.java    From ScreenCapture with MIT License 6 votes vote down vote up
private void unlockFocus() {
        try {
            // Reset the auto-focus trigger
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                    CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
//            setAutoFlash(mPreviewRequestBuilder);
            mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                    mBackgroundHandler);
            // After this, the camera will go back to the normal state of preview.
            mState = STATE_PREVIEW;
            mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback,
                    mBackgroundHandler);
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }
 
Example #14
Source File: Camera2Proxy.java    From CameraDemo with Apache License 2.0 6 votes vote down vote up
private void process(CaptureResult result) {
    Integer state = result.get(CaptureResult.CONTROL_AF_STATE);
    if (null == state) {
        return;
    }
    Log.d(TAG, "process: CONTROL_AF_STATE: " + state);
    if (state == CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED || state == CaptureResult
            .CONTROL_AF_STATE_NOT_FOCUSED_LOCKED) {
        Log.d(TAG, "process: start normal preview");
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest
                .CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.FLASH_MODE_OFF);
        startPreview();
    }
}
 
Example #15
Source File: Camera2BasicFragment.java    From opencv-documentscanner-android with Apache License 2.0 6 votes vote down vote up
/**
 * Unlock the focus. This method should be called when still image capture sequence is
 * finished.
 */
private void unlockFocus() {
    try {
        // Reset the auto-focus trigger
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
        setAutoFlash(mPreviewRequestBuilder);
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                mBackgroundHandler);
        // After this, the camera will go back to the normal state of preview.
        mState = STATE_PREVIEW;
        mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
                mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #16
Source File: Camera2BasicFragment.java    From Android-Camera2-Front-with-Face-Detection with Apache License 2.0 6 votes vote down vote up
/**
 * Unlock the focus. This method should be called when still image capture sequence is
 * finished.
 */
private void unlockFocus() {
    try {
        // Reset the auto-focus trigger
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
        setAutoFlash(mPreviewRequestBuilder);
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                mBackgroundHandler);
        // After this, the camera will go back to the normal state of preview.
        mState = STATE_PREVIEW;
        mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
                mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #17
Source File: BasicCamera.java    From Camera2App with Apache License 2.0 6 votes vote down vote up
private void unlockFocus() {
    try {
        // AFのロックを解除する(トリガーをキャンセルする)
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
        // AFトリガーのキャンセルを実行する
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                mInterface.getBackgroundHandler());
        // プレビューを継続するためsetRepeatingRequestメソッドを実行する
        mState = STATE_PREVIEW;
        mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
                mInterface.getBackgroundHandler());
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #18
Source File: Camera2Fragment.java    From MultiMediaSample with Apache License 2.0 6 votes vote down vote up
/**
 * Unlock the focus. This method should be called when still image capture sequence is
 * finished.
 */
private void unlockFocus() {
    try {
        // Reset the auto-focus trigger
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
        setAutoFlash(mPreviewRequestBuilder);
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                mBackgroundHandler);
        // After this, the camera will go back to the normal state of preview.
        mState = STATE_PREVIEW;
        mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
                mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #19
Source File: CameraNew.java    From EvilsLive with MIT License 6 votes vote down vote up
private void doPreviewConfiguration() {
        if (mCamera == null) {
            return;
        }

        try {
//            mPreviewBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
//            mPreviewBuilder.addTarget(surfaceView.getHolder().getSurface());
//            mPreviewBuilder.addTarget(mImageReader.getSurface());
            mPreviewBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
//            mPreviewBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
//            mPreviewBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);
//            mPreviewBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);

            mPreviewBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, mFps[mFps.length -1 ]);
            mCaptureSession.setRepeatingRequest(mPreviewBuilder.build(), mPreCaptureCallback, mHandler);

        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }
 
Example #20
Source File: Camera2Handler.java    From Augendiagnose with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reconfigure the camera with new flash and focus settings.
 */
private void reconfigureCamera() {
	if (mCameraDevice != null && mCaptureSession != null) {
		try {
			mCaptureSession.stopRepeating();

			mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
			mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);

			doPreviewConfiguration();
		}
		catch (CameraAccessException | IllegalStateException e) {
			mCameraCallback.onCameraError("Failed to reconfigure the camera", "rec1", e);
		}
	}
}
 
Example #21
Source File: Camera2ApiManager.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 6 votes vote down vote up
/**
 * @required: <uses-permission android:name="android.permission.FLASHLIGHT"/>
 */
public void disableLantern() {
  CameraCharacteristics characteristics = getCameraCharacteristics();
  if (characteristics == null) return;

  if (characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE)) {
    if (builderInputSurface != null) {
      try {
        builderInputSurface.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_OFF);
        cameraCaptureSession.setRepeatingRequest(builderInputSurface.build(),
            faceDetectionEnabled ? cb : null, null);
        lanternEnable = false;
      } catch (Exception e) {
        Log.e(TAG, "Error", e);
      }
    }
  }
}
 
Example #22
Source File: Camera2Fragment.java    From 361Camera with Apache License 2.0 6 votes vote down vote up
private void switchHdrMode() {
    switch (mHdrMode) {
        case 0:
            mHdrMode = 1;
            mIvHdr.setImageResource(R.mipmap.hdr_on);
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_HDR);
            break;
        case 1:
            mHdrMode = 0;
            mIvHdr.setImageResource(R.mipmap.hdr_off);
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_SCENE_MODE, CameraMetadata.CONTROL_SCENE_MODE_DISABLED);
            break;
    }
    try {
        mCaptureSession.setRepeatingRequest(
                mPreviewRequestBuilder.build(),
                mPreCaptureCallback, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
        return;
    }
}
 
Example #23
Source File: Camera2Source.java    From Camera2Vision with Apache License 2.0 6 votes vote down vote up
/**
 * Unlock the focus. This method should be called when still image capture sequence is
 * finished.
 */
private void unlockFocus() {
    try {
        // Reset the auto-focus trigger
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
        if(mFlashSupported) {
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, mFlashMode);
        }
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
        // After this, the camera will go back to the normal state of preview.
        mState = STATE_PREVIEW;
        mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #24
Source File: Camera.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private static boolean isMonochrome(@NonNull String deviceName, @NonNull CameraManager cameraManager) {
  try {
    CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(deviceName);
    int[]                 capabilities    = characteristics.get(CameraCharacteristics.REQUEST_AVAILABLE_CAPABILITIES);

    if (capabilities != null) {
      for (int capability : capabilities) {
        if (capability == CameraMetadata.REQUEST_AVAILABLE_CAPABILITIES_MONOCHROME) {
          return true;
        }
      }
    }
  } catch (CameraAccessException e) {
    return false;
  }

  return false;
}
 
Example #25
Source File: CameraFragment.java    From io2015-codelabs with Apache License 2.0 6 votes vote down vote up
/**
 * Unlock the focus. This method should be called when still image capture sequence is finished.
 */
private void unlockFocus() {
    Log.d(TAG, "unlockFocus: ");
    try {
        if (mEnabledAutoFocus) {
            // Reset the autofucos trigger
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                    CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                    CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
        }
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                mBackgroundHandler);
        // After this, the camera will go back to the normal state of preview.
        mState = STATE_PREVIEW;
        mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
                mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #26
Source File: Camera2Fragment.java    From MultiMediaSample with Apache License 2.0 5 votes vote down vote up
/**
 * Lock the focus as the first step for a still image capture.
 */
private void lockFocus() {
    try {
        // This is how to tell the camera to lock focus.
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CameraMetadata.CONTROL_AF_TRIGGER_START);
        // Tell #mCaptureCallback to wait for the lock.
        mState = STATE_WAITING_LOCK;
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #27
Source File: Camera2StateMachine.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
public void enter() throws CameraAccessException {
    mPreviewRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
    mPreviewRequestBuilder.addTarget(mSurface);
    mPreviewRequestBuilder.addTarget(mPreviewImageReader.getSurface());
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
    mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback, mHandler);
}
 
Example #28
Source File: CameraTexture2.java    From PHONK with GNU General Public License v3.0 5 votes vote down vote up
private void unlockFocus() {
    MLog.d(TAG, "unlockFocus");

    try {
        // Reset the auto-focus trigger
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
        //setAutoFlash(mPreviewRequestBuilder);
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, null);
        // After this, the camera will go back to the normal state of preview.
        mState = STATE_PREVIEW;
        mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, null);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #29
Source File: Camera2Fragment.java    From 361Camera with Apache License 2.0 5 votes vote down vote up
private void triggerFocusArea(float x, float y) {
    CameraManager manager = (CameraManager) getActivity().getSystemService(Context.CAMERA_SERVICE);
    try {
        CameraCharacteristics characteristics
                = manager.getCameraCharacteristics(mCameraId);
        Integer sensorOrientation = characteristics.get(
                CameraCharacteristics.SENSOR_ORIENTATION);

        sensorOrientation = sensorOrientation == null ? 0 : sensorOrientation;

        Rect cropRegion = AutoFocusHelper.cropRegionForZoom(characteristics, 1f);
        mAERegions = AutoFocusHelper.aeRegionsForNormalizedCoord(x, y, cropRegion, sensorOrientation);
        mAFRegions = AutoFocusHelper.afRegionsForNormalizedCoord(x, y, cropRegion, sensorOrientation);

        // Step 1: Request single frame CONTROL_AF_TRIGGER_START.
        CaptureRequest.Builder builder;
        builder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        builder.addTarget(mPreviewSurface);
        builder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);

        mControlAFMode = AutoFocusMode.AUTO;

        builder.set(CaptureRequest.CONTROL_AF_MODE, mControlAFMode.switchToCamera2FocusMode());
        builder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_START);
        mCaptureSession.capture(builder.build(), mPreCaptureCallback, mBackgroundHandler);

        // Step 2: Call repeatingPreview to update mControlAFMode.
        sendRepeatPreviewRequest();
        resumeContinuousAFAfterDelay(DELAY_TIME_RESUME_CONTINUOUS_AF);
    } catch (CameraAccessException ex) {
        Log.e(TAG, "Could not execute preview request.", ex);
    }
}
 
Example #30
Source File: Camera2BasicFragment.java    From android-Camera2Basic with Apache License 2.0 5 votes vote down vote up
/**
 * Lock the focus as the first step for a still image capture.
 */
private void lockFocus() {
    try {
        // This is how to tell the camera to lock focus.
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CameraMetadata.CONTROL_AF_TRIGGER_START);
        // Tell #mCaptureCallback to wait for the lock.
        mState = STATE_WAITING_LOCK;
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}