Java Code Examples for android.hardware.camera2.CameraMetadata

The following are top voted examples for showing how to use android.hardware.camera2.CameraMetadata. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: opencv-documentscanner-android   File: Camera2BasicFragment.java   View source code 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 2
Project: Android-Code-Demos   File: Camera2BasicFragment.java   View source code 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 3
Project: Camera_Calibration_Android   File: Camera2BasicFragment.java   View source code 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 4
Project: android-Camera2Basic-master   File: Camera2BasicFragment.java   View source code 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 5
Project: Camera2Vision   File: Camera2Source.java   View source code 6 votes vote down vote up
public void autoFocus(@Nullable AutoFocusCallback cb, MotionEvent pEvent, int screenW, int screenH) {
    if(cb != null) {
        mAutoFocusCallback = cb;
    }
    if(sensorArraySize != null) {
        final int y = (int)pEvent.getX() / screenW * sensorArraySize.height();
        final int x = (int)pEvent.getY() / screenH * sensorArraySize.width();
        final int halfTouchWidth = 150;
        final int halfTouchHeight = 150;
        MeteringRectangle focusAreaTouch = new MeteringRectangle(
                Math.max(x-halfTouchWidth, 0),
                Math.max(y-halfTouchHeight, 0),
                halfTouchWidth*2,
                halfTouchHeight*2,
                MeteringRectangle.METERING_WEIGHT_MAX - 1);

        try {
            mCaptureSession.stopRepeating();
            //Cancel any existing AF trigger (repeated touches, etc.)
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_OFF);
            mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);

            //Now add a new AF trigger with focus region
            if(isMeteringAreaAFSupported) {
                mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_REGIONS, new MeteringRectangle[]{focusAreaTouch});
            }
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
            mPreviewRequestBuilder.setTag("FOCUS_TAG"); //we'll capture this later for resuming the preview!
            //Then we ask for a single request (not repeating!)
            mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
        } catch(CameraAccessException ex) {
            Log.d("ASD", "AUTO FOCUS EXCEPTION: "+ex);
        }
    }
}
 
Example 6
Project: Camera2Vision   File: Camera2Source.java   View source code 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 7
Project: 361Camera   File: Camera2Fragment.java   View source code 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 8
Project: 361Camera   File: Camera2Fragment.java   View source code 6 votes vote down vote up
/**
 * Called after a RAW/JPEG capture has completed; resets the AF trigger state for the
 * pre-capture sequence.
 * <p/>
 * Call this only with {@link #mCameraStateLock} held.
 */
private void finishedCaptureLocked() {
    try {
        // Reset the auto-focus trigger in case AF didn't run quickly enough.
        if (!mNoAFRun) {
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                    CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);

            mCaptureSession.capture(mPreviewRequestBuilder.build(), mPreCaptureCallback,
                    mBackgroundHandler);

            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                    CameraMetadata.CONTROL_AF_TRIGGER_IDLE);
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 9
Project: OkayCamera-Android   File: Camera2RawFragment.java   View source code 6 votes vote down vote up
/**
 * Called after a RAW/JPEG capture has completed; resets the AF trigger state for the
 * pre-capture sequence.
 * <p/>
 * Call this only with {@link #mCameraStateLock} held.
 */
private void finishedCaptureLocked() {
    try {
        // Reset the auto-focus trigger in case AF didn't run quickly enough.
        if (!mNoAFRun) {
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                    CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);

            mCaptureSession.capture(mPreviewRequestBuilder.build(), mPreCaptureCallback,
                    mBackgroundHandler);

            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                    CameraMetadata.CONTROL_AF_TRIGGER_IDLE);
        }
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 10
Project: AppRTC-Android   File: Camera2Session.java   View source code 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 11
Project: JinsMemeBRIDGE-Android   File: Camera2BasicFragment.java   View source code 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
Project: AndroidRTC   File: Camera2Session.java   View source code 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 13
Project: CameraKitView   File: Camera2Fragment.java   View source code 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);
        mPreviewSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
            mBackgroundHandler);

        updateAutoFocus();
        updateFlash(mPreviewRequestBuilder);
        // After this, the camera will go back to the normal state of preview.
        mState = STATE_PREVIEW;
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
            CaptureRequest.CONTROL_AF_TRIGGER_IDLE);
        mPreviewSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
            mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 14
Project: CameraKitView   File: Camera2.java   View source code 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);
        mPreviewSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
            mBackgroundHandler);

        updateAutoFocus();
        updateFlash(mPreviewRequestBuilder);
        // After this, the camera will go back to the normal state of preview.
        mState = STATE_PREVIEW;
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
            CaptureRequest.CONTROL_AF_TRIGGER_IDLE);
        mPreviewSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback,
            mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 15
Project: VideoCRE   File: Camera2Session.java   View source code 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 16
Project: EvilsLive   File: CameraNew.java   View source code 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 17
Project: DiedricoApp   File: Camera2BasicFragment.java   View source code 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 18
Project: DiedricoApp   File: Camera2BasicFragment.java   View source code 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
Project: MultiMediaSample   File: Camera2Fragment.java   View source code 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 20
Project: androidprojectbase   File: Camera2BasicFragment.java   View source code 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 21
Project: NoobCameraFlash   File: CameraUtilLollipop.java   View source code 6 votes vote down vote up
@Override
public void onOpened(@NonNull CameraDevice camera) {
    mCameraDevice = camera;
    //get builder
    try {
        mBuilder = camera.createCaptureRequest(CameraDevice.TEMPLATE_MANUAL);
        //flash on, default is on
        mBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AF_MODE_AUTO);
        mBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_TORCH);
        List<Surface> list = new ArrayList<>();
        SurfaceTexture mSurfaceTexture = new SurfaceTexture(1);
        Size size = getSmallestSize(mCameraDevice.getId());
        mSurfaceTexture.setDefaultBufferSize(size.getWidth(), size.getHeight());
        Surface mSurface = new Surface(mSurfaceTexture);
        list.add(mSurface);
        mBuilder.addTarget(mSurface);
        camera.createCaptureSession(list, new MyCameraCaptureSessionStateCallback(), null);
        mSurfaceTexture.release();
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example 22
Project: aurora-imui   File: CameraNew.java   View source code 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 23
Project: MoleMapperAndroid   File: LollipopCameraFragment.java   View source code 6 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)
    {
        LogExt.e(getClass(), e);
    }
}
 
Example 24
Project: MoleMapperAndroid   File: LollipopCameraFragment.java   View source code 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)
    {
        LogExt.e(getClass(), e);
        LogExt.e(getClass(), e);
    }
}
 
Example 25
Project: Camera2App   File: BasicCamera.java   View source code 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 26
Project: Camera2   File: CaptureDataSerializer.java   View source code 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 27
Project: Camera2   File: OneCameraImpl.java   View source code 6 votes vote down vote up
/**
 * Request preview capture stream with AF_MODE_CONTINUOUS_PICTURE.
 *
 * @return true if request was build and sent successfully.
 * @param tag
 */
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(), mAutoFocusStateListener,
                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 28
Project: Camera2   File: OneCameraImpl.java   View source code 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(), mAutoFocusStateListener, 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 29
Project: 365browser   File: VideoCaptureCamera2.java   View source code 6 votes vote down vote up
static int getCaptureApiType(int id) {
    final CameraCharacteristics cameraCharacteristics = getCameraCharacteristics(id);
    if (cameraCharacteristics == null) {
        return VideoCaptureApi.UNKNOWN;
    }

    final int supportedHWLevel =
            cameraCharacteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);
    switch (supportedHWLevel) {
        case CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY:
            return VideoCaptureApi.ANDROID_API2_LEGACY;
        case CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_FULL:
            return VideoCaptureApi.ANDROID_API2_FULL;
        case CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LIMITED:
            return VideoCaptureApi.ANDROID_API2_LIMITED;
        default:
            return VideoCaptureApi.ANDROID_API2_LEGACY;
    }
}
 
Example 30
Project: material-camera   File: Camera2Fragment.java   View source code 6 votes vote down vote up
private void lockFocus() {
  try {
    if (mAfAvailable) {
      // This is how to tell the camera to lock focus.
      mPreviewBuilder.set(
          CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
      // Tell #mCaptureCallback to wait for the lock.
      mState = STATE_WAITING_LOCK;
    } else {
      runPrecaptureSequence();
      return;
    }

    setFlashMode(mPreviewBuilder);

    mPreviewSession.capture(mPreviewBuilder.build(), mCaptureCallback, mBackgroundHandler);
  } catch (CameraAccessException e) {
    e.printStackTrace();
  }
}
 
Example 31
Project: material-camera   File: Camera2Fragment.java   View source code 6 votes vote down vote up
private void setFlashMode(CaptureRequest.Builder requestBuilder) {
  mPreviewBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);

  int aeMode;
  int flashMode;
  switch (mInterface.getFlashMode()) {
    case FLASH_MODE_AUTO:
      aeMode = CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH;
      flashMode = CameraMetadata.FLASH_MODE_SINGLE;
      break;
    case FLASH_MODE_ALWAYS_ON:
      aeMode = CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH;
      flashMode = CameraMetadata.FLASH_MODE_TORCH;
      break;
    case FLASH_MODE_OFF:
    default:
      aeMode = CaptureRequest.CONTROL_AE_MODE_ON;
      flashMode = CameraMetadata.FLASH_MODE_OFF;
      break;
  }

  requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, aeMode);
  requestBuilder.set(CaptureRequest.FLASH_MODE, flashMode);
}
 
Example 32
Project: binea_project_for_android   File: Camera2BasicFragment.java   View source code 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 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 33
Project: io2015-codelabs   File: CameraFragment.java   View source code 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 34
Project: io2015-codelabs   File: CameraFragment.java   View source code 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 35
Project: io2015-codelabs   File: CameraFragment.java   View source code 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 36
Project: breadwallet-android   File: CameraActivity.java   View source code 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 37
Project: LiveMultimedia   File: LollipopCamera.java   View source code 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 38
Project: Augendiagnose   File: Camera2Handler.java   View source code 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 39
Project: opencv-documentscanner-android   File: Camera2BasicFragment.java   View source code 5 votes vote down vote up
/**
     * Lock the focus as the first step for a still image capture.
     */
    private void lockFocus() {
        try {
            Log.d(TAG, "lockFocus: ");
            // 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 40
Project: CameraFragment   File: Camera2Manager.java   View source code 5 votes vote down vote up
private void lockFocus() {
    try {
        previewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);

        previewState = STATE_WAITING_LOCK;
        captureSession.capture(previewRequestBuilder.build(), captureCallback, backgroundHandler);
    } catch (Exception ignore) {
    }
}