android.hardware.camera2.CaptureRequest Java Examples

The following examples show how to use android.hardware.camera2.CaptureRequest. 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: CaptureRequestFactory.java    From libsoftwaresync with Apache License 2.0 6 votes vote down vote up
public CaptureRequest.Builder makeFrameInjectionRequest(
    long desiredExposureTimeNs, List<Surface> imageSurfaces) throws CameraAccessException {
  CaptureRequest.Builder builder = device.createCaptureRequest(TEMPLATE_PREVIEW);
  builder.set(CONTROL_MODE, CONTROL_MODE_AUTO);
  builder.set(CONTROL_AE_MODE, CONTROL_AE_MODE_OFF);
  builder.set(SENSOR_EXPOSURE_TIME, desiredExposureTimeNs);
  // TODO: Inserting frame duration directly would be more accurate than inserting exposure since
  // {@code frame duration ~ exposure + variable overhead}. However setting frame duration may not
  // be supported on many android devices, so we use exposure time here.

  List<Integer> targetIndices = new ArrayList<>();
  for (int i = 0; i < imageSurfaces.size(); i++) {
    builder.addTarget(imageSurfaces.get(i));
    targetIndices.add(i);
  }
  builder.setTag(new CaptureRequestTag(targetIndices, PhaseAlignController.INJECT_FRAME));

  return builder;
}
 
Example #2
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 #3
Source File: CameraCaptureSessionImpl.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public int setRepeatingBurst(List<CaptureRequest> requests,
        CaptureCallback callback, Handler handler) throws CameraAccessException {
    checkRepeatingRequests(requests);

    synchronized (mDeviceImpl.mInterfaceLock) {
        checkNotClosed();

        handler = checkHandler(handler, callback);

        if (DEBUG) {
            CaptureRequest[] requestArray = requests.toArray(new CaptureRequest[0]);
            Log.v(TAG, mIdString + "setRepeatingBurst - requests " +
                    Arrays.toString(requestArray) + ", callback " + callback +
                    " handler" + "" + handler);
        }

        return addPendingSequence(mDeviceImpl.setRepeatingBurst(requests,
                createCaptureCallbackProxy(handler, callback), mDeviceExecutor));
    }
}
 
Example #4
Source File: Camera2Source.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 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 #5
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 #6
Source File: CameraHelp2.java    From WeiXinRecordedDemo with MIT License 6 votes vote down vote up
public void shotPhoto(){

        try {
            CaptureRequest.Builder captureRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
            captureRequestBuilder.addTarget(mImageReader.getSurface());
            // 自动对焦
            captureRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
            // 自动曝光
            captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
            captureRequestBuilder.set(CaptureRequest.JPEG_ORIENTATION, mOrientation);
            CaptureRequest captureRequest = captureRequestBuilder.build();
            mCameraCaptureSession.capture(captureRequest, null, mHandler);
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }
 
Example #7
Source File: Camera2.java    From LockDemo with Apache License 2.0 6 votes vote down vote up
/**
 * Unlocks the auto-focus and restart camera preview. This is supposed to be called after
 * capturing a still picture.
 */
void unlockFocus() {
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
            CaptureRequest.CONTROL_AF_TRIGGER_CANCEL);
    try {
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, null);
        updateAutoFocus();
        updateFlash();
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CaptureRequest.CONTROL_AF_TRIGGER_IDLE);
        mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback,
                null);
        mCaptureCallback.setState(PictureCaptureCallback.STATE_PREVIEW);
    } catch (CameraAccessException e) {
        Log.e(TAG, "Failed to restart camera preview.", e);
    }
}
 
Example #8
Source File: Camera2.java    From cameraview with Apache License 2.0 6 votes vote down vote up
/**
 * Unlocks the auto-focus and restart camera preview. This is supposed to be called after
 * capturing a still picture.
 */
void unlockFocus() {
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
            CaptureRequest.CONTROL_AF_TRIGGER_CANCEL);
    try {
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, null);
        updateAutoFocus();
        updateFlash();
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,
                CaptureRequest.CONTROL_AF_TRIGGER_IDLE);
        mCaptureSession.setRepeatingRequest(mPreviewRequestBuilder.build(), mCaptureCallback,
                null);
        mCaptureCallback.setState(PictureCaptureCallback.STATE_PREVIEW);
    } catch (CameraAccessException e) {
        Log.e(TAG, "Failed to restart camera preview.", e);
    }
}
 
Example #9
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 #10
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 #11
Source File: MainActivity.java    From Android-9-Development-Cookbook with MIT License 5 votes vote down vote up
private void startPreview(CameraCaptureSession session) {
    mCameraCaptureSession = session;
    mCaptureRequestBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
    HandlerThread backgroundThread = new HandlerThread("CameraPreview");
    backgroundThread.start();
    Handler backgroundHandler = new Handler(backgroundThread. getLooper());
    try {
        mCameraCaptureSession
                .setRepeatingRequest(mCaptureRequestBuilder.build(), null, backgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #12
Source File: DoorbellCamera.java    From androidthings-cameraCar with Apache License 2.0 5 votes vote down vote up
@Override
public void onCaptureCompleted(CameraCaptureSession session,
                               CaptureRequest request,
                               TotalCaptureResult result) {
    if (session != null) {
        session.close();
        mCaptureSession = null;
        Log.d(TAG, "CaptureSession closed");
    }
}
 
Example #13
Source File: Camera2Source.java    From Camera2Vision with Apache License 2.0 5 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 #14
Source File: CameraInfo.java    From MobileInfo with Apache License 2.0 5 votes vote down vote up
private static String getAvailableFaceDetectModes(int availableFaceDetectModes) {
    switch (availableFaceDetectModes) {
        case CaptureRequest.STATISTICS_FACE_DETECT_MODE_FULL:
            return "FULL";
        case CaptureRequest.STATISTICS_FACE_DETECT_MODE_SIMPLE:
            return "SIMPLE";
        case CaptureRequest.STATISTICS_FACE_DETECT_MODE_OFF:
            return "OFF";
        default:
            return UNKNOWN + "-" + availableFaceDetectModes;

    }
}
 
Example #15
Source File: Camera2CaptureCallbackSplitter.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
@Override
public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request,
                               TotalCaptureResult result) {
    for (CaptureCallback target : mRecipients) {
        target.onCaptureCompleted(session, request, result);
    }
}
 
Example #16
Source File: AutoStrategy.java    From CameraDemo with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
public void setCaptureRequest(CaptureRequest.Builder requestBuilder, CameraCaptureSession cameraCaptureSession, Handler handler) {
    requestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
    requestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);

    try {
        cameraCaptureSession.setRepeatingRequest(requestBuilder.build(),null,handler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #17
Source File: CameraThread.java    From CameraRecorder-android with MIT License 5 votes vote down vote up
/**
 * stop camera preview
 */
void stopPreview() {
    Log.v(TAG, "stopPreview:");
    isFlashTorch = false;
    if (requestBuilder != null) {
        requestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_OFF);
        try {
            cameraCaptureSession.setRepeatingRequest(requestBuilder.build(), null, null);
            cameraDevice.close();
            Log.v(TAG, "stopPreview: cameraDevice.close()");
        } catch (CameraAccessException e) {
            e.printStackTrace();
        }
    }
}
 
Example #18
Source File: Camera2BasicFragment.java    From opencv-documentscanner-android with Apache License 2.0 5 votes vote down vote up
/**
 * Run the precapture sequence for capturing a still image. This method should be called when
 * we get a response in {@link #mCaptureCallback} from {@link #lockFocus()}.
 */
private void runPrecaptureSequence() {
    try {
        // This is how to tell the camera to trigger.
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
                CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
        // Tell #mCaptureCallback to wait for the precapture sequence to be set.
        mState = STATE_WAITING_PRECAPTURE;
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #19
Source File: AndroidCameraCaptureSessionProxy.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
@Override
public void onCaptureProgressed(CameraCaptureSession session, CaptureRequest request,
                                CaptureResult partialResult)
{
    mCallback.onCaptureProgressed(AndroidCameraCaptureSessionProxy.this, request,
            partialResult);
}
 
Example #20
Source File: Camera2Handler.java    From Augendiagnose with GNU General Public License v2.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 = CameraState.STATE_WAITING_LOCK;

		mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
	}
	catch (CameraAccessException | IllegalStateException e) {
		mCameraCallback.onCameraError("Failed to lock focus", "loc1", e);
	}
}
 
Example #21
Source File: AFTriggerResult.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
@Override
public void update(CaptureResultProxy result)
{
    Integer afState = result.get(CaptureResult.CONTROL_AF_STATE);
    boolean done = mStateMachine.update(
            result.getFrameNumber(),
            result.getRequest().get(CaptureRequest.CONTROL_AF_TRIGGER),
            afState);
    if (done)
    {
        boolean inFocus = Objects.equal(afState, CaptureResult.CONTROL_AF_STATE_PASSIVE_FOCUSED)
                || Objects.equal(afState, CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED);
        mFutureResult.set(inFocus);
    }
}
 
Example #22
Source File: Camera2.java    From TikTok with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the internal state of flash to {@link #mFlash}.
 */
void updateFlash() {
    switch (mFlash) {
        case Constants.FLASH_OFF:
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                    CaptureRequest.CONTROL_AE_MODE_ON);
            mPreviewRequestBuilder.set(CaptureRequest.FLASH_MODE,
                    CaptureRequest.FLASH_MODE_OFF);
            break;
        case Constants.FLASH_ON:
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                    CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
            mPreviewRequestBuilder.set(CaptureRequest.FLASH_MODE,
                    CaptureRequest.FLASH_MODE_OFF);
            break;
        case Constants.FLASH_TORCH:
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                    CaptureRequest.CONTROL_AE_MODE_ON);
            mPreviewRequestBuilder.set(CaptureRequest.FLASH_MODE,
                    CaptureRequest.FLASH_MODE_TORCH);
            break;
        case Constants.FLASH_AUTO:
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                    CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
            mPreviewRequestBuilder.set(CaptureRequest.FLASH_MODE,
                    CaptureRequest.FLASH_MODE_OFF);
            break;
        case Constants.FLASH_RED_EYE:
            mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                    CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH_REDEYE);
            mPreviewRequestBuilder.set(CaptureRequest.FLASH_MODE,
                    CaptureRequest.FLASH_MODE_OFF);
            break;
    }
}
 
Example #23
Source File: CameraConstrainedHighSpeedCaptureSessionImpl.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public int setRepeatingBurst(List<CaptureRequest> requests, CaptureCallback listener,
        Handler handler) throws CameraAccessException {
    if (!isConstrainedHighSpeedRequestList(requests)) {
        throw new IllegalArgumentException(
            "Only request lists created by createHighSpeedRequestList() can be submitted to " +
            "a constrained high speed capture session");
    }
    return mSessionImpl.setRepeatingBurst(requests, listener, handler);
}
 
Example #24
Source File: CameraHelp2.java    From WeiXinRecordedDemo with MIT License 5 votes vote down vote up
public void openFlash(){
    try {
        previewRequestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_TORCH);
        CaptureRequest previewRequest = previewRequestBuilder.build();
        mCameraCaptureSession.setRepeatingRequest(previewRequest, null, mHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #25
Source File: CameraConstrainedHighSpeedCaptureSessionImpl.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public int captureBurstRequests(List<CaptureRequest> requests, Executor executor,
        CaptureCallback listener) throws CameraAccessException {
    if (!isConstrainedHighSpeedRequestList(requests)) {
        throw new IllegalArgumentException(
            "Only request lists created by createHighSpeedRequestList() can be submitted to " +
            "a constrained high speed capture session");
    }
    return mSessionImpl.captureBurstRequests(requests, executor, listener);
}
 
Example #26
Source File: Camera2Input.java    From EZFilter with MIT License 5 votes vote down vote up
@Override
public void takePhoto(boolean isFront, int degree, PhotoTakenCallback callback) {
    mIsFront = isFront;
    mDegree = degree;
    mPhotoTakenCallback = callback;

    CaptureRequest.Builder captureRequestBuilder;
    try {
        captureRequestBuilder = mCamera.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
        // 将ImageReader的surface作为CaptureRequest.Builder的目标
        captureRequestBuilder.addTarget(mImageReader.getSurface());
        // 自动对焦
        captureRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        // 自动曝光
        captureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
        // 设置照片方向
        if (mIsFront) {
            captureRequestBuilder.set(CaptureRequest.JPEG_ORIENTATION, 270);
        } else {
            captureRequestBuilder.set(CaptureRequest.JPEG_ORIENTATION, 90);
        }
        // 拍照
        CaptureRequest captureRequest = captureRequestBuilder.build();
        mCameraCaptureSession.capture(captureRequest, null, mPreviewHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #27
Source File: CameraNew.java    From aurora-imui with MIT License 5 votes vote down vote up
/**
 * Run the precapture sequence for capturing a still image. This method should be called when
 * we get a response in {@link #mCaptureCallback} from {@link #lockFocus()}.
 */
private void runPrecaptureSequence() {
    try {
        // This is how to tell the camera to trigger.
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER,
                CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
        // Tell #mCaptureCallback to wait for the precapture sequence to be set.
        mState = STATE_WAITING_PRECAPTURE;
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
                mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #28
Source File: Camera2.java    From SimpleVideoEditor with Apache License 2.0 5 votes vote down vote up
private void updateAutoFocus() {
    if (mConfig.isAutoFocus()) {
        CameraView.MODE mode = mConfig.getMode();
        if (mode == CameraView.MODE.PICTURE) {
            mCaptureRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                    CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        } else if (mode == CameraView.MODE.VIDEO) {
            mCaptureRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                    CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_VIDEO);
        }
    } else {
        mCaptureRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE,
                CaptureRequest.CONTROL_AF_MODE_MACRO);
    }
}
 
Example #29
Source File: Camera2Source.java    From Machine-Learning-Projects-for-Mobile-Applications with MIT License 5 votes vote down vote up
/**
 * Run the precapture sequence for capturing a still image. This method should be called when
 * we get a response in {@link #mCaptureCallback} from {@link #lockFocus()}.
 */
private void runPrecaptureSequence() {
    try {
        // This is how to tell the camera to trigger.
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_START);
        // Tell #mCaptureCallback to wait for the precapture sequence to be set.
        mState = STATE_WAITING_PRECAPTURE;
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}
 
Example #30
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);
    }
}