简体   繁体   English

在 ROS 中使用 cv::FileStorage 加载 YML 文件时出现分段错误

[英]Segmentation fault when loading YML file with cv::FileStorage in ROS

I have a problem with cv::FileStorage when I tried to read a YML file in a ROS node.当我尝试在 ROS 节点中读取 YML 文件时,我遇到了cv::FileStorage问题。 I got Segmentation fault (core dumped) error when running the node and I was able to identified the problem which comes from the calling of cv::FileStorage constructor.运行节点时出现Segmentation fault (core dumped)错误,我能够确定来自调用cv::FileStorage构造函数的问题。 Then, according to this similar question, I put the following code in main function (separately in a node), but the error still occurs, due to the fs.open(...) function.然后,根据这个类似的问题,我将以下代码放在主 function 中(单独在一个节点中),但由于fs.open(...) function,错误仍然存在。

Remark that I linked the necessary packages with my ros package, and I provided the absolute path to the file as well.请注意,我将必要的软件包与我的 ros package 链接在一起,并且我还提供了文件的绝对路径。

std::string filePath = "/home/user/catkin_ws/src/arucov3_node/param/raspicam_v2_400x300.yml";
cv::FileStorage fs;
try{
    fs.open(filePath, cv::FileStorage::READ);
}
catch(cv::Exception ex){
    ROS_ERROR("%s", ex.what());
    return 0;
}

For providing more information about this issue, I tried to debug with gdb and got the detailed error message:为了提供有关此问题的更多信息,我尝试使用 gdb 进行调试并得到详细的错误消息:

Thread 1 "detect_node" received signal SIGSEGV, Segmentation fault. 0x00007ffff51e4a18 in cv::FileStorage::Impl::release(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) [clone.constprop.330] ()

Hope someone could help me for this problem.希望有人可以帮助我解决这个问题。

I figured out this issue based on PaulMcKenzie's comments.我根据 PaulMcKenzie 的评论发现了这个问题。 It was a version problem of OpenCV.这是 OpenCV 的版本问题。 Actually, aside from binary installed OpenCV 3.2.0 in Ubuntu, I have built OpenCV 4.5.2 from source, with which my program is linked and didn't work.实际上,除了在 Ubuntu 中安装二进制 OpenCV 3.2.0 之外,我还构建了 OpenCV 4.5.2 的源代码。

So I specify in CMakeLists.txt : find_package(OpenCV 3.2.0 REQUIRED) Then it is working.所以我在CMakeLists.txt中指定: find_package(OpenCV 3.2.0 REQUIRED)然后它就可以工作了。

I felt so strange about that a newer version of OpenCV doesn't work with such a basic function.我觉得很奇怪,新版本的 OpenCV 不能与这样基本的 function 一起使用。 Not sure if it was me who have missed anything.不知道是不是我错过了什么。

I update my response by giving more details:我通过提供更多详细信息来更新我的回复:

The 4.5.2 version of OpenCV didn't work for some reasons, so I rebuilt it by cloning the 3.4 branch of OpenCV . OpenCV 的 4.5.2 版本由于某些原因无法正常工作,所以我通过克隆OpenCV的 3.4 分支来重建它。 (The default 3.2.0 version in Ubuntu lacks some of the latest functionalities) (Ubuntu 中的默认 3.2.0 版本缺少一些最新功能)

Since I have built my package (and also another library from source) based on OpenCV 4.5.2, I need to rebuild everything giving the path to the same version of OpenCV.由于我已经基于 OpenCV 4.5.2 构建了我的 package(以及另一个来自源的库),因此我需要重建所有内容以提供相同版本的 Z5BD4C87976F48E6A53919D53E1 的路径Basically it was simply adding an argument while compiling by cmake or catkin, like cmake -DOpenCV_DIR=<pathTo-OpenCVConfig.cmake>..基本上它只是在通过 cmake 或 catkin 编译时添加一个参数,例如cmake -DOpenCV_DIR=<pathTo-OpenCVConfig.cmake>..

Not sure if it's related to your issue without seeing the rest of your code, but OpenCV exceptions are not copyable, so your catch won't work.在没有看到代码的 rest 的情况下不确定它是否与您的问题有关,但 OpenCV 异常不可复制,因此您的捕获将不起作用。 Try this, you might have an actual error message instead:试试这个,你可能会收到一条实际的错误消息:

catch(const cv::Exception& e){
    ROS_ERROR("%s", e.what());
    //... abort or continue
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM