以下的代码片段是从摄像头中获取视频帧,但是里面使用到了AutoFitTextureView,这样的话就需要预览才可以获取视频帧。但是机器人识别中不需要,这样要怎么处理呢?
- // 创建捕获图片session
- private void createCaptureSession() {
- try {
- final SurfaceTexture texture = mTextureView.getSurfaceTexture();
- texture.setDefaultBufferSize(mPreviewSize.getWidth(), mPreviewSize.getHeight());
-
- final Surface surface = new Surface(texture);
- final CaptureRequest.Builder captureRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
- captureRequestBuilder.addTarget(surface);
-
- mImageReader = ImageReader.newInstance(
- mPreviewSize.getWidth(), mPreviewSize.getHeight(), ImageFormat.JPEG, 10);
-
- mCameraDevice.createCaptureSession(
- Arrays.asList(surface, mImageReader.getSurface()),
- new CameraCaptureSession.StateCallback() {
-
- @Override
- public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
- if (null == mCameraDevice) {
- return;
- }
-
- mCaptureSession = cameraCaptureSession;
- try {
- 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);
-
- CaptureRequest previewRequest = captureRequestBuilder.build();
- mCaptureSession.setRepeatingRequest(
- previewRequest, new CameraCaptureSession.CaptureCallback() {
- @Override
- public void onCaptureProgressed(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull CaptureResult partialResult) {
- super.onCaptureProgressed(session, request, partialResult);
- }
-
- @Override
- public void onCaptureFailed(@NonNull CameraCaptureSession session, @NonNull CaptureRequest request, @NonNull CaptureFailure failure) {
- super.onCaptureFailed(session, request, failure);
- Log.d(TAG, "onCaptureFailed = " + failure.getReason());
- }
-
- @Override
- public void onCaptureSequenceCompleted(@NonNull CameraCaptureSession session, int sequenceId, long frameNumber) {
- super.onCaptureSequenceCompleted(session, sequenceId, frameNumber);
- Log.d(TAG, "onCaptureSequenceCompleted");
- }
- }, mCaptureHandler);
- } catch (final CameraAccessException e) {
- Log.e(TAG, "onConfigured exception ", e);
- }
- }
-
- @Override
- public void onConfigureFailed(@NonNull final CameraCaptureSession cameraCaptureSession) {
- Log.e(TAG, "onConfigureFailed ");
- }
- },
- null);
- } catch (final CameraAccessException e) {
- Log.e(TAG, "创建捕获图片session异常 ", e);
- }
- }