我正在尝试使用 OpenCV 的 chamferMatching 功能在 OSX 上工作,但收到有关尝试释放未分配对象失败的错误(据我所知):
fs(58697,0x100b3c000) malloc: *** error for object 0x103800000: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
我发现很少有像这两个有用的帖子:
- chamerMatching malloc error
- debug assertion failed vc\include\vector vector iterator + offset out of range in chamferMatching Opencv
在 Ubuntu 上,只需编译 OpenCV 2.4.1从源代码并使用它就可以了。
虽然在 OSX 上同样没有工作。我还在 Matching
析构函数中注释掉了模板删除:
~Matching()
{
for (size_t i = 0; i<templates.size(); i++) {
// delete templates[i];
}
}
但没有快乐。
我什至尝试注释掉 chamfermatching.cpp 中的所有删除语句,但我仍然遇到同样的错误。
更新 我已经尝试使用 3 个不同版本的 g++ 重新编译 OpenCV 2.4.1:4.9、5 和 6,但出现链接错误。这是一个使用 g++ 5 编译的示例:
g++-5 ../fs.cpp -I/Users/George/Downloads/Grouped/cv/opencv-2.4.1/build/install/include/opencv -I/Users/George/Downloads/Grouped/cv/opencv-2.4.1/build/install/include -L/Users/George/Downloads/Grouped/cv/opencv-2.4.1/build/install/lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_video -lopencv_videostab -o fs
Undefined symbols for architecture x86_64:
"cv::chamerMatching(cv::Mat&, cv::Mat&, std::vector<std::vector<cv::Point_<int>, std::allocator<cv::Point_<int> > >, std::allocator<std::vector<cv::Point_<int>, std::allocator<cv::Point_<int> > > > >&, std::vector<float, std::allocator<float> >&, double, int, double, int, int, int, double, double, double, double)", referenced from:
_main in ccTJvcHd.o
"std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > cv::CommandLineParser::analyzeValue<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)", referenced from:
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > cv::CommandLineParser::get<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) in ccTJvcHd.o
"cv::CommandLineParser::has(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > cv::CommandLineParser::get<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) in ccTJvcHd.o
"cv::CommandLineParser::getString(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > cv::CommandLineParser::get<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool) in ccTJvcHd.o
"cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
_main in ccTJvcHd.o
"cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray const&)", referenced from:
_main in ccTJvcHd.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
我试过添加标志,例如 -std=c++11
然后是 -std=c++0x
,但没有成功。
关于我如何解决这个问题的任何提示?
我是一名优秀的程序员,十分优秀!