在本地安装时如何包含和使用openCV库? [英] How to include and use openCV library when installed locally?

查看:194
本文介绍了在本地安装时如何包含和使用openCV库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在OSX上的文件夹中本地安装OpenCV版本,而不会覆盖旧的可执行文件所需的旧安装。

I want to install an OpenCV version locally on OSX in a folder without overwriting the old installation that I need for an old executable.

我遵循了[这些说明] [1],特别是使用CMake,使用命令行从源代码构建OpenCV 部分。

I followed [these instructions][1], particularly the Building OpenCV from Source Using CMake, Using the Command Line section.

基本上,我是:


  1. 使用git下载了源代码,现在它位于子文件夹 openCV

  2. 已创建新目录 cmake_bin_dir

  3. 输入 cmake_bin_dir 并创建另一个子目录 instDir

  4. cmake_bin_dir 中启动命令 cmake -D CMAKE_BUILD_TYPE = DEBUG -D CMAKE_INSTALL_PREFIX = / my / home / Downloads / openCVProject / cmake_bin_dir / instDir / .. / openCV /

  5. 从同一目录中,我先启动 make ,然后启动 sudo make install 。这会在 cmake_bin_dir / instDir 目录中创建 *。dylib 文件。

  1. downloaded the source code with git and now it is in the subfolder openCV
  2. Created a new directory cmake_bin_dir
  3. Entered in cmake_bin_dir and created another subdirectory instDir
  4. From the cmake_bin_dir I launched the command cmake -D CMAKE_BUILD_TYPE=DEBUG -D CMAKE_INSTALL_PREFIX=/my/home/Downloads/openCVProject/cmake_bin_dir/instDir/ ../openCV/
  5. From the same directory I launched first make and then sudo make install. This created the *.dylib files in the cmake_bin_dir/instDir directory.

要测试安装,我创建了项目目录(与 cmake_bin_dir 处于同一级别。

To test the installation I created my project directory (at the same level of cmake_bin_dir.

我尝试使用以下命令编译名为test.cpp的文件:

I tried to compile the file named test.cpp with the command:

    g++ -std=c++11 -I../cmake_bin_dir/ -I../openCV/include -I../openCV/modules/core/include/ \
-I../openCV/modules/calib3d/include/ -I../openCV/modules/features2d/include \
-I../openCV/modules/flann/include -I../openCV/modules/dnn/include -I../openCV/modules/highgui/include/ \
-I../openCV/modules/imgcodecs/include -I../openCV/modules/videoio/include -I../openCV/modules/imgproc/include \
-I../openCV/modules/ml/include -I../openCV/modules/objdetect/include -I../openCV/modules/photo/include \
-I../openCV/modules/shape/include -I../openCV/modules/stitching/include -I../openCV/modules/superres/include \
-I../openCV/modules/video/include -I../openCV/modules/videostab/include test.cpp -o test.o

我一一添加了include,因为每次都遇到编译错误。
但是现在我得到一个链接错误:

I added the include one by one because I got compilation error each time. However now I getting a linkage error:

Undefined symbols for architecture x86_64:
  "cv::String::deallocate()", referenced from:
      cv::String::~String() in test-afd12e.o
      cv::String::operator=(cv::String const&) in test-afd12e.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

所以我的问题是如何使用OpenCV库的本地安装来编译程序和其他项目?
[1]: https:// docs。 opencv.org/2.4/doc/tutorials/introduction/linux_install/linux_install.html

So my question is how can I compile my program and other projects using the local installation of the OpenCV library? [1]: https://docs.opencv.org/2.4/doc/tutorials/introduction/linux_install/linux_install.html

推荐答案

好,我找到了错误。如果有人遇到相同的问题,请尝试在终端上执行此操作:

Ok I found my error. If anybody will have the same problem try to execute this on terminal:

export DYLD_LIBRARY_PATH=../your/path/lib/:$DYLD_LIBRARY_PATH

在我的情况下,我执行了:

In my case the I executed:

export DYLD_LIBRARY_PATH=../cmake_bin_dir/lib/:$DYLD_LIBRARY_PATH

我还创建了一个 Makefile ,其内容如下:

I also created a Makefile with the following content:

CPP = g++ -std=c++11

# OpenCV trunk
CPPFLAGS = -L../cmake_bin_dir/lib/ \
       -I../cmake_bin_dir/include \
           -I../cmake_bin_dir/ -I../openCV/include -I../openCV/modules/core/include/ \
           -I../openCV/modules/calib3d/include/ \
           -I../openCV/modules/features2d/include \
           -I../openCV/modules/flann/include -I../openCV/modules/dnn/include -I../openCV/modules/highgui/include/ \
           -I../openCV/modules/imgcodecs/include -I../openCV/modules/videoio/include -I../openCV/modules/imgproc/include \
       -I../openCV/modules/ml/include -I../openCV/modules/objdetect/include -I../openCV/modules/photo/include \
       -I../openCV/modules/shape/include -I../openCV/modules/stitching/include -I../openCV/modules/superres/include \
       -I../openCV/modules/video/include -I../openCV/modules/videostab/include \
           `pkg-config --cflags --libs ../cmake_bin_dir/instDir/lib/pkgconfig/opencv.pc`

# Opencv 2.4.8
#CPPFLAGS = -L/home/krystof/libs/opencv-2.4.8/release/installed/libs \
       -I/home/krystof/libs/opencv-2.4.8/release/installed/include

all: test

test: test.cpp
    $(CPP) $(CPPFLAGS) $^ -o $@

现在执行 make 应该使用本地openCV版本构建程序。

Now executing make should build the program with the local openCV version.

这篇关于在本地安装时如何包含和使用openCV库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆