【发布时间】:2019-01-16 09:29:08
【问题描述】:
我已经成功地为 android arm64-v8a 构建了 opencv(with ffmpeg),但是,cvCreateCameraCapture 返回 null。 cvCreateFileCapture 效果很好。我发现我们需要为支持相机设置以下项目:
-DWITH_V4L=1 -DHAVE_CAMV4L2=ON
现在,v4l 已经内置在 opencv 中。
但是,当app启动时,native源代码会通过opencv的函数cvCreateCameraCapture打开相机。 cap_libv4l.cpp(opencv的源代码)下面的接口无法成功打开设备。
static void icvInitCapture_V4L() {
//...
CameraNumber = 0;
while(CameraNumber < MAX_CAMERAS) {
/* Print the CameraNumber at the end of the string with a width of one character */
sprintf(deviceName, "/dev/video%1d", CameraNumber);
/* Test using an open to see if this new device name really does exists. */
deviceHandle = open(deviceName, O_RDONLY);
char* strno = strerror(errno);
LOGD("icvInitCapture_V4L wwwwwwwwwww %s !!\n", strno );
if (deviceHandle != -1) {
/* This device does indeed exist - add it to the total so far */
// add indexList
indexList|=(1 << CameraNumber);
numCameras++;
}
//...
}
由于权限被拒绝,该打开功能失败。
icvInitCapture_V4L wwwwwwwwwww 权限被拒绝!!
我认为我的 android 应用没有相关权限。但是,我在 AndroidManifest.xml 中添加了以下设置:
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera" android:required="false"/>
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
并且在我的应用程序的线程中调用了 opencv 函数。我的应用是针对 android 的服务。
我检查了关于 /dev/videoX 的权限如下。
1|gts4lltechn:/dev $ ls -l | grep video ls: ./event-log-tags: Permission denied
crw-rw---- 1 system camera 81, 0 2017-04-01 08:37 video0
crw-rw---- 1 system camera 81, 1 2017-04-01 08:37 video1
crw-rw---- 1 system camera 81, 2 2017-04-01 08:37 video2
crw-rw---- 1 system camera 81, 3 2017-04-01 08:37 video3
crw-rw---- 1 system camera 81, 32 2017-04-01 08:37 video32
crw-rw---- 1 system camera 81, 33 2017-04-01 08:37 video33
crw-rw---- 1 system camera 81, 4 2017-04-01 08:37 video4
crw-rw---- 1 system camera 81, 5 2017-04-01 08:37 video5
crw-rw---- 1 system camera 81, 6 2018-12-20 21:28 video6
如何解决我的应用的权限问题?
PS:在应用启动之前,我通过设置打开相机和存储的权限。
【问题讨论】:
标签: android opencv permissions camera native