Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在构建ROS节点时如何查找安装在/usr/local中的OpenCV_Opencv_Cmake_Opencv3.0_Ros - Fatal编程技术网

在构建ROS节点时如何查找安装在/usr/local中的OpenCV

在构建ROS节点时如何查找安装在/usr/local中的OpenCV,opencv,cmake,opencv3.0,ros,Opencv,Cmake,Opencv3.0,Ros,我在OpenCV中使用ROS动能。我创建了一个使用CUDA实现的OpenCV算法的节点(ros-kinetic-opencv3包中没有),因此我从源代码处编译了OpenCV,启用了CUDA,并将其安装在/usr/local中 为了测试我的/usr/local安装是否按预期工作(以及我的代码是否正确),我在ROS之外创建了一个程序,使用以下CMakeList.txt: cmake_minimum_required(VERSION 2.8.3) project(stereo_algorithms_t

我在OpenCV中使用ROS动能。我创建了一个使用CUDA实现的OpenCV算法的节点(ros-kinetic-opencv3包中没有),因此我从源代码处编译了OpenCV,启用了CUDA,并将其安装在
/usr/local

为了测试我的
/usr/local
安装是否按预期工作(以及我的代码是否正确),我在ROS之外创建了一个程序,使用以下
CMakeList.txt

cmake_minimum_required(VERSION 2.8.3)
project(stereo_algorithms_testing)
set(ENV{OpenCV_DIR} "/usr/local")
find_package(OpenCV REQUIRED)
include_directories(include ${OpenCV_INCLUDE_DIRS})
add_executable(stereo_algorithms main.cpp)
target_link_libraries(stereo_algorithms ${OpenCV_LIBS})
cmake_minimum_required(VERSION 2.8.3)
project(depth_calculator)
set(ENV{OpenCV_DIR} "/usr/local")
find_package(OpenCV REQUIRED core highgui calib3d PATHS /usr/local NO_DEFAULT_PATH)
find_package(catkin REQUIRED COMPONENTS cv_bridge image_transport)
catkin_package()
include_directories(include ${OpenCV_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS})
add_executable(double_image_acq src/double_image_acquisition.cpp)
target_link_libraries(double_image_acq ${OpenCV_LIBS} ${catkin_LIBRARIES})
当我运行
cmake.
时,我得到以下输出:

-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/g++
-- Check for working CXX compiler: /usr/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found CUDA: /usr/local/cuda (found suitable exact version "8.0") 
-- Found OpenCV: /usr/local (found version "3.2.0") 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/degraw/Opencv_testing/stereo_algorithms/test
一切正常,代码按预期运行,没有运行时错误

现在,当我在ROS节点中使用相同的代码时,我有以下
CMakeList.txt

cmake_minimum_required(VERSION 2.8.3)
project(stereo_algorithms_testing)
set(ENV{OpenCV_DIR} "/usr/local")
find_package(OpenCV REQUIRED)
include_directories(include ${OpenCV_INCLUDE_DIRS})
add_executable(stereo_algorithms main.cpp)
target_link_libraries(stereo_algorithms ${OpenCV_LIBS})
cmake_minimum_required(VERSION 2.8.3)
project(depth_calculator)
set(ENV{OpenCV_DIR} "/usr/local")
find_package(OpenCV REQUIRED core highgui calib3d PATHS /usr/local NO_DEFAULT_PATH)
find_package(catkin REQUIRED COMPONENTS cv_bridge image_transport)
catkin_package()
include_directories(include ${OpenCV_INCLUDE_DIRS} ${catkin_INCLUDE_DIRS})
add_executable(double_image_acq src/double_image_acquisition.cpp)
target_link_libraries(double_image_acq ${OpenCV_LIBS} ${catkin_LIBRARIES})
注意,我明确告诉cmake只在
/usr/local
中查找OpenCV。
catkin\u make
的输出为:

-- Using CATKIN_DEVEL_PREFIX: /home/degraw/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /home/degraw/catkin_ws/devel;/usr/local;/opt/ros/kinetic
-- This workspace overlays: /home/degraw/catkin_ws/devel;/opt/ros/kinetic
-- Using PYTHON_EXECUTABLE: /usr/bin/python
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/degraw/catkin_ws/build/test_results
-- Found gtest sources under '/usr/src/gtest': gtests will be built
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.6
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 2 packages in topological order:
-- ~~  - depth_calculator
-- ~~  - zed_wrapper
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'depth_calculator'
-- ==> add_subdirectory(depth_calculator)
-- Found OpenCV: /opt/ros/kinetic (found version "3.2.0") found components:  core highgui calib3d 
...
...
...
Running command: "make -j4 -l4" in "/home/degraw/catkin_ws/build"
[ 14%] Built target zed_wrapper_gencfg
[ 28%] Linking CXX executable /home/degraw/catkin_ws/devel/lib/depth_calculator/double_image_acq
[ 57%] Built target ZEDWrapper
[ 85%] Built target zed_wrapper_node
CMakeFiles/double_image_acq.dir/src/double_image_acquisition.cpp.o: In function `OpencvDisparityCalculator::callback(boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > const> const&, boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > const> const&)':
double_image_acquisition.cpp:(.text._ZN25OpencvDisparityCalculator8callbackERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEES9_[_ZN25OpencvDisparityCalculator8callbackERKN5boost10shared_ptrIKN11sensor_msgs6Image_ISaIvEEEEES9_]+0x1ad): undefined reference to `cv::cuda::createStereoBM(int, int)'
collect2: error: ld returned 1 exit status
depth_calculator/CMakeFiles/double_image_acq.dir/build.make:175: recipe for target '/home/degraw/catkin_ws/devel/lib/depth_calculator/double_image_acq' failed
make[2]: *** [/home/degraw/catkin_ws/devel/lib/depth_calculator/double_image_acq] Error 1
CMakeFiles/Makefile2:353: recipe for target 'depth_calculator/CMakeFiles/double_image_acq.dir/all' failed
make[1]: *** [depth_calculator/CMakeFiles/double_image_acq.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j4 -l4" failed
——使用CATKIN\u-DEVEL\u前缀:/home/degraw/CATKIN\u-ws/DEVEL
--使用CMAKE_前缀_路径:/home/degraw/catkin_ws/devel/usr/本地/opt/ros/kinetic
--此工作区覆盖:/home/degraw/catkin\u ws/devel/opt/ros/kinetic
--使用PYTHON\u可执行文件:/usr/bin/PYTHON
--使用Debian Python包布局
--使用empy:/usr/bin/empy
--使用CATKIN\u启用\u测试:打开
--调用enable_testing()
--使用CATKIN\u测试结果\u目录:/home/degraw/CATKIN\u ws/build/TEST\u结果
--在“/usr/src/gtest”下找到gtest源:将生成gtest
--使用Python测试:/usr/bin/nosetests-2.7
--柳絮0.7.6
--构建共享库已打开
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--~~按拓扑顺序遍历2个包:
--深度计算器
--~~-zed\u包装器
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--+++处理柳絮包:“深度\计算器”
--==>添加子目录(深度计算器)
--找到OpenCV:/opt/ros/kinetic(找到版本“3.2.0”)找到组件:core highgui calib3d
...
...
...
正在运行命令“/home/degraw/catkin\u ws/build”中的“make-j4-l4”
[14%]构建目标zed\u包装器\u gencfg
[28%]链接CXX可执行文件/home/degraw/catkin\u ws/devel/lib/depth\u calculator/double\u image\u acq
[57%]内置目标ZEDWrapper
[85%]构建的目标zed\u包装器\u节点
CMakeFiles/double_image_acq.dir/src/double_image_acquisition.cpp.o:在函数“OpencvDisparityCalculator::callback(boost::shared_ptr const&,boost::shared_ptr const&)”中:
double_image_acquisition.cpp:(.text._zn25opencvdisparitycalculator8callbackerkn5boost10共享_ptrikn11传感器_msgs6Image_是一个独立的ees9)[_zn25opencvdisparitycalculator8callbackerkn5boost10共享_ptrikn11传感器_msgs6;图像_是一个独立的ees9_1;0x1ad]:对“cv::cuda::createsterobm(int,int)”的未定义引用
collect2:错误:ld返回了1个退出状态
深度计算器/cmakfiles/double\u image\u acq.dir/build.make:175:目标“/home/degraw/catkin\u ws/devel/lib/depth\u计算器/double\u image\u acq”的配方失败
make[2]:***[/home/degraw/catkin\u ws/devel/lib/depth\u calculator/double\u image\u acq]错误1
CMakeFiles/Makefile2:353:目标“深度计算器/CMakeFiles/double\u图像\u acq.dir/all”的配方失败
make[1]:***[depth\u calculator/CMakeFiles/double\u image\u acq.dir/all]错误2
Makefile:138:目标“全部”的配方失败
make:**[全部]错误2
调用“make-j4-l4”失败

显然这是一个链接器问题。它发现错误的OpenCV(ROS OpenCV),其中不包括CUDA的库


如何告诉catkin_make在
/usr/local
中查找OpenCV?

没有默认路径
find_package()
应该只在提示和路径选项下搜索(甚至忽略环境变量)。我看到了使用
/opt/ros/kinetic
路径的唯一方法:缓存变量OpenCV_DIR已经设置为该路径。例如,有人以前搜索过OpenCV,或者你在尝试重新配置之前忘记清除缓存。我在一百万年内都不会想到这一点!它成功了,最终在/usr/local中找到了OpenCV。不幸的是,我仍然存在链接错误,我将继续尝试查找错误,但现在至少我正在加载正确的OpenCV。非常感谢你!嗨@Degraw!一年过去了,你最终找到了解决问题的方法吗?我现在处境相同,很想听听你是如何解决这个问题的。嗨@MrSquid。不幸的是,这已经有一段时间了,我甚至不记得我是否解决了它。但每当我遇到类似的问题时,我都会想到一件事,那就是清理我的柳絮工作区并重新编译所有内容修复了一些缓存问题。我还记得在某个时候,我根本没有安装ROS OpenCV(或任何依赖于它的包,例如cv_bridge、image_transport),但我使用它将所有这些包的源代码添加到我的catkin工作区并编译它们,链接到我的
/usr/local
OpenCV。希望这能帮上忙!我自己也解决了这个问题——问题变得相当模糊,我用catkin_simple添加到我的CmakeList中的依赖项也使用OpenCV,并加载OpenCV的ros安装,从而覆盖了我为自定义安装定义的路径。无论如何,感谢您的回复:)如果没有默认路径,
find\u package()
应该只在提示和路径选项下搜索(它甚至会忽略环境变量)。我看到了使用
/opt/ros/kinetic
路径的唯一方法:缓存变量OpenCV_DIR已经设置为该路径。例如,有人以前搜索过OpenCV,或者你在尝试重新配置之前忘记清除缓存。我在一百万年内都不会想到这一点!它成功了,最终在/usr/local中找到了OpenCV。不幸的是,我仍然存在链接错误,我将继续尝试查找错误,但现在至少我正在加载正确的OpenCV。非常感谢你!嗨@Degraw!一年过去了,你最终找到了解决问题的方法吗?我现在处境相同,很想听听你是如何解决这个问题的。嗨@MrSquid。不幸的是,已经有一段时间了,我不能