OpenCV
以与QT
一起工作。我在这里看到了一些相关的问题(如何链接QtCreator中的OpenCV并使用Qt库和如何在OSX中设置OpenCV与QT?),但没有太多细节说明。在QT网站和我的网络搜索中,所有信息似乎都是关于Windows或Linux的。
我列出了我的设置和代码,但运行代码时出现错误::-1:错误:找不到体系结构x86_64的符号
这是否意味着未找到内容是因为路径不正确还是因为我可能已将openCV构建为x86_32?有办法检查后者吗?我对配置和设置过程的某些部分不太熟悉。
更新2
下面是控制台输出——也许错误很明显?
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'
目前为止我所做的事情(简短概括):
从源代码构建和安装了最新版本的openCV(2.4.6),并通过一些命令行程序进行了测试。
安装了最新版本的QT(5.1),能够运行所有示例等。
在项目文件中指定了路径(如下所示)
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
在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" 等。
这些重要细节总是让我困扰,但教程通常假定读者已经掌握了这些内容。
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