我刚刚开始使用 OpenCV,并且在收到链接错误时正在浏览一些基本的示例程序。一切都应该是核心库 libopencv_core.2.4.3.dylib 的一部分,它是适当链接的(Mat 对象没有问题,只是操作.hpp 中的格式化程序类)。
另外,如果行: cout << format(M,"C") << endl; 被排除在外,那么代码编译得很好,但有一个奇怪的行为。一旦 M Mat 对象被发送到 cout,对象中包含的值就不会打印出来,随后对 cout 的调用也不会产生任何结果,即使代码运行完成。
其他人遇到过这个问题吗?
来自 macports、xcode 4.5.2、os x Lion 10.7.5 的 openCV 2.4.3
代码:(实际上是来自 openCV 示例代码的 cout_mat.cpp 片段)
#include "/usr/local/include/opencv2/opencv.hpp"
#include "/usr/local/include/opencv2/core/operations.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int,char**)
{
Mat M = Mat::eye(4, 4, CV_64F);
M.at<double>(0,0) = CV_PI;
// print out val at 0,0
cout << "M(0,0) = " << M.at<double>(0,0) << endl;
// test serial out capabilities of cv::Mat (yields no output beyond M=)
cout << "M = " << endl << M << endl;
// try to print M(0,0) to screen again to demonstrate that cout no longer prints to screen
cout << "M(0,0) = " << M.at<double>(0,0) << endl;
// Try to format the output with 'c-style', Note: if included in program this line yields linker error
cout << format(M,"C") << endl;
return 0;
}
调试器中的输出:带有行“cout << format(M,"C") << endl;" 注释掉
M(0,0) = 3.14159
M =
M= 为空以及额外的 cout:M(0,0) = 3.14159
"cout << format(M,"C") << endl;" 行出错 包括:
Undefined symbols for architecture x86_64:
"cv::Formatted::Formatted(cv::Mat const&, cv::Formatter const*, std::__1::vector<int, std::__1::allocator<int> > const&)", referenced from:
__ZN2cvL6formatERKNS_3MatEPKcRKNSt3__16vectorIiNS5_9allocatorIiEEEE 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)