ARCore与Camera2API共享摄像头时图像捕捉的问题。
创始人
2024-09-12 10:00:53
0

要解决这个问题,可以使用Google提供的CameraX插件。CameraX是一个简化了Camera2 API调用方式的库,可让开发人员更轻松地控制照相机的设置和捕获功能。

这里有一个使用CameraX和ARCore共享照相机的代码示例:

首先,在build.gradle中添加以下依赖项:

dependencies {
    // CameraX core library using camera2 implementation
    def camerax_version = "1.0.0-alpha06"
    implementation "androidx.camera:camera-core:${camerax_version}"
}

在Activity中,使用以下代码启动摄像头:

implementation 'androidx.camera:camera-camera2:1.0.0-beta04'
implementation 'androidx.camera:camera-lifecycle:1.0.0-beta04'

CameraManager cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);

// Get the ID of the camera
String cameraId = getFrontCameraId(cameraManager); // implement your method to select the necessary camera

// Create configuration object for the viewfinder use case
PreviewConfig previewConfig = new PreviewConfig.Builder()
                                   .setTargetAspectRatio(AspectRatio.RATIO_4_3)
                                   .setLensFacing(CameraX.LensFacing.FRONT)
                                   .build();

// Create a preview use case instance and bind it to the viewfinder
Preview preview = new Preview(previewConfig);
preview.setOnPreviewOutputUpdateListener(output -> {
    ViewGroup parent = (ViewGroup) findViewById(R.id.preview_view_container);
    parent.removeAllViews();
    parent.addView(output.getView());
});

// Create a photo capture use case instance
ImageCaptureConfig imageCaptureConfig = new ImageCaptureConfig.Builder().build();
ImageCapture imageCapture = new ImageCapture(imageCaptureConfig);

// Create an ImageAnalysis use case instance and set its analyzer
ImageAnalysisConfig imageAnalysisConfig =
            new ImageAnalysisConfig.Builder()
                      .setImageReaderMode(ImageAnalysis.ImageReaderMode.ACQUIRE_LATEST_IMAGE)
                      .build();
ImageAnalysis imageAnalysis = new ImageAnalysis(imageAnalysisConfig);
imageAnalysis.setAnalyzer(new MyImageAnalyzer());

CameraX.bindToLifecycle(this, preview

相关内容

热门资讯

4存在!浙江游戏大厅辅助工具(... 您好,浙江游戏大厅辅助工具这款游戏可以开挂的,确实是有挂的,需要了解加微【485275054】很多玩...
5自建房(pokermaste... 5自建房(pokermaster外挂)外挂透明挂辅助软件(透视)力荐教程(有挂规律)-哔哩哔哩,支持...
6个系统!德州wepower透... 1、6个系统!德州wepower透视辅助(数据工具)原来真的有挂(有挂技巧)-哔哩哔哩2、进入游戏-...
1个计算器!德扑线上创建房间(... 1个计算器!德扑线上创建房间(自定义房间)辅助透视(有挂秘诀)-哔哩哔哩;德扑线上创建房间是一种具有...
第3机器人(来玩app德州)外... 1、第3机器人(来玩app德州)外挂透明挂辅助APP(辅助挂)AI教程(揭秘有挂)-哔哩哔哩;详细教...
第七苹果版!功夫川麻将怎么刷好... 第七苹果版!功夫川麻将怎么刷好牌(透视)太坑了其实真的有挂(有挂分享)-哔哩哔哩1、下载好功夫川麻将...
第六个私人局!wepoke透明... 第六个私人局!wepoke透明挂辅助软件是真的(辅助挂)软件透明挂(有挂辅助)-哔哩哔哩1、让任何用...
第三个ai辅助!德州ai人工智... 德州ai人工智能赢率提升策略‌;第三个ai辅助!德州ai人工智能(计算胜率软件)透视辅助(有挂教程)...
五个教程!wpk辅助器是真的(... 五个教程!wpk辅助器是真的(德州辅助)其实真的有挂(有挂秘笈)-哔哩哔哩;原来确实真的有挂(需添加...
第四内置(wpk挂)外挂透明挂... 第四内置(wpk挂)外挂透明挂辅助app(辅助挂)黑科技教程(有挂总结)-哔哩哔哩;wpk挂是一种具...