Linux/Ubuntu中的OpenCV安装

OpenCV Installation in Linux/Ubuntu

本文关键字:OpenCV 安装 中的 Ubuntu Linux      更新时间:2023-10-16

我正在做这个教程http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html#linux-安装但我很困惑。我停止了从源代码构建OpenCV。

我已经创建了一个名为Workspace的文件,在其中我制作了cmake_binary_dir(命名版本)。我下载了源文件(它在我的主目录中,名为:opencv-2.3.1),现在我想运行这个

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

我使用的位置:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/home/markus/opencv-2.3.1

但是终端一直告诉我,这个源目录不存在!?那么我做错了什么?

CMAKE_INSTALL_PREFIX定义二进制文件编译和链接后的分发位置,默认为好位置(/usr/local/),因此避免将其定义为

你漏掉了拖尾部分。。在你的cmake命令中,它告诉它在哪里获得源代码,因此错误消息

以下是从源代码安装使用cmake 的任何项目时的典型步骤

如果你看到一个文件:

CMakeLists.txt

在src目录中,这表示它希望您使用cmake

0  cd into dir where your expanded source code lives
1  mkdir build # make a build dir (initially empty)  
2  cd build
3  cmake .. # NOTE those little .. which declares relative path to src dir
      which says populate current dir (build) with compiled code 
      and get the source code and configs from parent directory (..)
4  examine the output, if it looks successful go to step 5
      if it has errors you may need to install upstream dependent 
      libraries then try cmake again 
5  make -j4  # compile source,  -j speeds up by using multicore
6  sudo make install <-- only if above step 4 and 5 are OK

您可以从命令行完成cmake相关的所有操作,但它的GUI非常方便,尤其是在不熟悉的项目中。在上面而不是键入:

cmake ..    

其GUI版本为:

cmake-gui ..

在GUI中,它很容易切换开/关设置,比如构建示例或不构建示例。。。右边的值列是可编辑的。。。如果您在gui中更改了底部的设置,请点击按钮Configure,然后当它完成时,点击Generate以执行与正常cmake ..相同的操作,现在返回到上面的步骤4以执行编译