简体   繁体   English

无法在 M1 Mac 上安装 OpenCV Python

[英]Unable to install OpenCV Python on M1 Mac

I've been following this thread ( https://trayansh.medium.com/setting-machine-learning-environment-on-m1-mac-apple-silicon-959836bf494d ), successfully installed TensorFlow but while making the config file(Cmake Command) for openCV it is giving me an error:-我一直在关注这个线程( https://trayansh.medium.com/setting-machine-learning-environment-on-m1-mac-apple-silicon-959836bf494d ),成功安装了 TensorFlow 但同时制作了配置文件(Cmake命令)对于 openCV,它给了我一个错误:-

CMake Error at cmake/OpenCVModule.cmake:354 (message):
  Duplicated modules LOCATIONS has been found
Call Stack (most recent call first):
  cmake/OpenCVModule.cmake:371 (_assert_uniqueness)
  modules/CMakeLists.txt:7 (ocv_glob_modules)

I've been trying to install it for two days now and no progress.我已经尝试安装它两天了,但没有任何进展。 :( :(

The CMake command I used was我使用的 CMake 命令是

cmake \
-DCMAKE_SYSTEM_PROCESSOR=arm64 \
-DCMAKE_OSX_ARCHITECTURES=arm64 \
-DWITH_OPENJPEG=OFF \
-DWITH_IPP=OFF \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=/Users/yashdhingra/Documents/Python/opencompile/opencv-4.5.0/modules \
-D PYTHON3_EXECUTABLE=/opt/homebrew/Caskroom/miniforge/base/envs/MLenv/python3 \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_ENABLE_NONFREE=ON \
-D BUILD_EXAMPLES=ON ..

I did change the path of the modules and the Virtual Env_python as instructed in the guide.我确实按照指南中的说明更改了模块和 Virtual Env_python 的路径。

This CMake error (Duplicated modules LOCATIONS has been found) is because you point the extra modules path to the main opencv module you are trying to build from.这个 CMake 错误(已发现重复的模块位置)是因为您将额外的模块路径指向您尝试构建的主要 opencv 模块。 You need to set the extra modules path to opencv-contrib and not opencv.您需要将额外的模块路径设置为 opencv-contrib 而不是 opencv。

OPENCV_EXTRA_MODULES_PATH=/Users/yashdhingra/Documents/Python/opencompile/ opencv_contrib-4.5.0 /modules OPENCV_EXTRA_MODULES_PATH=/Users/yashdhingra/Documents/Python/opencompile/ opencv_contrib-4.5.0 /modules

You have perhaps copied the extra modules into the main module directory, and then are using -D OPENCV_EXTRA_MODULES_PATH=/opt/OpenCV3.4/modules to locate this.您可能已将额外的模块复制到主模块目录中,然后使用 -D OPENCV_EXTRA_MODULES_PATH=/opt/OpenCV3.4/modules 来定位它。 But the module locator looks at ALL the modules that are in a directory;但是模块定位器会查看目录中的所有模块; and then it also requires each module to be unique and seen only once.然后它还要求每个模块都是唯一的并且只能看到一次。 Since the cmake looks at all the modules in the main /module directory by default, and then looks at all the modules in the EXTRA_MODULES path again when you specify this cmake option, it gets confused, and thinks it is seeing the exact same modules twice, and then barfs.由于 cmake 默认查看主 /module 目录中的所有模块,然后在指定此 cmake 选项时再次查看 EXTRA_MODULES 路径中的所有模块,因此它会感到困惑,并认为它看到了两次完全相同的模块,然后是巴夫。

Solution 1: Simply don't specify -D OPENCV_EXTRA_MODULES_PATH=/opt/OpenCV3.4/modules in your cmake instructions if you have included all extra modules into the default system module file by hand.解决方案 1:如果您手动将所有额外模块包含到默认系统模块文件中,只需不要在 cmake 指令中指定 -D OPENCV_EXTRA_MODULES_PATH=/opt/OpenCV3.4/modules。 It will only review this directory once, and will happily compile all of them.它只会审查这个目录一次,并且会很高兴地编译所有这些目录。

Solution 2: Keep the extra modules in their own separate directory, and specify cmake option -D OPENCV_EXTRA_MODULES_PATH=/my_extra_modules_directory which is separate from the main /modules directory.解决方案 2:将额外的模块保存在它们自己的单独目录中,并指定 cmake 选项 -D OPENCV_EXTRA_MODULES_PATH=/my_extra_modules_directory 与主 /modules 目录分开。

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

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