我使用Android OpenCV .2.4.3.2和Galaxy Nexus手机。当我运行示例"教程5 -相机控制"时,我可以看到预览很好,可以使用选项菜单更改颜色等。
但是,当我触摸屏幕拍照时,应用程序崩溃了。
然后,当我尝试使用任何应用程序再次使用相机时,我得到"相机错误:无法连接到相机"。我只能通过关机再开机来再次使用相机。
我没有更改提供的示例中的任何代码。什么好主意吗?
谢谢!
当我试图拍照时崩溃的日志:
I/JavaCameraView(1278): Preview Frame received. Need to create MAT and deliver it to clients
I/JavaCameraView(1278): Frame size is 1036800
I/OCVSample::Activity(1278): onTouch event
I/Sample::SampleJavaCameraView(1278): Tacking picture
I/InputDispatcher(220): Application is not responding: Window{41bfb328 org.opencv.samples.tutorial5/org.opencv.samples.tutorial5.Sample5CameraControl paused=false}. 5006.3ms since event,5005.7ms since wait started
I/WindowManager(220): Input event dispatching timed out sending to org.opencv.samples.tutorial5/org.opencv.samples.tutorial5.Sample5CameraControl
I/Process(220): Sending signal. PID: 1278 SIG: 3
I/dalvikvm(1278): threadid=3: reacting to signal 3
I/dalvikvm(1278): Wrote stack traces to '/data/anr/traces.txt'
I/Process(220): Sending signal. PID: 220 SIG: 3
I/dalvikvm(220): threadid=3: reacting to signal 3
I/dalvikvm(220): Wrote stack traces to '/data/anr/traces.txt'
I/Process(220): Sending signal. PID: 426 SIG: 3
I/dalvikvm(426): threadid=3: reacting to signal 3
I/dalvikvm(426): Wrote stack traces to '/data/anr/traces.txt'
I/Process(220): Sending signal. PID: 301 SIG: 3
I/dalvikvm(301): threadid=3: reacting to signal 3
I/dalvikvm(301): Wrote stack traces to '/data/anr/traces.txt'
I/Process(220): Sending signal. PID: 440 SIG: 3
I/dalvikvm(440): threadid=3: reacting to signal 3
I/dalvikvm(440): Wrote stack traces to '/data/anr/traces.txt'
D/dalvikvm(220): GC_CONCURRENT freed 597K, 9% free 17508K/19143K, paused 3ms+4ms
D/dalvikvm(220): GC_EXPLICIT freed 153K, 9% free 17529K/19143K, paused 2ms+3ms
E/ActivityManager(220): ANR in org.opencv.samples.tutorial5 (org.opencv.samples.tutorial5/.Sample5CameraControl)
E/ActivityManager(220): Reason: keyDispatchingTimedOut
E/ActivityManager(220): Load: 0.51 / 0.29 / 0.11
E/ActivityManager(220): CPU usage from 12987ms to 0ms ago with 99% awake:
E/ActivityManager(220): 58% 1278/org.opencv.samples.tutorial5: 51% user + 6.9% kernel / faults: 57446 minor
E/ActivityManager(220): 26% 120/mediaserver: 24% user + 1.3% kernel
E/ActivityManager(220): 1.8% 220/system_server: 1% user + 0.7% kernel / faults: 69 minor
E/ActivityManager(220): 1.6% 117/surfaceflinger: 0.7% user + 0.8% kernel / faults: 10 minor
E/ActivityManager(220): 1.5% 126/adbd: 0.3% user + 1.1% kernel / faults: 39 minor
E/ActivityManager(220): 0.9% 4/kworker/0:0: 0% user + 0.9% kernel
E/ActivityManager(220): 0.8% 1121/logcat: 0.4% user + 0.3% kernel
E/ActivityManager(220): 0.6% 23/kinteractiveup: 0.6% user + 0% kernel
E/ActivityManager(220): 0.6% 76/kworker/u:2: 0% user + 0.6% kernel
E/ActivityManager(220): 0.5% 68/kworker/1:1: 0% user + 0.5% kernel
E/ActivityManager(220): 0.1% 53/kworker/u:1: 0% user + 0.1% kernel
E/ActivityManager(220): 0.3% 5/kworker/u:0: 0% user + 0.3% kernel
E/ActivityManager(220): 0.1% 77/kworker/u:3: 0% user + 0.1% kernel
E/ActivityManager(220): 0% 426/com.android.phone: 0% user + 0% kernel / faults: 16 minor
E/ActivityManager(220): 46% TOTAL: 39% user + 6.3% kernel + 0% iowait + 0% softirq
E/ActivityManager(220): CPU usage from 371ms to 883ms later with 99% awake:
E/ActivityManager(220): 5.7% 220/system_server: 0% user + 5.7% kernel
E/ActivityManager(220): 3.8% 257/InputDispatcher: 0% user + 3.8% kernel
E/ActivityManager(220): 1.3% 68/kworker/1:1: 0% user + 1.3% kernel
E/ActivityManager(220): 1.3% 76/kworker/u:2: 0% user + 1.3% kernel
E/ActivityManager(220): 2.9% TOTAL: 0% user + 2.9% kernel
I/WindowManager(220): createSurface Window{41c0d8f0 paused=false}: DRAW NOW PENDING
当我尝试在崩溃后再次使用相机时的日志:
D/OpenGLRenderer(303): Flushing caches (mode 0)
V/CameraHolder(1463): open camera 0
W/CameraService(119): CameraService::connect X (pid 1463) rejected (existing client).
E/CameraHolder(1463): fail to connect Camera
E/CameraHolder(1463): java.lang.RuntimeException: Fail to connect to camera service
E/CameraHolder(1463): at android.hardware.Camera.native_setup(Native Method)
E/CameraHolder(1463): at android.hardware.Camera.<init>(Camera.java:302)
E/CameraHolder(1463): at android.hardware.Camera.open(Camera.java:264)
E/CameraHolder(1463): at com.android.camera.CameraHolder.open(CameraHolder.java:131)
E/CameraHolder(1463): at com.android.camera.Util.openCamera(Util.java:267)
E/CameraHolder(1463): at com.android.camera.Camera$4.run(Camera.java:1008)
E/CameraHolder(1463): at java.lang.Thread.run(Thread.java:856)
它看起来像是应用程序试图在UI线程中保存照片并阻止它(Application is not responding...
第一次日志输出的一部分)
破碎的应用程序不会释放相机,所以当你试图再次访问它时,你会得到错误。
尝试将照片保存部分移动到另一个线程-应该可以。