项目场景:
ros2 foxy 运行单目orb slam3
问题描述
编译正常,程序运行时报错如下
Loading ORB Vocabulary. This could take a while...
Vocabulary loaded!
Initialization of Atlas from scratch
Creation of new map with id: 0
Creation of new map with last KF id: 0
Seq. Name:
There are 1 cameras in the atlas
Camera 0 is pinhole
slam changed
============================
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.2.0) /home/ros2/opencv4.4/opencv-4.4.0/modules/highgui/src/window.cpp:634: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvNamedWindow'
错误解决方案
按照系统给出的解决方案,执行命令
sudo apt-get install libgtk2.0-dev
sudo apt-get install pkg-config
并不能解决问题
原因分析:
问题出在,安装opencv时编译配置出现了问题。
正确的执行命令是:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.4.0/modules ../opencv-4.4.0
解决方案:
opencv目录结构:
以前的编译命令:
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.4.0/modules ../opencv-4.4.0
正确的编译执行命令:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.4.0/modules ../opencv-4.4.0
重新编译后运行:
ros2 run orbslam3 mono ~/ros2_ws/src/ORB_SLAM3/Vocabulary/ORBvoc.txt ~/ros2_ws/src/ORB_SLAM3/Examples/Monocular/EuRoC.yaml
程序正常运行。
参考博客:文章来源:https://www.toymoban.com/news/detail-527035.html
If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config_绿竹巷人的博客-CSDN博客文章来源地址https://www.toymoban.com/news/detail-527035.html
到了这里,关于The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!