简体   繁体   English

无法在Mac上安装OpenCv:/ usr / local中没有文件

[英]Can't install OpenCv on Mac: there are no files in /usr/local

I've downloaded tar.gz files from official site(versions 2.4.3, 2.4.7, 2.4.8). 我已经从官方网站(版本2.4.3、2.4.7、2.4.8)下载了tar.gz文件。 Then unzipped them somewhere. 然后将它们解压缩到某个地方。

mac-mini-olia:Data olia$ cd opencv-2.4.6.1/
mac-mini-olia:opencv-2.4.6.1 olia$ mkdir build
mac-mini-olia:opencv-2.4.6.1 olia$ cd build/
mac-mini-olia:build olia$ cmake -G "Unix Makefiles" ..
mac-mini-olia:build olia$ make -j8

after the last command output is 3910 warnings and 12 errors generated. 在最后一个命令输出之后是3910警告和12错误生成。 Errors are like 错误就像

/Volumes/Data/opencv-2.4.6.1/3rdparty/libjpeg/._jcapimin.c:1:4096: error: source file is not valid UTF-8

and

/Volumes/Data/opencv-2.4.6.1/3rdparty/libpng/._pngerror.c:1:2: error: expected identifier or '('

And after that in /usr/local/lib and /usr/local/include there are no files of opencv. 之后,在/ usr / local / lib/ usr / local / include中没有opencv文件。

There are multiple ways to install OpenCV on OSX. 有多种方法可以在OSX上安装OpenCV。 You can use MacPorts Make sure you have XCode installed with it's Command Line Tools first. 您可以使用MacPorts确保首先安装了XCode及其命令行工具。 (An easy way to test that is to see if xcodebuild if a found command in Terminal) (一种简单的测试方法是查看是否在终端中找到了xcodebuild命令)

After you install MacPorts simply do 安装MacPorts之后,只需

sudo port install opencv

This will take care of building the project from source and installing it for you. 这将帮助您从源代码构建项目并为您安装项目。 (The path might be /opt/local/lib /opt/local/include though, haven't used it in a while) (尽管该路径可能是/opt/local/lib /opt/local/include但已经有一段时间没有使用了)

There are also port variants: opencv with options. 还有端口变体:带有选项的opencv。 For example if you plan to use openni 1.5.x and have it integrated with opencv you can try 例如,如果您计划使用openni 1.5.x并将其与opencv集成,则可以尝试

sudo port install opencv +openni

If you do 如果你这样做

sudo port variants opencv

you should get a list of all the options(eg python support, qt support, etc.) 您应该获得所有选项的列表(例如python支持,qt支持等)

If you want to build from source yourself, I recommend installing the ccmake command (I think macports can also do that for you) or use the CMake gui tool. 如果您想自己从源代码进行构建,建议您安装ccmake命令(我认为macports也可以为您提供)或使用CMake gui工具。 This will allow you to easily configure the build and setup your install location(/use/local/...and so on) 这将使您轻松配置构建并设置安装位置(/ use / local / ...等)

So you can try someting like this: 因此,您可以尝试进行以下操作:

cd /path/to/your/opencv_folder
mkdir build && cd build
ccmake ..

At this stage you should see something like this: 在此阶段,您应该会看到以下内容: OpenCV CCMake的

hit Enter to change an option and Enter again to exit edit mode and use the up/down keys to scroll through the options. 按Enter更改选项,然后再次按Enter退出编辑模式,然后使用向上/向下键滚动选项。 When you're happy with the settings, press C to configure. 对设置满意后,请按C进行配置。 Once that's done, you can press G to generate. 完成后,您可以按G生成。 This will generate the makefiles for you so you can do this: 这将为您生成makefile,因此您可以执行以下操作:

make
sudo make install

make install will actually copy the built libraries/headers to the /usr/ folder. make install实际上会将构建的库/标题复制到/ usr /文件夹。 You might run into errors when running make, depending on your setup(eg if you're missing dependencies, etc.), but the cool thing about ccmake is that you can go back, run it again, disable the things you don't want to build right now and go back to the make stage. 根据您的设置,运行make时可能会遇到错误(例如,如果缺少依赖项等),但是ccmake的妙处在于您可以返回,再次运行它,禁用不执行的操作想要立即构建并返回到制作阶段。

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

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