当我在android studio上处于调试模式时,我发现在iamgecaputre.takepicture()发生后,代码没有进入onimagesaved()。好像它在告诉我图像根本没有被捕获和保存。它也没有进入onerror()。我正在为temi robot编程,以便为我的自定义对象检测模型收集数据集。
如果有人能帮我指出我在这里犯的错误,那就太好了。提前谢谢。
主要代码
private void setupCameraX() {
ListenableFuture<ProcessCameraProvider> cameraProviderFuture =
ProcessCameraProvider.getInstance(this);
cameraProviderFuture.addListener(() -> {
try {
ProcessCameraProvider cameraProvider = cameraProviderFuture.get();
PreviewView previewView = findViewById(R.id.preview_view);
final Preview preview = new Preview.Builder()
.setTargetRotation(Surface.ROTATION_270)
.build();
CameraSelector cameraSelector = new CameraSelector
.Builder()
.requireLensFacing(CameraSelector.LENS_FACING_FRONT)
.build();
preview.setSurfaceProvider(previewView.getSurfaceProvider());
executor = Executors.newCachedThreadPool();
imageCapture = new ImageCapture
.Builder()
.setTargetRotation(Surface.ROTATION_270)
.setIoExecutor(executor)
.setCaptureMode(ImageCapture.CAPTURE_MODE_MAXIMIZE_QUALITY)
.build();
cameraProvider.unbindAll();
cameraProvider.bindToLifecycle(
this,
cameraSelector,
imageCapture,
preview);
findViewById(R.id.imageCaptureButton).setOnClickListener(v -> {
this.captureAnImage();
});
} catch (InterruptedException | ExecutionException e) {
new AlertDialog
.Builder(this)
.setTitle("Camera setup error")
.setMessage(e.getMessage())
.setPositiveButton("Ok",
(dialog, which) -> {
})
.show();
}
}, ContextCompat.getMainExecutor(this));
}
private void captureAnImage() {
ImageCapture.OutputFileOptions outputFileOptions = new ImageCapture
.OutputFileOptions
.Builder(new File("TrainingData"))
.build();
imageCapture.takePicture(outputFileOptions,
executor,
new ImageCapture.OnImageSavedCallback() {
@Override
public void onImageSaved(
@NotNull ImageCapture.OutputFileResults outputFileResults) {
Log.d("imagePathname", "Path: " + outputFileResults.toString());
}
@Override
public void onError(@NotNull ImageCaptureException exception) {
exception.printStackTrace();
}
});
}
androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.FallDetectionAITrainingCamera">
<meta-data
android:name="com.robotemi.sdk.metadata.SKILL"
android:value="@string/app_name" />
<activity android:name="org.FallPreventionAITrainingCamera.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
格雷德尔先生
android{编译SDK版本30构建工具版本“30.0.3”
defaultConfig {
applicationId "org.FallDetectionAITrainingCamera"
minSdkVersion 22
targetSdkVersion 30
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
依赖关系{
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
def camerax_version = "1.0.0"
implementation "androidx.camera:camera-core:$camerax_version"
implementation "androidx.camera:camera-camera2:$camerax_version"
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
implementation "androidx.camera:camera-view:1.0.0-alpha26"
implementation "com.google.android.material:material:1.4.0"
implementation 'com.robotemi:sdk:0.10.77'
}
更新我已尝试以下代码,但它们不起作用:
SimpleDateFormat formatter = (SimpleDateFormat) SimpleDateFormat.getDateTimeInstance();
Date date = new Date();
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME,
"Fall Prevention Training Data " + formatter.format(date));
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/jpeg");
ImageCapture.OutputFileOptions outputFileOptions = new ImageCapture
.OutputFileOptions .Builder(getContentResolver(),MediaStore.Images.Media.EXTERNAL_CONTENT_URI,contentValues)
.build();
更新我不包含这些日志的信息:
D/CaptureSession: Issuing capture request.
W/LegacyRequestMapper: convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
Only received metering rectangles with weight 0.
W/LegacyRequestMapper: convertRequestToMetadata - Ignoring android.lens.focusDistance false, only 0.0f is supported
E/RequestThread-1: Hit timeout for jpeg callback!
W/CaptureCollector: Jpeg buffers dropped for request: 1
E/CameraDevice-JV-1: Lost output buffer reported for frame 116
W/LegacyRequestMapper: convertRequestMetadata - control.awbRegions setting is not supported, ignoring value
Only received metering rectangles with weight 0.
W/LegacyRequestMapper: convertRequestToMetadata - Ignoring android.lens.focusDistance false, only 0.0f is supported
I/RequestThread-1: Received jpeg.
W/CaptureCollector: jpegProduced called with no jpeg request on queue!
E/RequestThread-1: Dropping jpeg frame.
更新
升级到camerax1.10-alpha06无法工作。
<uses-feature android:name="android.hardware.camera" />
<!-- Register as a system camera app -->
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<action android:name="android.media.action.STILL_IMAGE_CAMERA"/>
<action android:name="android.media.action.VIDEO_CAMERA" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
我试过了 user-feature
及 intent filter
但这是行不通的
编辑:
我想这里的主要问题是日志,为什么requestthread-1:hit timeout for jpeg回调?
暂无答案!
目前还没有任何答案,快来回答吧!