简体   繁体   English

在Mac上安装OpenCV3

[英]OpenCV3 installation on Mac

I tried to install OpenCV3 for Mac with the following command in terminal: 我尝试在终端中使用以下命令安装OpenCV3 for Mac:

brew install opencv3 --with-contrib -with-ffmpeg

It repeatedly gets stuck at this point: 它一再陷入困境:

cmake .. -DCMAKE_C_FLAGS_RELEASE=-DNDEBUG -DCMAKE_CXX_FLAGS_RELEASE=-DNDEBUG -DCMAKE

Can someone please tell me how to fix this? 有人可以告诉我如何解决这个问题吗?

You need to install Xcode command line tools first. 您需要先安装Xcode命令行工具。 Go to the AppStore and download and install Xcode from Apple for free. 转到AppStore并免费从Apple下载并安装Xcode。

Then run: 然后运行:

xcode-select --install

to get make , cmake , and all the command-line development tools. 获取makecmake和所有命令行开发工具。


Also, consider adding the QuickTime back-end, by additionally specifying --with-qt5 , ie: 另外,考虑添加QuickTime后端,另外指定--with-qt5 ,即:

brew install opencv3 --with-contrib -with-ffmpeg --with-qt5

That gives you extra options to save the images you generate and display with the highgui module. 这为您提供了额外的选项来保存您生成的图像并使用highgui模块进行显示。

I also had the exact same issue. 我也有同样的问题。 Someone else had also reported this problem on the brew github, but they could also not reproduce the issue. 还有人在brew github上报告了这个问题 ,但他们也无法重现这个问题。 In my case though, it would go a step further and get stuck after calling make for hours : 在我的情况下,它会更进一步,并在调用make 几个小时后卡住:

cmake .. -DCMAKE_C_FLAGS_RELEASE=-DNDEBUG -DCMAKE_CXX_FLAGS_RELEASE=-DNDEBUG -DCMAKE
make

I went ahead and tracked the processes in the Activity Monitor on my Mac and found out that it kicks off a batch of clang processes in sequence on multiple threads. 我继续跟踪Mac上活动监视器中的进程,发现它在多个线程上按顺序启动了一批clang进程。 But I had several apps running that were robbing it of CPU and Memory resources. 但我有几个运行的应用程序正在抢夺它的CPU和内存资源。 So I shut down Safari, Finder, IDEs (XCode, PyCharm) etc, and this time it did complete. 所以我关闭了Safari,Finder,IDE(XCode,PyCharm)等,这次它完成了。

Solution : was to just let it run with as much CPU and memory overhead it needs. 解决方案 :只是让它运行所需的CPU和内存开销。 And with no other power-hungry apps running in the background, it finished in 25mins. 并且没有其他耗电的应用程序在后台运行,它在25分钟内完成。

CMake Approach: Your next best approach is to bypass using package manager, like brew, and follow the instructions given on PyImageSearch to build OpenCV manually using CMake: CMake方法:您的下一个最佳方法是绕过使用包管理器,如brew,并按照PyImageSearch上的说明使用CMake手动构建OpenCV:

  1. Install dependencies like CMake, pkg-config (and possibly others...) 安装依赖项,如CMake,pkg-config(可能还有其他...)
  2. Clone OpenCV and OpenCV_Contrib git repos: 克隆OpenCV和OpenCV_Contrib git repos:
    1. https://github.com/opencv/opencv https://github.com/opencv/opencv
    2. https://github.com/opencv/opencv_contrib https://github.com/opencv/opencv_contrib
  3. Checkout version [eg 3.2.0] 结帐版本[例如3.2.0]
  4. Make build directory inside opencv directory opencv目录中build目录
  5. Run CMake with the appropriate parameters for your system: 使用适合您系统的参数运行CMake:

    cmake -D CMAKE_BUILD_TYPE=RELEASE \\ -D CMAKE_INSTALL_PREFIX=/usr/local/opencv3 \\ -D PYTHON2_PACKAGES_PATH=/usr/local/lib/python2.7/site-packages \\ -D PYTHON2_LIBRARY=/usr/local/opt/python/bin \\ -D PYTHON2_INCLUDE_DIR=/usr/local/Frameworks/Python.framework/Headers \\ -D BUILD_OPENCV_PYTHON2=ON \\ -D INSTALL_C_EXAMPLES=OFF \\ -D INSTALL_PYTHON_EXAMPLES=OFF \\ -D BUILD_EXAMPLES=OFF \\ -D OPENCV_EXTRA_MODULES_PATH=/Users/Salman_Naqvi/Downloads/opencv_contrib/modules ..

  6. Compile using: make -j4 使用: make -j4编译

  7. Install it on MacOS: make install 在MacOS上make installmake install

--> It'll be installed in the directory specified by: CMAKE_INSTALL_PREFIX=/usr/local/opencv3 - >它将安装在由以下指定的目录中: CMAKE_INSTALL_PREFIX=/usr/local/opencv3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM