#android #tensorflow #raspberry-pi #android-things
#Android #tensorflow #raspberry-pi #android-things
Вопрос:
Я пытался реализовать активность детектора tensorflow-demo в Android things, но просто появляется черный экран. вот некоторый код во фрагменте подключения к камере
private void createCameraPreviewSession() {
try {
final SurfaceTexture texture = textureView.getSurfaceTexture();
assert texture != null;
// We configure the size of default buffer to be the size of camera preview we want.
texture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight());
// This is the output Surface we need to start preview.
final Surface surface = new Surface(texture);
// We set up a CaptureRequest.Builder with the output Surface.
previewRequestBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
previewRequestBuilder.addTarget(surface);
LOGGER.i("Opening camera preview: " previewSize.getWidth() "x" previewSize.getHeight());
// Create the reader for the preview frames.
previewReader =
ImageReader.newInstance(
previewSize.getWidth(), previewSize.getHeight(), ImageFormat.YUV_420_888, 2);
previewReader.setOnImageAvailableListener(imageListener, backgroundHandler);
previewRequestBuilder.addTarget(previewReader.getSurface());
// Here, we create a CameraCaptureSession for camera preview.
/* cameraDevice.createCaptureSession(
Arrays.asList(surface),
new CameraCaptureSession.StateCallback() {*/
cameraDevice.createCaptureSession(
Arrays.asList(surface, previewReader.getSurface()),
new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(final CameraCaptureSession cameraCaptureSession) {
// The camera is already closed
if (null == cameraDevice) {
return;
}
// When the session is ready, we start displaying the preview.
captureSession = cameraCaptureSession;
try {
// Auto focus should be continuous for camera preview.
previewRequestBuilder.set(
CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
// Flash is automatically enabled when necessary.
previewRequestBuilder.set(
CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
// Finally, we start displaying the camera preview.
previewRequest = previewRequestBuilder.build();
captureSession.setRepeatingRequest(
previewRequest, captureCallback, backgroundHandler);
} catch (final CameraAccessException e) {
LOGGER.e(e, "Exception!");
}
}
@Override
public void onConfigureFailed(final CameraCaptureSession cameraCaptureSession) {
showToast("Failed");
}
},
null);
} catch (final CameraAccessException e) {
LOGGER.e(e, "Exception!");
} }
и вот его логарифм
2019-04-24 13:55:00.735 5046-5046/org.tensorflow.demo I/TensorFlowInferenceInterface: Checking to see if TensorFlow native methods are already loaded
2019-04-24 13:55:00.736 5046-5046/org.tensorflow.demo E/zygote: No implementation found for long org.tensorflow.contrib.android.RunStats.allocate() (tried Java_org_tensorflow_contrib_android_RunStats_allocate and Java_org_tensorflow_contrib_android_RunStats_allocate__)
2019-04-24 13:55:00.736 5046-5046/org.tensorflow.demo I/TensorFlowInferenceInterface: TensorFlow native methods not found, attempting to load via tensorflow_inference
2019-04-24 13:55:01.132 5046-5046/org.tensorflow.demo I/TensorFlowInferenceInterface: Successfully loaded TensorFlow native methods (RunStats error may be ignored)
2019-04-24 13:55:04.607 5046-5046/org.tensorflow.demo I/TensorFlowInferenceInterface: Model load took 1718ms, TensorFlow version: 1.13.1
2019-04-24 13:55:04.614 5046-5046/org.tensorflow.demo I/TensorFlowInferenceInterface: Successfully loaded model from 'file:///android_asset/frozen_inference_graph.pb'
2019-04-24 13:55:04.618 5046-5046/org.tensorflow.demo I/tensorflow: DetectorActivity: Camera orientation relative to screen canvas: -270
2019-04-24 13:55:04.619 5046-5046/org.tensorflow.demo I/tensorflow: DetectorActivity: Initializing at size 640x480
2019-04-24 13:55:04.669 5046-5046/org.tensorflow.demo W/tensorflow: ImageUtils: Native library not found, native RGB -> YUV conversion may be unavailable.
2019-04-24 13:55:04.698 5046-5091/org.tensorflow.demo I/tensorflow: CameraConnectionFragment: Opening camera preview: 640x480
2019-04-24 13:55:04.830 5046-5091/org.tensorflow.demo W/CameraDevice-JV-0: Stream configuration failed due to: endConfigure:372: Camera 0: Unsupported set of inputs/outputs provided
2019-04-24 13:55:04.854 5046-5091/org.tensorflow.demo E/CameraCaptureSession: Session 0: Failed to create capture session; configuration failed
2019-04-24 13:55:05.895 5046-5094/org.tensorflow.demo D/vndksupport: Loading /vendor/lib/hw/android.hardware.graphics.mapper@2.0-impl.so from current namespace instead of sphal namespace.
когда я запускаю тот же код на мобильном устройстве, он показывает предварительный просмотр камеры. вот logcat
22508-22508/org.tensorflow.demo I/TensorFlowInferenceInterface: Checking to see if TensorFlow native methods are already loaded
2019-04-24 15:04:09.397 22508-22508/org.tensorflow.demo E/zygote64: No implementation found for long org.tensorflow.contrib.android.RunStats.allocate() (tried Java_org_tensorflow_contrib_android_RunStats_allocate and Java_org_tensorflow_contrib_android_RunStats_allocate__)
2019-04-24 15:04:09.397 22508-22508/org.tensorflow.demo I/TensorFlowInferenceInterface: TensorFlow native methods not found, attempting to load via tensorflow_inference
2019-04-24 15:04:09.468 22508-22508/org.tensorflow.demo I/TensorFlowInferenceInterface: Successfully loaded TensorFlow native methods (RunStats error may be ignored)
2019-04-24 15:04:10.838 22508-22508/org.tensorflow.demo I/TensorFlowInferenceInterface: Model load took 984ms, TensorFlow version: 1.13.1
2019-04-24 15:04:10.841 22508-22508/org.tensorflow.demo I/TensorFlowInferenceInterface: Successfully loaded model from 'file:///android_asset/frozen_inference_graph.pb'
2019-04-24 15:04:10.844 22508-22508/org.tensorflow.demo I/tensorflow: DetectorActivity: Camera orientation relative to screen canvas: 90
2019-04-24 15:04:10.846 22508-22508/org.tensorflow.demo I/tensorflow: DetectorActivity: Initializing at size 640x480
2019-04-24 15:04:10.875 22508-22520/org.tensorflow.demo I/zygote64: Do partial code cache collection, code=30KB, data=21KB
2019-04-24 15:04:10.877 22508-22520/org.tensorflow.demo I/zygote64: After code cache collection, code=23KB, data=18KB
2019-04-24 15:04:10.877 22508-22520/org.tensorflow.demo I/zygote64: Increasing code cache capacity to 128KB
2019-04-24 15:04:10.882 22508-22508/org.tensorflow.demo W/tensorflow: ImageUtils: Native library not found, native RGB -> YUV conversion may be unavailable.
2019-04-24 15:04:10.936 22508-22508/org.tensorflow.demo I/PermissionManager: camera remind result:true
2019-04-24 15:04:10.936 22508-22508/org.tensorflow.demo I/CameraManager: open camera: 0, package name: org.tensorflow.demo
2019-04-24 15:04:10.936 22508-22508/org.tensorflow.demo I/HwSystemManager: pkgName = org.tensorflow.demo pid = 22508uidOf3RdApk = 10158permType = 0permCfg=1
2019-04-24 15:04:10.937 22508-22508/org.tensorflow.demo I/BackgroundPermManager: pkgName: org.tensorflow.demo,pid: 22508 ,uidOf3RdApk: 10158 ,permType: 0 ,permCfg: 1
2019-04-24 15:04:10.943 22508-22529/org.tensorflow.demo I/CameraManagerGlobal: single back camera, do not need hide aux camera, device number: 2
2019-04-24 15:04:10.943 22508-22529/org.tensorflow.demo I/CameraManagerGlobal: single back camera, do not need hide aux camera, device number: 2
2019-04-24 15:04:11.003 22508-22540/org.tensorflow.demo I/tensorflow: CameraConnectionFragment: Opening camera preview: 640x480
2019-04-24 15:04:11.008 22508-22540/org.tensorflow.demo E/BufferQueueProducer: [] Can not get hwsched service
2019-04-24 15:04:11.130 22508-22508/org.tensorflow.demo W/InputMethodManager: startInputReason = 5
2019-04-24 15:04:11.132 22508-22508/org.tensorflow.demo I/Choreographer: Skipped 104 frames! The application may be doing too much work on its main thread.
2019-04-24 15:04:11.429 22508-22540/org.tensorflow.demo D/tensorflow: CameraActivity: Initializing buffer 0 at size 307200
2019-04-24 15:04:11.431 22508-22540/org.tensorflow.demo D/tensorflow: CameraActivity: Initializing buffer 1 at size 153599
2019-04-24 15:04:11.434 22508-22540/org.tensorflow.demo D/tensorflow: CameraActivity: Initializing buffer 2 at size 153599
Я предполагаю, что с размером предварительного просмотра проблем нет, поскольку из обоих результатов в logcat он открывается с одинаковым размером предварительного просмотра камеры 640 x 480