无法在运行AndroidThings的Raspberry Pi上使用Android Camera(1)API连接相机

时间:2018-05-05 11:12:53

标签: raspberry-pi android-things

我正在尝试使用附带Raspberry Pi Camera V2的运行Android Things 0.7版本的Raspberry Pi上运行带有QR码扫描程序的标准Android应用程序。

应用程序和QR扫描程序在大多数Android手机(Lollipop +)上运行良好。

在Android Things上我可以加载应用程序并登录正常,但是当我打开QR扫描仪选项卡时,我遇到了崩溃。这很奇怪,因为检测到相机(Camera.getNumberOfCameras()= 1)并且相机看起来具有正面方向(cameraInfo.facing = 1),但是当我尝试打开相机时我得到RuntimeException:连接失败到相机服务(见下面的stacktrace)。请注意,我使用Rx在后台线程上打开相机:

[C:CameraSource] [M:getIdForRequestedCamera] [L:836]: numberOfCameras = 1
[C:CameraSource] [M:getIdForRequestedCamera] [L:839]: id 0, cameraInfo.facing = 1
W/CameraBase: An error occurred while connecting to camera 0: Status(-8): '10: connectHelper:1399: Failed to initialize camera "0": No such device (-19)'
W/System.err: io.reactivex.exceptions.OnErrorNotImplementedException: Fail to connect to camera service
W/System.err:     at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:704)
W/System.err:     at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:701)
W/System.err:     at io.reactivex.internal.observers.ConsumerSingleObserver.onError(ConsumerSingleObserver.java:45)
W/System.err:     at io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.onError(SingleSubscribeOn.java:73)
W/System.err:     at io.reactivex.internal.operators.single.SingleFromCallable.subscribeActual(SingleFromCallable.java:43)
W/System.err:     at io.reactivex.Single.subscribe(Single.java:2700)
W/System.err:     at io.reactivex.internal.operators.single.SingleSubscribeOn$SubscribeOnObserver.run(SingleSubscribeOn.java:89)
W/System.err:     at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:452)
W/System.err:     at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:61)
W/System.err:     at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:52)
W/System.err:     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
W/System.err:     at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
W/System.err:     at java.lang.Thread.run(Thread.java:764)
W/System.err: Caused by: java.lang.RuntimeException: Fail to connect to camera service
W/System.err:     at android.hardware.Camera.<init>(Camera.java:519)
W/System.err:     at android.hardware.Camera.open(Camera.java:365)

另请注意,我使用的是旧版Android Camera(1)API。

我遇到了一个错误报告,其中有人试图在AndroidThings / Rpi上运行带有Camera(1)API的Android应用程序。他们能够连接到相同的Raspberry Pi相机,但预览有一些问题:https://issuetracker.google.com/issues/37130806 (更多信息https://plus.google.com/u/0/+PeterMeijer1/posts/1SKZGiP9jLrhttps://plus.google.com/+RonaldVanDerLingen/posts/TE4JtJbHWqF

玩过针对AndroidThings的Google Doorbell示例应用程序,似乎我可能需要实现Camera2 API。但是,看起来有些人使用Camera(1)API取得了成功。

最重要的是,我想知道为什么会检测到相机,但是当我尝试打开它时,我会得到“没有这样的设备”。

以下是代码:

private static int getIdForRequestedCamera(int facing) {
    CameraInfo cameraInfo = new CameraInfo();
    for (int i = 0; i < Camera.getNumberOfCameras(); ++i) {
        Camera.getCameraInfo(i, cameraInfo);
        if (cameraInfo.facing == facing) {
            return i;
        }
    }
    return -1;
}

private Camera createCamera() {
        int requestedCameraId = getIdForRequestedCamera(mFacing);
        if (requestedCameraId == -1) {
            throw new RuntimeException("Could not find requested 
camera.");
            }
            Camera camera = Camera.open(requestedCameraId);
...
}

0 个答案:

没有答案