關於ros將opencv版本固定“寫死”的一些想法


今天主要工作是將ros和zed結合起來,但是發現自己安裝了opencv3.1,ros indigo安裝的是opencv2.4.8,這就麻煩了,zed支持的是opencv3.1。一開始使用slam2時,報錯:

編譯出現錯誤,
CMakeFiles/Stereo.dir/src/ros_stereo.cc.o: In function `String':
/usr/local/include/opencv2/core/cvstd.hpp:625: undefined reference to `cv::String::allocate(unsigned long)'
CMakeFiles/Stereo.dir/src/ros_stereo.cc.o: In function `main':
/home/car/Desktop/ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/ros_stereo.cc:86: undefined reference to `cv::FileStorage::FileStorage(cv::String const&, int, cv::String const&)'
CMakeFiles/Stereo.dir/src/ros_stereo.cc.o: In function `main':
/usr/local/include/opencv2/core/cvstd.hpp:667: undefined reference to `cv::String::deallocate()'
CMakeFiles/Stereo.dir/src/ros_stereo.cc.o: In function `~String':
/usr/local/include/opencv2/core/cvstd.hpp:667: undefined reference to `cv::String::deallocate()'
CMakeFiles/Stereo.dir/src/ros_stereo.cc.o: In function `cv::FileNode::operator int() const':
/usr/local/include/opencv2/core/persistence.hpp:1180: undefined reference to `cv::read(cv::FileNode const&, int&, int)'
/usr/local/include/opencv2/core/persistence.hpp:1180: undefined reference to `cv::read(cv::FileNode const&, int&, int)'
/usr/local/include/opencv2/core/persistence.hpp:1180: undefined reference to `cv::read(cv::FileNode const&, int&, int)'
/usr/local/include/opencv2/core/persistence.hpp:1180: undefined reference to `cv::read(cv::FileNode const&, int&, int)'
CMakeFiles/Stereo.dir/src/ros_stereo.cc.o: In function `main':
/usr/local/include/opencv2/core/cvstd.hpp:667: undefined reference to `cv::String::deallocate()'
/usr/local/include/opencv2/core/cvstd.hpp:667: undefined reference to `cv::String::deallocate()'

 

之后:

我將CMakeLists.txt 里面的
find_package(OpenCV 2.4.3 REQUIRED)
改成
find_package(OpenCV 3.1.0 REQUIRED COMPONENTS core highgui imgproc imgcodecs)


好像就可以了,但是,運行出錯了
OpenCV Error: Bad argument (Invalid pointer to file storage) in cvGetFileNodeByName, file /build/buildd/opencv-2.4.8+dfsg1/modules/core/src/persistence.cpp, line 740
terminate called after throwing an instance of 'cv::Exception'
  what():  /build/buildd/opencv-2.4.8+dfsg1/modules/core/src/persistence.cpp:740: error: (-5) Invalid pointer to file storage in function cvGetFileNodeByName


OpenCV Error: Bad argument in cvGetFileNodeByName,src/persistence.cpp,  throwing 'cv::Exception'
  what():  /build/buildd/opencv-2.4.8+dfsg1/modules/core/src/persistence.cpp:740: error: (-5) Invalid pointer to file storage in function cvGetFileNodeByName

 

 

還是出錯,改的心慌慌呀。

 

 

網上有個解決方案,轉自http://m.blog.csdn.net/article/details?id=52842099

ROS-Kinect cv_bridge的opencv版本兼容問題

發表於2016/10/17 21:32:15  326人閱讀

分類: 研究

轉自我的博客(http://gongzheng92.net)


今天在編譯自己的drone_sensor模塊的時候(含stereo camera)出現了

/home/joey/pfl/ros/src/drone_sensor/src/stereo_camera/CameraThread.cpp: In member function ‘virtual void CameraThread::loop()’: /home/joey/pfl/ros/src/drone_sensor/src/stereo_camera/CameraThread.cpp:65:47: error: ‘cvDeInterlace’ was not declared in this scope cvDeInterlace(img, evenImage, oddImage); ^ /home/joey/pfl/ros/src/drone_sensor/src/stereo_camera/CameraThread.cpp: In member function ‘void CameraThread::publishImage(image_transport::CameraPublisher&, IplImage*)’: /home/joey/pfl/ros/src/drone_sensor/src/stereo_camera/CameraThread.cpp:85:32: error: no matching function for call to ‘cv::Mat::Mat(IplImage*&)’ cv::Mat image = cv::Mat(img);
  • 1
  • 2
  • 3
  • 4
  • 5

的錯誤(我的catkin_ws即為~/pfl/ros

我的配置為:

  • Ubuntu 16.04 虛擬機
  • ROS版本為Kinect,路徑為/opt/ros/kinect

通過這條問題里中提到的命令查詢opencv的路徑與版本還有依賴庫:

    pkg-config --modversion opencv
    2.4.9.1 pkg-config --cflags opencv -I/usr/include/opencv pkg-config --libs opencv #這里有好多.so文件的路徑,每個人都不盡一樣,略去。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

從報錯以及網上的資料可以發現造成錯誤的原因主要是由於ros在Kinect的版本中自帶了opencv3(通過ros-kinect-opencv3安裝),在目錄/opt/ros/kinetic/include/opencv-3.1.0-dev下。cv3與cv2的不兼容造成了錯誤。具體造成本錯誤的原因是cvDeInterlace這個函數存在於cvaux.h所引用的opencv2/legacy/legacy.hpp文件中,而在cv3中cvaux並沒有引用這個文件(那么在cv3中對應的函數應該如何調用?

這個問題中題主遇到了非常相似的情況,然而給出的解決方式:

將cmakelist中
find_package(OpenCV REQUIRED)
改為
find_package(OpenCV 2.4.8 EXACT REQUIRED)
(其中2.4.8為具體版本號,我的情況為2.4.9.1)

並沒有用,make還是會去調用ros的cv3.

繼續在網上翻找之后發現時cv_bridge的問題。ros kinect的cv_bridge會自動關聯cv3。具體在/opt/ros/kinetic/share/cv_bridge/cmake中的cv_bridgeConfig.cmake里可以看到:

94-96行: if(NOT "include;/opt/ros/kinetic/include/opencv-3.1.0-dev/opencv;/opt/ros/kinetic/include/opencv-3.1.0-dev " STREQUAL " ") set(cv_bridge_INCLUDE_DIRS "") set(_include_dirs "include;/opt/ros/kinetic/include/opencv-3.1.0-dev/opencv;/opt/ros/kinetic/include/opencv-3.1.0-dev")
  • 1
  • 2
  • 3
  • 4

以及第112行的所有lib都是cv3的。

因此將所有的這些opencv的路徑都改為系統的opencv路徑即可解決問題。同時上述的find_package中的信息並沒有必要修改。
附上我的修改方案:

#94-96行: if(NOT "include;/usr/include/opencv;/usr/include " STREQUAL " ") set(cv_bridge_INCLUDE_DIRS "") set(_include_dirs "include;/usr/include/opencv;/usr/include") #112行: set(libraries "cv_bridge;/usr/lib/x86_64-linux-gnu/libopencv_calib3d.s
o;/usr/lib/x86_64-linux-gnu/libopencv_contrib.so;/usr/lib/x86_64-linux-
gnu/libopencv_core.so;/usr/lib/x86_64-linux-gnu/libopencv_features2d.so
;/usr/lib/x86_64-linux-gnu/libopencv_flann.so;/usr/lib/x86_64-linux-gnu
/libopencv_gpu.so;/usr/lib/x86_64-linux-gnu/libopencv_highgui.so;/usr/li
b/x86_64-linux-gnu/libopencv_imgproc.so;/usr/lib/x86_64-linux-gnu/libope
ncv_legacy.so;/usr/lib/x86_64-linux-gnu/libopencv_ml.so;/usr/lib/x86_64-l
inux-gnu/libopencv_objdetect.so;/usr/lib/x86_64-linux-gnu/libopencv_ocl.so
;/usr/lib/x86_64-linux-gnu/libopencv_photo.so;/usr/lib/x86_64-linux-gnu/
libopencv_stitching.so;/usr/lib/x86_64-linux-gnu/libopencv_superres.so;/
usr/lib/x86_64-linux-gnu/libopencv_ts.so;/usr/lib/x86_64-linux-gnu/lib
opencv_video.so;/usr/lib/x86_64-linux-gnu/libopencv_videostab.so")

有了些啟發,但是還是沒做出來




 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM