Mac macOS 10.14 Mojave Xcode opencv 调用摄像头权限错误 This app has crashed because it attempted to access privacy-sensitive data without a usage description.

更新了macOS 10.14 Mojave之后,使用opencv调用摄像头会产生权限错误,报错This app has crashed because it attempted to access privacy-sensitive data without a usage description.
原因是macOS 10.14加入了对所有程序的隐私权限管理,如果要涉及隐私权限,要在可执行程序旁边加入Info.plist且在里面注册摄像头权限。
在测试开发时,简单起见,只需要从别的程序里复制一个Info.plist文件移动到DerivedData\工程名\Build\Products\Debug目录下,且改动Info.plist,加入摄像头权限。

操作示例

这里从Mac自带程序Photo Booth里复制Info.plist,在应用程序文件夹里找到Photo Booth.app,右键选择显示包内容,文件夹里有一个Info.plist文件,拷贝到DerivedData\工程名\Build\Products\Debug目录下,用Xcode打开并编辑。原内容如下。Mac macOS 10.14 Mojave Xcode opencv 调用摄像头权限错误 This app has crashed because it attempted to...

删去其中的不必要的键值对,最后加入键Privacy - Camera Usage Description,值为YES,修改好后的Info.plist如下,其中cvModel为我的项目名。
Mac macOS 10.14 Mojave Xcode opencv 调用摄像头权限错误 This app has crashed because it attempted to...
然后编译,就能通过啦。
最后附上测试代码

//
//  main.cpp
//  cvModel
//
//  Created by Renzibei on 10/9/18.
//  Copyright © 2018 GF. All rights reserved.
//

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace cv;

int main(int argc, const char * argv[]) {
    VideoCapture cam(0);
    Mat image;
    cam >> image;
    imshow("test", image);
    waitKey(0);
    return 0;
}

相关文章:

  • 2022-12-23
  • 2021-11-20
  • 2021-09-19
  • 2021-04-07
  • 2021-11-11
  • 2022-12-23
  • 2021-12-30
猜你喜欢
  • 2021-04-07
  • 2021-08-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
相关资源
相似解决方案