在OSX上的QT中设置OpenCV [英] Setting up OpenCV in QT on OSX

查看:81
本文介绍了在OSX上的QT中设置OpenCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在OSX 10.7.5/MacbookPro 2.5 Ghz Intel Core 2 Duo上设置OpenCV以与QT一起使用.我在这里看到了一些相关的问题(如何在OSX中使用QT设置OpenCV?),但是没有太多细节.在QT网站和我的网络搜索中,所有信息似乎都与Windows或Linux有关.

I am trying to set up OpenCV to work with QT on OSX 10.7.5/MacbookPro 2.5 Ghz Intel Core 2 Duo. I've seen a few related question here (How to link opencv in QtCreator and use Qt library and How do you set up OpenCV with QT in OSX?) but there isn't much detail. On the QT site and in my web searches all of the information seems to be about Windows or Linux.

我在下面列出了我的设置和代码.运行代码时出现错误::-1: error: symbol(s) not found for architecture x86_64

I've listed what my setup and code is below. When I run the code I am getting an error: :-1: error: symbol(s) not found for architecture x86_64

这是否意味着由于路径错误或因为我可能为x86_32构建了openCV而找不到东西?有没有一种方法可以检查后者?我对部分配置和设置过程不太了解.

Does this mean it's not finding stuff because the paths are wrong or because I may have built openCV for x86_32? Is there a way of checking the latter? I'm not so savvy with parts of the configuration and setup process.

更新2

控制台输出在下面-也许错误很明显?

The console output is below - perhaps the error is obvious?

02:44:38: Running steps for project RP_openCV_01...
02:44:38: Configuration unchanged, skipping qmake step.
02:44:38: Starting: "/usr/bin/make" 
clang++ -headerpad_max_install_names -mmacosx-version-min=10.6 -o RP_openCV_01 main.o   -L/usr/local/lib -1ibopencv_core.2.4.6,dylib -1ibopencv_imgproc.2.4.6.dylib -F/Users/rise/Qt5.0.2/5.0.2/clang_64/lib -framework QtCore 
clang: warning: argument unused during compilation: '-1ibopencv_core.2.4.6,dylib'
clang: warning: argument unused during compilation: '-1ibopencv_imgproc.2.4.6.dylib'
Undefined symbols for architecture x86_64:
  "cv::_InputArray::_InputArray(cv::Mat const&)", referenced from:
      _main in main.o
  "cv::namedWindow(std::string const&, int)", referenced from:
      _main in main.o
  "cv::Mat::deallocate()", referenced from:
      _main in main.o
  "cv::imread(std::string const&, int)", referenced from:
      _main in main.o
  "cv::imshow(std::string const&, cv::_InputArray const&)", referenced from:
      _main in main.o
  "cv::waitKey(int)", referenced from:
      _main in main.o
  "cv::fastFree(void*)", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [RP_openCV_01] Error 1
02:44:38: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project RP_openCV_01 (kit: Desktop Qt 5.0.2 clang 64bit)
When executing step 'Make'


到目前为止我所拥有的(tl; dr):

  • 从源代码构建并安装了最新版本的openCV(2.4.6),并通过一些命令行程序对其进行了测试.

  • built and installed the latest version of openCV (2.4.6) from source and tested it with some command line programs.

安装了最新版本的QT(5.1),并能够运行所有示例,等等.

installed the latest version of QT (5.1) and am able to run all the examples, etc.

在项目文件中指定了路径(如下)

specified the paths in the project file (below)

QT       += core
QT       -= gui

TARGET = RP_openCV_01
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app
SOURCES += main.cpp

INCLUDEPATH += /usr/local/include\
LIBS += -L/usr/local/lib

  • 试图在项目设置中指定路径(如下).我添加了/usr/local/include/usr/local/lib
    • tried to specify the path in the project settings (below). I added /usr/local/include and /usr/local/lib
    • main.cpp中的简单示例代码

      The simple example code in main.cpp

      #include <opencv2/core/core.hpp>
      #include <opencv2/highgui/highgui.hpp>
      
      int main() {
      
          // read an image
          cv::Mat image= cv::imread("dog.jpg");
          // create image window named "My Image"
          cv::namedWindow("My Image");
          // show the image on window
          cv::imshow("My Image", image);
          // wait key for 5000 ms
          cv::waitKey(5000);
      
          return 1;
      }
      


      更新1

      我基于教程尝试的另一件事是在QT配置文件中指定库(如下图所示).尽管该教程是针对Windows的,但我不知道OSX是否有所不同.在Windows示例中的-1ibopencv_core246d位置,我尝试了带分隔符和不带分隔符但不带"d"的情况.当然,库的全名是"libopencv_core.2.4.6.dylib"等.

      Another thing I tried based on a tutorial was to specify the libs in the QT profile (as in image below). The tutorial was for Windows though and I didn't know if or how OSX is different. Where in the Windows example it is -1ibopencv_core246d I tried it with and without the separating periods but without the "d". Of course the full name of a lib is "libopencv_core.2.4.6.dylib" etc.

      这些重要的细节总是让我绊倒,但是在教程中经常假定人们知道这些东西.

      These sorts of important details always trip me up but it's often assumed in tutorials that one knows this stuff.

       LIBS += -L/usr/local/lib \
           -1ibopencv_core.2.4.6 \
           -1ibopencv_imgproc.2.4.6 \
           -1ibopencv_features2d.2.4.6 \
           -1ibopencv_highgui.2.4.6
      

      推荐答案

      天真的错误

      正确的声明是:

      LIBS += -L/usr/local/lib \
           -lopencv_core \
           -lopencv_imgproc \
           -lopencv_features2d\
           -lopencv_highgui
      

      这篇关于在OSX上的QT中设置OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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