ros加载编译opencv-3.4.9,编译安装opencv-3.4.9

以你之姓@ 2022-10-29 01:59 413阅读 0赞

ros加载编译opencv-3.4.9

ros中配置opencv

1.加载自己的opencv库 cv_bridge find_package(OpenCV REQUIRED)

  1. cmake_minimum_required(VERSION 3.0.2)
  2. project(visualOrientation)
  3. ## Compile as C++11, supported in ROS Kinetic and newer
  4. add_compile_options(-std=c++11)
  5. #set(OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)
  6. # 配置依赖目录及程序输出目录
  7. #set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIR}/bin" CACHE PATH "Runtime directory" FORCE)
  8. #set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib" CACHE PATH "Library directory" FORCE)
  9. #set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib" CACHE PATH "Archive directory" FORCE)
  10. ## Find catkin macros and libraries
  11. ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
  12. ## is used, also find other catkin packages
  13. #set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty)
  14. #set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
  15. #set(CMAKE_MODULE_PATH /home/iimt/3rdparty/OpenCV-3.4.9)
  16. #set(OpenCV_DIR /home/iimt/3rdparty/OpenCV-3.4.9)
  17. find_package(catkin REQUIRED COMPONENTS
  18. roscpp
  19. rosmsg
  20. rospy
  21. sensor_msgs
  22. cv_bridge
  23. image_transport
  24. tf
  25. )
  26. #cv_bridge
  27. find_package(OpenCV REQUIRED)
  28. ## System dependencies are found with CMake's conventions
  29. # find_package(Boost REQUIRED COMPONENTS system)
  30. ## Uncomment this if the package has a setup.py. This macro ensures
  31. ## modules and global scripts declared therein get installed
  32. ## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
  33. # catkin_python_setup()
  34. ################################################
  35. ## Declare ROS messages, services and actions ##
  36. ################################################
  37. ## To declare and build messages, services or actions from within this
  38. ## package, follow these steps:
  39. ## * Let MSG_DEP_SET be the set of packages whose message types you use in
  40. ## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
  41. ## * In the file package.xml:
  42. ## * add a build_depend tag for "message_generation"
  43. ## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET
  44. ## * If MSG_DEP_SET isn't empty the following dependency has been pulled in
  45. ## but can be declared for certainty nonetheless:
  46. ## * add a exec_depend tag for "message_runtime"
  47. ## * In this file (CMakeLists.txt):
  48. ## * add "message_generation" and every package in MSG_DEP_SET to
  49. ## find_package(catkin REQUIRED COMPONENTS ...)
  50. ## * add "message_runtime" and every package in MSG_DEP_SET to
  51. ## catkin_package(CATKIN_DEPENDS ...)
  52. ## * uncomment the add_*_files sections below as needed
  53. ## and list every .msg/.srv/.action file to be processed
  54. ## * uncomment the generate_messages entry below
  55. ## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)
  56. ## Generate messages in the 'msg' folder
  57. # add_message_files(
  58. # FILES
  59. # Message1.msg
  60. # Message2.msg
  61. # )
  62. ## Generate services in the 'srv' folder
  63. # add_service_files(
  64. # FILES
  65. # Service1.srv
  66. # Service2.srv
  67. # )
  68. ## Generate actions in the 'action' folder
  69. # add_action_files(
  70. # FILES
  71. # Action1.action
  72. # Action2.action
  73. # )
  74. ## Generate added messages and services with any dependencies listed here
  75. # generate_messages(
  76. # DEPENDENCIES
  77. # std_msgs # Or other packages containing msgs
  78. # )
  79. ################################################
  80. ## Declare ROS dynamic reconfigure parameters ##
  81. ################################################
  82. ## To declare and build dynamic reconfigure parameters within this
  83. ## package, follow these steps:
  84. ## * In the file package.xml:
  85. ## * add a build_depend and a exec_depend tag for "dynamic_reconfigure"
  86. ## * In this file (CMakeLists.txt):
  87. ## * add "dynamic_reconfigure" to
  88. ## find_package(catkin REQUIRED COMPONENTS ...)
  89. ## * uncomment the "generate_dynamic_reconfigure_options" section below
  90. ## and list every .cfg file to be processed
  91. ## Generate dynamic reconfigure parameters in the 'cfg' folder
  92. # generate_dynamic_reconfigure_options(
  93. # cfg/DynReconf1.cfg
  94. # cfg/DynReconf2.cfg
  95. # )
  96. ###################################
  97. ## catkin specific configuration ##
  98. ###################################
  99. ## The catkin_package macro generates cmake config files for your package
  100. ## Declare things to be passed to dependent projects
  101. ## INCLUDE_DIRS: uncomment this if your package contains header files
  102. ## LIBRARIES: libraries you create in this project that dependent projects also need
  103. ## CATKIN_DEPENDS: catkin_packages dependent projects also need
  104. ## DEPENDS: system dependencies of this project that dependent projects also need
  105. catkin_package(
  106. # INCLUDE_DIRS include
  107. # LIBRARIES visualOrientation
  108. # CATKIN_DEPENDS roscpp rosmsg rospy
  109. # DEPENDS system_lib
  110. )
  111. ###########
  112. ## Build ##
  113. ###########
  114. ## Specify additional locations of header files
  115. ## Your package locations should be listed before other locations
  116. include_directories(
  117. # include
  118. ${catkin_INCLUDE_DIRS}
  119. )
  120. include_directories(/usr/include/eigen3)
  121. #include_directories(${OpenCV_INCLUDE_DIRS})
  122. ## Declare a C++ library
  123. # add_library(${PROJECT_NAME}
  124. # src/${PROJECT_NAME}/visualOrientation.cpp
  125. # )
  126. ## Add cmake target dependencies of the library
  127. ## as an example, code may need to be generated before libraries
  128. ## either from message generation or dynamic reconfigure
  129. # add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
  130. ## Declare a C++ executable
  131. ## With catkin_make all packages are built within a single CMake context
  132. ## The recommended prefix ensures that target names across packages don't collide
  133. add_executable(main_node src/main.cpp)
  134. add_executable(CameraIntrinsicFromFiles_node src/CameraIntrinsicFromFiles.cpp)
  135. add_executable(QRcodeOrlentationCalibration_node src/QRcodeOrlentationCalibration.cpp)
  136. add_executable(saveImgeAndCarPose src/saveImgeAndCarPose.cpp)
  137. ## Rename C++ executable without prefix
  138. ## The above recommended prefix causes long target names, the following renames the
  139. ## target back to the shorter version for ease of user use
  140. ## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
  141. # set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")
  142. ## Add cmake target dependencies of the executable
  143. ## same as for the library above
  144. # add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
  145. ## Specify libraries to link a library or executable target against
  146. target_link_libraries(
  147. main_node
  148. ${catkin_LIBRARIES}
  149. ${OpenCV_LIBS}
  150. )
  151. target_link_libraries(
  152. CameraIntrinsicFromFiles_node
  153. ${catkin_LIBRARIES}
  154. )
  155. target_link_libraries(
  156. QRcodeOrlentationCalibration_node
  157. ${catkin_LIBRARIES}
  158. )
  159. target_link_libraries(
  160. saveImgeAndCarPose
  161. ${catkin_LIBRARIES}
  162. )
  163. #link_directories(${OpenCV_LIBRARY_DIRS})
  164. #############
  165. ## Install ##
  166. #############
  167. # all install targets should use catkin DESTINATION variables
  168. # See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html
  169. ## Mark executable scripts (Python etc.) for installation
  170. ## in contrast to setup.py, you can choose the destination
  171. # catkin_install_python(PROGRAMS
  172. # scripts/my_python_script
  173. # DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
  174. # )
  175. ## Mark executables for installation
  176. ## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html
  177. # install(TARGETS ${PROJECT_NAME}_node
  178. # RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
  179. # )
  180. ## Mark libraries for installation
  181. ## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html
  182. # install(TARGETS ${PROJECT_NAME}
  183. # ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  184. # LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  185. # RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
  186. # )
  187. ## Mark cpp header files for installation
  188. # install(DIRECTORY include/${PROJECT_NAME}/
  189. # DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
  190. # FILES_MATCHING PATTERN "*.h"
  191. # PATTERN ".svn" EXCLUDE
  192. # )
  193. ## Mark other files for installation (e.g. launch and bag files, etc.)
  194. # install(FILES
  195. # # myfile1
  196. # # myfile2
  197. # DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
  198. # )
  199. #############
  200. ## Testing ##
  201. #############
  202. ## Add gtest based cpp test target and link libraries
  203. # catkin_add_gtest(${PROJECT_NAME}-test test/test_visualOrientation.cpp)
  204. # if(TARGET ${PROJECT_NAME}-test)
  205. # target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
  206. # endif()
  207. ## Add folders to be run by python nosetests
  208. # catkin_add_nosetests(test)

ros中配置第三方opencv

  1. cmake_minimum_required(VERSION 3.0.2)
  2. project(demour)
  3. ## Compile as C++11, supported in ROS Kinetic and newer
  4. # add_compile_options(-std=c++11)
  5. ## Find catkin macros and libraries
  6. ## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
  7. ## is used, also find other catkin packages
  8. find_package(catkin REQUIRED COMPONENTS
  9. roscpp
  10. rosmsg
  11. rospy
  12. diagnostic_msgs
  13. )
  14. find_package(OpenCV REQUIRED)
  15. set(CMAKE_INCLUDE_CURRENT_DIR ON)
  16. set(CMAKE_AUTOMOC ON)
  17. find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport Network)
  18. ## System dependencies are found with CMake's conventions
  19. # find_package(Boost REQUIRED COMPONENTS system)
  20. ## Uncomment this if the package has a setup.py. This macro ensures
  21. ## modules and global scripts declared therein get installed
  22. ## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
  23. # catkin_python_setup()
  24. ################################################
  25. ## Declare ROS messages, services and actions ##
  26. ################################################
  27. ## To declare and build messages, services or actions from within this
  28. ## package, follow these steps:
  29. ## * Let MSG_DEP_SET be the set of packages whose message types you use in
  30. ## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
  31. ## * In the file package.xml:
  32. ## * add a build_depend tag for "message_generation"
  33. ## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET
  34. ## * If MSG_DEP_SET isn't empty the following dependency has been pulled in
  35. ## but can be declared for certainty nonetheless:
  36. ## * add a exec_depend tag for "message_runtime"
  37. ## * In this file (CMakeLists.txt):
  38. ## * add "message_generation" and every package in MSG_DEP_SET to
  39. ## find_package(catkin REQUIRED COMPONENTS ...)
  40. ## * add "message_runtime" and every package in MSG_DEP_SET to
  41. ## catkin_package(CATKIN_DEPENDS ...)
  42. ## * uncomment the add_*_files sections below as needed
  43. ## and list every .msg/.srv/.action file to be processed
  44. ## * uncomment the generate_messages entry below
  45. ## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)
  46. ## Generate messages in the 'msg' folder
  47. # add_message_files(
  48. # FILES
  49. # Message1.msg
  50. # Message2.msg
  51. # )
  52. ## Generate services in the 'srv' folder
  53. # add_service_files(
  54. # FILES
  55. # Service1.srv
  56. # Service2.srv
  57. # )
  58. ## Generate actions in the 'action' folder
  59. # add_action_files(
  60. # FILES
  61. # Action1.action
  62. # Action2.action
  63. # )
  64. ## Generate added messages and services with any dependencies listed here
  65. # generate_messages(
  66. # DEPENDENCIES
  67. # std_msgs # Or other packages containing msgs
  68. # )
  69. ################################################
  70. ## Declare ROS dynamic reconfigure parameters ##
  71. ################################################
  72. ## To declare and build dynamic reconfigure parameters within this
  73. ## package, follow these steps:
  74. ## * In the file package.xml:
  75. ## * add a build_depend and a exec_depend tag for "dynamic_reconfigure"
  76. ## * In this file (CMakeLists.txt):
  77. ## * add "dynamic_reconfigure" to
  78. ## find_package(catkin REQUIRED COMPONENTS ...)
  79. ## * uncomment the "generate_dynamic_reconfigure_options" section below
  80. ## and list every .cfg file to be processed
  81. ## Generate dynamic reconfigure parameters in the 'cfg' folder
  82. # generate_dynamic_reconfigure_options(
  83. # cfg/DynReconf1.cfg
  84. # cfg/DynReconf2.cfg
  85. # )
  86. ###################################
  87. ## catkin specific configuration ##
  88. ###################################
  89. ## The catkin_package macro generates cmake config files for your package
  90. ## Declare things to be passed to dependent projects
  91. ## INCLUDE_DIRS: uncomment this if your package contains header files
  92. ## LIBRARIES: libraries you create in this project that dependent projects also need
  93. ## CATKIN_DEPENDS: catkin_packages dependent projects also need
  94. ## DEPENDS: system dependencies of this project that dependent projects also need
  95. catkin_package(
  96. # INCLUDE_DIRS include
  97. # LIBRARIES demour
  98. # CATKIN_DEPENDS roscpp rosmsg rospy
  99. # DEPENDS system_lib
  100. )
  101. ###########
  102. ## Build ##
  103. ###########
  104. ## Specify additional locations of header files
  105. ## Your package locations should be listed before other locations
  106. include_directories(
  107. # include
  108. ${catkin_INCLUDE_DIRS}
  109. )
  110. ## Declare a C++ library
  111. # add_library(${PROJECT_NAME}
  112. # src/${PROJECT_NAME}/demour.cpp
  113. # )
  114. ## Add cmake target dependencies of the library
  115. ## as an example, code may need to be generated before libraries
  116. ## either from message generation or dynamic reconfigure
  117. # add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
  118. ## Declare a C++ executable
  119. ## With catkin_make all packages are built within a single CMake context
  120. ## The recommended prefix ensures that target names across packages don't collide
  121. add_subdirectory(src/driver)
  122. #add_executable(ur_cpp_node src/ur_cpp.cpp src/PaintWidget.cpp src/Type.cpp src/urwWritWindow.cpp)
  123. add_executable(ur_cpp_node src/ur_cpp.cpp)
  124. ## Rename C++ executable without prefix
  125. ## The above recommended prefix causes long target names, the following renames the
  126. ## target back to the shorter version for ease of user use
  127. ## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
  128. # set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")
  129. ## Add cmake target dependencies of the executable
  130. ## same as for the library above
  131. # add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
  132. ## Specify libraries to link a library or executable target against
  133. #target_link_libraries(
  134. # ur_cpp_node
  135. # ${catkin_LIBRARIES}
  136. # ${OpenCV_LIBS}
  137. # driver
  138. #)
  139. target_link_libraries(
  140. ur_cpp_node
  141. ${catkin_LIBRARIES}
  142. ${OpenCV_LIBS}
  143. driver
  144. )
  145. #############
  146. ## Install ##
  147. #############
  148. # all install targets should use catkin DESTINATION variables
  149. # See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html
  150. ## Mark executable scripts (Python etc.) for installation
  151. ## in contrast to setup.py, you can choose the destination
  152. # catkin_install_python(PROGRAMS
  153. # scripts/my_python_script
  154. # DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
  155. # )
  156. ## Mark executables for installation
  157. ## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html
  158. # install(TARGETS ${PROJECT_NAME}_node
  159. # RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
  160. # )
  161. ## Mark libraries for installation
  162. ## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html
  163. # install(TARGETS ${PROJECT_NAME}
  164. # ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  165. # LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
  166. # RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
  167. # )
  168. ## Mark cpp header files for installation
  169. # install(DIRECTORY include/${PROJECT_NAME}/
  170. # DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
  171. # FILES_MATCHING PATTERN "*.h"
  172. # PATTERN ".svn" EXCLUDE
  173. # )
  174. ## Mark other files for installation (e.g. launch and bag files, etc.)
  175. # install(FILES
  176. # # myfile1
  177. # # myfile2
  178. # DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
  179. # )
  180. #############
  181. ## Testing ##
  182. #############
  183. ## Add gtest based cpp test target and link libraries
  184. # catkin_add_gtest(${PROJECT_NAME}-test test/test_demour.cpp)
  185. # if(TARGET ${PROJECT_NAME}-test)
  186. # target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
  187. # endif()
  188. ## Add folders to be run by python nosetests
  189. # catkin_add_nosetests(test)

3.ros中更换第三方opencv库

配置文件地址为:/opt/ros/melodic/share/cv_bridge/cmake/cv_bridgeConfig.cmake

将119行注释(可以在vim中按:输入set number显示行号)或者直接在里面修改,结果如下

注意:set(libraries “ 后面把所有库都加进去)

cmakelist.txt按第一个写

  1. # generated from catkin/cmake/template/pkgConfig.cmake.in
  2. # append elements to a list and remove existing duplicates from the list
  3. # copied from catkin/cmake/list_append_deduplicate.cmake to keep pkgConfig
  4. # self contained
  5. macro(_list_append_deduplicate listname)
  6. if(NOT "${ARGN}" STREQUAL "")
  7. if(${listname})
  8. list(REMOVE_ITEM ${listname} ${ARGN})
  9. endif()
  10. list(APPEND ${listname} ${ARGN})
  11. endif()
  12. endmacro()
  13. # append elements to a list if they are not already in the list
  14. # copied from catkin/cmake/list_append_unique.cmake to keep pkgConfig
  15. # self contained
  16. macro(_list_append_unique listname)
  17. foreach(_item ${ARGN})
  18. list(FIND ${listname} ${_item} _index)
  19. if(_index EQUAL -1)
  20. list(APPEND ${listname} ${_item})
  21. endif()
  22. endforeach()
  23. endmacro()
  24. # pack a list of libraries with optional build configuration keywords
  25. # copied from catkin/cmake/catkin_libraries.cmake to keep pkgConfig
  26. # self contained
  27. macro(_pack_libraries_with_build_configuration VAR)
  28. set(${VAR} "")
  29. set(_argn ${ARGN})
  30. list(LENGTH _argn _count)
  31. set(_index 0)
  32. while(${_index} LESS ${_count})
  33. list(GET _argn ${_index} lib)
  34. if("${lib}" MATCHES "^(debug|optimized|general)$")
  35. math(EXPR _index "${_index} + 1")
  36. if(${_index} EQUAL ${_count})
  37. message(FATAL_ERROR "_pack_libraries_with_build_configuration() the list of libraries '${ARGN}' ends with '${lib}' which is a build configuration keyword and must be followed by a library")
  38. endif()
  39. list(GET _argn ${_index} library)
  40. list(APPEND ${VAR} "${lib}${CATKIN_BUILD_CONFIGURATION_KEYWORD_SEPARATOR}${library}")
  41. else()
  42. list(APPEND ${VAR} "${lib}")
  43. endif()
  44. math(EXPR _index "${_index} + 1")
  45. endwhile()
  46. endmacro()
  47. # unpack a list of libraries with optional build configuration keyword prefixes
  48. # copied from catkin/cmake/catkin_libraries.cmake to keep pkgConfig
  49. # self contained
  50. macro(_unpack_libraries_with_build_configuration VAR)
  51. set(${VAR} "")
  52. foreach(lib ${ARGN})
  53. string(REGEX REPLACE "^(debug|optimized|general)${CATKIN_BUILD_CONFIGURATION_KEYWORD_SEPARATOR}(.+)$" "\\1;\\2" lib "${lib}")
  54. list(APPEND ${VAR} "${lib}")
  55. endforeach()
  56. endmacro()
  57. if(cv_bridge_CONFIG_INCLUDED)
  58. return()
  59. endif()
  60. set(cv_bridge_CONFIG_INCLUDED TRUE)
  61. # set variables for source/devel/install prefixes
  62. if("FALSE" STREQUAL "TRUE")
  63. set(cv_bridge_SOURCE_PREFIX /tmp/binarydeb/ros-kinetic-cv-bridge-1.12.8)
  64. set(cv_bridge_DEVEL_PREFIX /tmp/binarydeb/ros-kinetic-cv-bridge-1.12.8/obj-x86_64-linux-gnu/devel)
  65. set(cv_bridge_INSTALL_PREFIX "")
  66. set(cv_bridge_PREFIX ${cv_bridge_DEVEL_PREFIX})
  67. else()
  68. set(cv_bridge_SOURCE_PREFIX "")
  69. set(cv_bridge_DEVEL_PREFIX "")
  70. set(cv_bridge_INSTALL_PREFIX /opt/ros/kinetic)
  71. set(cv_bridge_PREFIX ${cv_bridge_INSTALL_PREFIX})
  72. endif()
  73. # warn when using a deprecated package
  74. if(NOT "" STREQUAL "")
  75. set(_msg "WARNING: package 'cv_bridge' is deprecated")
  76. # append custom deprecation text if available
  77. if(NOT "" STREQUAL "TRUE")
  78. set(_msg "${_msg} ()")
  79. endif()
  80. message("${_msg}")
  81. endif()
  82. # flag project as catkin-based to distinguish if a find_package()-ed project is a catkin project
  83. set(cv_bridge_FOUND_CATKIN_PROJECT TRUE)
  84. ##susususu
  85. #if(NOT "include;/opt/ros/kinetic/include/opencv-3.3.1-dev;/opt/ros/kinetic/include/opencv-3.3.1-dev/opencv " STREQUAL " ")
  86. if(NOT "include;/home/iimt/3rdparty/OpenCV-3.4.9/include " STREQUAL " ")
  87. set(cv_bridge_INCLUDE_DIRS "")
  88. ##susususu
  89. #set(_include_dirs "include;/opt/ros/kinetic/include/opencv-3.3.1-dev;/opt/ros/kinetic/include/opencv-3.3.1-dev/opencv")
  90. set(_include_dirs "include;/home/iimt/3rdparty/OpenCV-3.4.9/include")
  91. if(NOT "https://github.com/ros-perception/vision_opencv/issues " STREQUAL " ")
  92. set(_report "Check the issue tracker 'https://github.com/ros-perception/vision_opencv/issues' and consider creating a ticket if the problem has not been reported yet.")
  93. elseif(NOT "http://www.ros.org/wiki/cv_bridge " STREQUAL " ")
  94. set(_report "Check the website 'http://www.ros.org/wiki/cv_bridge' for information and consider reporting the problem.")
  95. else()
  96. set(_report "Report the problem to the maintainer 'Vincent Rabaud <vincent.rabaud@gmail.com>' and request to fix the problem.")
  97. endif()
  98. foreach(idir ${_include_dirs})
  99. if(IS_ABSOLUTE ${idir} AND IS_DIRECTORY ${idir})
  100. set(include ${idir})
  101. elseif("${idir} " STREQUAL "include ")
  102. get_filename_component(include "${cv_bridge_DIR}/../../../include" ABSOLUTE)
  103. if(NOT IS_DIRECTORY ${include})
  104. message(FATAL_ERROR "Project 'cv_bridge' specifies '${idir}' as an include dir, which is not found. It does not exist in '${include}'. ${_report}")
  105. endif()
  106. else()
  107. message(FATAL_ERROR "Project 'cv_bridge' specifies '${idir}' as an include dir, which is not found. It does neither exist as an absolute directory nor in '\${prefix}/${idir}'. ${_report}")
  108. endif()
  109. _list_append_unique(cv_bridge_INCLUDE_DIRS ${include})
  110. endforeach()
  111. endif()
  112. ##susususu
  113. #set(libraries "cv_bridge;/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_core3.so.3.3.1;/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgproc3.so.3.3.1;/opt/ros/kinetic/lib/x86_64-linux-gnu/libopencv_imgcodecs3.so.3.3.1")
  114. #set(libraries "cv_bridge;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_core.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_imgproc.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_imgcodecs.so.3.4.9")
  115. set(libraries "cv_bridge;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_aruco.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_aruco.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_aruco.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_bgsegm.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_bgsegm.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_bgsegm.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_bioinspired.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_bioinspired.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_bioinspired.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_calib3d.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_calib3d.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_calib3d.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_ccalib.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_ccalib.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_ccalib.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_core.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_core.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_core.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_datasets.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_datasets.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_datasets.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_dnn.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_dnn.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_dnn.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_dnn_objdetect.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_dnn_objdetect.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_dnn_objdetect.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_dpm.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_dpm.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_dpm.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_face.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_face.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_face.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_features2d.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_features2d.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_features2d.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_flann.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_flann.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_flann.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_freetype.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_freetype.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_freetype.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_fuzzy.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_fuzzy.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_fuzzy.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_hdf.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_hdf.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_hdf.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_hfs.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_hfs.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_hfs.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_highgui.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_highgui.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_highgui.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_imgcodecs.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_imgcodecs.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_imgcodecs.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_img_hash.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_img_hash.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_img_hash.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_imgproc.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_imgproc.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_imgproc.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_line_descriptor.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_line_descriptor.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_line_descriptor.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_ml.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_ml.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_ml.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_objdetect.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_objdetect.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_objdetect.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_optflow.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_optflow.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_optflow.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_phase_unwrapping.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_phase_unwrapping.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_phase_unwrapping.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_photo.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_photo.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_photo.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_plot.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_plot.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_plot.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_reg.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_reg.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_reg.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_rgbd.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_rgbd.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_rgbd.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_saliency.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_saliency.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_saliency.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_sfm.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_sfm.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_sfm.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_shape.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_shape.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_shape.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_stereo.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_stereo.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_stereo.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_stitching.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_stitching.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_stitching.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_structured_light.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_structured_light.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_structured_light.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_superres.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_superres.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_superres.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_surface_matching.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_surface_matching.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_surface_matching.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_text.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_text.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_text.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_tracking.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_tracking.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_tracking.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_video.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_video.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_video.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_videoio.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_videoio.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_videoio.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_videostab.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_videostab.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_videostab.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_viz.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_viz.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_viz.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_xfeatures2d.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_xfeatures2d.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_xfeatures2d.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_ximgproc.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_ximgproc.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_ximgproc.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_xobjdetect.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_xobjdetect.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_xobjdetect.so.3.4.9;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_xphoto.so;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_xphoto.so.3.4;/home/iimt/3rdparty/OpenCV-3.4.9/lib/libopencv_xphoto.so.3.4.9")
  116. #set(libraries "cv_bridge;/home/iimt/3rdparty/OpenCV-3.4.9/lib")
  117. foreach(library ${libraries})
  118. # keep build configuration keywords, target names and absolute libraries as-is
  119. if("${library}" MATCHES "^(debug|optimized|general)$")
  120. list(APPEND cv_bridge_LIBRARIES ${library})
  121. elseif(${library} MATCHES "^-l")
  122. list(APPEND cv_bridge_LIBRARIES ${library})
  123. elseif(${library} MATCHES "^-")
  124. # This is a linker flag/option (like -pthread)
  125. # There's no standard variable for these, so create an interface library to hold it
  126. if(NOT cv_bridge_NUM_DUMMY_TARGETS)
  127. set(cv_bridge_NUM_DUMMY_TARGETS 0)
  128. endif()
  129. # Make sure the target name is unique
  130. set(interface_target_name "catkin::cv_bridge::wrapped-linker-option${cv_bridge_NUM_DUMMY_TARGETS}")
  131. while(TARGET "${interface_target_name}")
  132. math(EXPR cv_bridge_NUM_DUMMY_TARGETS "${cv_bridge_NUM_DUMMY_TARGETS}+1")
  133. set(interface_target_name "catkin::cv_bridge::wrapped-linker-option${cv_bridge_NUM_DUMMY_TARGETS}")
  134. endwhile()
  135. add_library("${interface_target_name}" INTERFACE IMPORTED)
  136. if("${CMAKE_VERSION}" VERSION_LESS "3.13.0")
  137. set_property(
  138. TARGET
  139. "${interface_target_name}"
  140. APPEND PROPERTY
  141. INTERFACE_LINK_LIBRARIES "${library}")
  142. else()
  143. target_link_options("${interface_target_name}" INTERFACE "${library}")
  144. endif()
  145. list(APPEND cv_bridge_LIBRARIES "${interface_target_name}")
  146. elseif(TARGET ${library})
  147. list(APPEND cv_bridge_LIBRARIES ${library})
  148. elseif(IS_ABSOLUTE ${library})
  149. list(APPEND cv_bridge_LIBRARIES ${library})
  150. else()
  151. set(lib_path "")
  152. set(lib "${library}-NOTFOUND")
  153. # since the path where the library is found is returned we have to iterate over the paths manually
  154. foreach(path /opt/ros/kinetic/lib;/opt/ros/kinetic/lib)
  155. find_library(lib ${library}
  156. PATHS ${path}
  157. NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
  158. if(lib)
  159. set(lib_path ${path})
  160. break()
  161. endif()
  162. endforeach()
  163. if(lib)
  164. _list_append_unique(cv_bridge_LIBRARY_DIRS ${lib_path})
  165. list(APPEND cv_bridge_LIBRARIES ${lib})
  166. else()
  167. # as a fall back for non-catkin libraries try to search globally
  168. find_library(lib ${library})
  169. if(NOT lib)
  170. message(FATAL_ERROR "Project '${PROJECT_NAME}' tried to find library '${library}'. The library is neither a target nor built/installed properly. Did you compile project 'cv_bridge'? Did you find_package() it before the subdirectory containing its code is included?")
  171. endif()
  172. list(APPEND cv_bridge_LIBRARIES ${lib})
  173. endif()
  174. endif()
  175. endforeach()
  176. set(cv_bridge_EXPORTED_TARGETS "")
  177. # create dummy targets for exported code generation targets to make life of users easier
  178. foreach(t ${cv_bridge_EXPORTED_TARGETS})
  179. if(NOT TARGET ${t})
  180. add_custom_target(${t})
  181. endif()
  182. endforeach()
  183. set(depends "rosconsole;sensor_msgs")
  184. foreach(depend ${depends})
  185. string(REPLACE " " ";" depend_list ${depend})
  186. # the package name of the dependency must be kept in a unique variable so that it is not overwritten in recursive calls
  187. list(GET depend_list 0 cv_bridge_dep)
  188. list(LENGTH depend_list count)
  189. if(${count} EQUAL 1)
  190. # simple dependencies must only be find_package()-ed once
  191. if(NOT ${cv_bridge_dep}_FOUND)
  192. find_package(${cv_bridge_dep} REQUIRED NO_MODULE)
  193. endif()
  194. else()
  195. # dependencies with components must be find_package()-ed again
  196. list(REMOVE_AT depend_list 0)
  197. find_package(${cv_bridge_dep} REQUIRED NO_MODULE ${depend_list})
  198. endif()
  199. _list_append_unique(cv_bridge_INCLUDE_DIRS ${${cv_bridge_dep}_INCLUDE_DIRS})
  200. # merge build configuration keywords with library names to correctly deduplicate
  201. _pack_libraries_with_build_configuration(cv_bridge_LIBRARIES ${cv_bridge_LIBRARIES})
  202. _pack_libraries_with_build_configuration(_libraries ${${cv_bridge_dep}_LIBRARIES})
  203. _list_append_deduplicate(cv_bridge_LIBRARIES ${_libraries})
  204. # undo build configuration keyword merging after deduplication
  205. _unpack_libraries_with_build_configuration(cv_bridge_LIBRARIES ${cv_bridge_LIBRARIES})
  206. _list_append_unique(cv_bridge_LIBRARY_DIRS ${${cv_bridge_dep}_LIBRARY_DIRS})
  207. list(APPEND cv_bridge_EXPORTED_TARGETS ${${cv_bridge_dep}_EXPORTED_TARGETS})
  208. endforeach()
  209. set(pkg_cfg_extras "cv_bridge-extras.cmake")
  210. foreach(extra ${pkg_cfg_extras})
  211. if(NOT IS_ABSOLUTE ${extra})
  212. set(extra ${cv_bridge_DIR}/${extra})
  213. endif()
  214. include(${extra})
  215. endforeach()

编译opencv-3.4.9

编译安装OpenCV依赖库

编译安装OpenCV环境

准备源码

  1. # 编译工具
  2. sudo apt-get install build-essential
  3. # 必须的
  4. sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
  5. sudo apt-get install libeigen3-dev libgflags-dev libgoogle-glog-dev
  6. sudo apt-get install libsuitesparse-dev
  7. # 可选的
  8. sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
  9. sudo apt-get install gtk-3.0-dev
  10. sudo apt-get install libatlas-base-dev gfortran
  11. # 创建一个总目录存放两个子目录
  12. mkdir -p ~/3rdparty/source/opencv_env
  13. cd ~/3rdparty/source/opencv_env
  14. # 如果网络好就直接执行命令 , 总共700MB
  15. git clone -b 3.4 https://gitee.com/mirrors/opencv.git
  16. git clone -b 3.4 https://gitee.com/mirrors/opencv_contrib.git
  17. # 或者直接使用资料中下好的文件, 将这两个文件拷贝到opencv_env路径下
  18. opencv-3.4.9.zip
  19. opencv_contrib-3.4.9.tar.gz
  20. # 使用tar -zxvf xxx.tar.gz 将上述两个文件进行解压

准备编译依赖的文件

修改hosts文件

打开此链接:https://githubusercontent.com.ipaddress.com/raw.githubusercontent.com

将其中显示的IP Address地址复制到粘贴板,这里为199.232.96.133

image-20201118151707815

编辑系统的hosts文件:

  1. sudo gedit /etc/hosts

把以下内容追加到末尾即可:

  1. 199.232.96.133 raw.githubusercontent.com

注意,这里用到的ip地址是我在网站链接中获取的,可能与你获得的不同,注意区分,直接复制使用不保证有效!

提前释放要下载的内容到.cache目录

建议在直接将cache.tar.gz内容解压缩到opencv源码根目录下的.cache,即可避免由于需要在线下载会出现的问题。原因是执行cmake时候,脚本会自动到github的资源库raw.githubusercontent.com下载文件,而这个网站时不时的就被河蟹了(科学上网可以解决,但不是人人都有梯子的),所以这里提前把脚本要下载的准备到opencv源码根目录里的.cache里即可。注意此cache目前在opencv-3.4.9情况下可用,其他版本不保证。

cache.tar.gz的百度网盘链接: https://pan.baidu.com/s/1kZU1gakKLP-LjSxQ4DYw7g 提取码: 5fxk

然后执行以下命令,将其内容解压到opencv的源码根目录

  1. tar -zxvf cache.tar.gz -C opencv

此时,进入opencv目录,确认是否有.cache目录即可,注意这个是隐藏目录,文件浏览器里按 Ctrl+H 可以查看隐藏目录,命令行里可以输入ls -al查看

配置&编译&安装

  1. # 进入Opencv目录
  2. cd opencv-3.4.9
  3. # 创建一个build目录
  4. mkdir build
  5. # 进入build目录
  6. cd build
  7. # cmake编译配置:也可以自行使用cmake-gui配置
  8. # 一定要确保以下用到的OPENCV_EXTRA_MODULES_PATH参数路径在你那里是存在且正确的!!!
  9. # 注意末尾的两个点 .. 不能少,注意最后一个参数要根据你自己的路径来
  10. cmake -D CMAKE_BUILD_TYPE=Release \
  11. -D BUILD_opencv_python2=OFF \
  12. -D BUILD_opencv_python3=ON \
  13. -D CMAKE_INSTALL_PREFIX=/usr/local \
  14. -D OPENCV_EXTRA_MODULES_PATH=~/3rdparty/source/opencv_env/opencv_contrib-3.4.9/modules ..
  15. # 或者用这个,可以编译安装一些Python和C++案例
  16. cmake -D CMAKE_BUILD_TYPE=Release \
  17. -D BUILD_opencv_python2=OFF \
  18. -D BUILD_opencv_python3=ON \
  19. -D CMAKE_INSTALL_PREFIX=/usr/local \
  20. -D INSTALL_PYTHON_EXAMPLES=ON \
  21. -D OPENCV_EXTRA_MODULES_PATH=~/3rdparty/source/opencv_env/opencv_contrib-3.4.9/modules \
  22. -D BUILD_EXAMPLES=ON ..
  23. # 或者指定任意输出目录,例如我把OpenCV输出到 ~/3rdparty/OpenCV-3.4.9
  24. cmake -D CMAKE_BUILD_TYPE=Release \
  25. -D BUILD_opencv_python2=OFF \
  26. -D BUILD_opencv_python3=ON \
  27. -D CMAKE_INSTALL_PREFIX=~/3rdparty/OpenCV-3.4.9 \
  28. -D INSTALL_PYTHON_EXAMPLES=ON \
  29. -D OPENCV_EXTRA_MODULES_PATH=~/3rdparty/source/opencv_env/opencv_contrib-3.4.9/modules \
  30. -D BUILD_EXAMPLES=ON ..
  31. # 开启8个线程
  32. make -j8
  33. # 编译成功之后, 再执行安装
  34. # 这里会安装到刚刚CMAKE_INSTALL_PREFIX指定的路径,如果时使用的~/开头的用户目录,建议不要加sudo
  35. sudo make install

正常情况下,编译安装即到此完毕!

出现的问题

!!!!!!!!!!如果.cache目录已按照上述步骤自行解压过,则以下步骤可以省略!!!!!!!!!!!!!!!

  • ippicv

由于是外国服务器原因,这里极大概率会出现下载错误,会提示ippicv_2019_lnx_intel64_general_20180723.tgz 下载失败!!解决方式如下

方式1:推荐

ippicv_2019_lnx_intel64_general_20180723.tgz拷贝为opencv/.cache/ippicv/c0bd78adb4156bbf552c1dfe90599607-ippicv_2019_lnx_intel64_general_20180723.tgz即可

方式2:

  1. # 打开终端,输入
  2. gedit ~/opencv_env/opencv/3rdparty/ippicv/ippicv.cmake #就是这个文件的路径
  3. # 将47行的
  4. "https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_COMMIT}ippicv/"
  5. # 改为步骤1中手动下载的文件的本地路径(也就是将网络下载的模式改为本地文件下载的模式):
  6. "file:///home/itheima/opencv_env/" #(仅供参考,根据自己的路径填写,ippicv所在的目录)
  • face_landmark_model.dat

cmake过程中会到https://raw.githubusercontent.com/opencv/opencv_3rdparty/8afa57abc8229d611c4937165d20e2a2d9fc5a12/face_landmark_model.dat下载dat文件,这里提前准备好,就不需要联网下啦,进入opencv源码根目录,执行:

  1. mkdir -p .cache/data
  2. cp face_landmark_model.dat .cache/data/7505c44ca4eb54b4ab1e4777cb96ac05-face_landmark_model.dat
  • opencv boostdesc_bgm.i

opencv boostdesc_bgm.i: No such file or directory

查看下载失败的文件

  1. opencv/build$ cat CMakeDownloadLog.txt

直接自行下载到指定目录,或将一下文件拷贝到指定目录

Clion中添加依赖参考

修改Cmake配置文件

  1. cmake_minimum_required(VERSION 3.14)
  2. project(study_opencv_cpp)
  3. set(CMAKE_CXX_STANDARD 11)
  4. find_package(OpenCV REQUIRED)
  5. add_executable(main main.cpp)
  6. target_link_libraries(main ${OpenCV_LIBS})

代码测试

Mat类

数据类型定义

  1. CV_位数(S|U|F)C通道数量
  2. 位数:
  3. 8 , 16位, 32 ,64 单通道颜色取值范围是0-255,所以通常是8
  4. S|U|F:
  5. S--代表---signed int---有符号整形
  6. U--代表--unsigned int--无符号整形
  7. F--代表--float---------单精度浮点型
  8. C通道数量:
  9. 通道数量 = 1:灰度图片,单通道图像
  10. 通道数量 = 3:灰度图片,单通道图像
  11. 通道数量 = 4:带Alph通道的RGB图像,png图片是这种

图片基本操作

  1. #include <iostream>
  2. #include <opencv2/opencv.hpp>
  3. using namespace std;
  4. using namespace cv;
  5. int main(){
  6. Mat img = imread("../assets/lena.jpg",IMREAD_COLOR);
  7. cout<<"read img success!";
  8. imshow("img",img);
  9. // 获取图片的大小
  10. Size imgSize = img.size();
  11. cout<<"img size:"<<imgSize;
  12. // 获取图片的通道数量
  13. int channels = img.channels();
  14. // 获取数据类型
  15. cout<<"channels:"<<channels<<"type:"<<img.type()<<endl;
  16. // 创建一个图片对象
  17. Mat dst(400,600,CV_8UC3);
  18. // 在图片中间增加一根红色的线
  19. for(int i=0;i<600;i++){
  20. dst.at<Vec3b>(200,i) = Vec3b(0,0,255);
  21. }
  22. namedWindow("dst",WINDOW_NORMAL);
  23. imshow("dst",dst);
  24. waitKey(0);
  25. destroyAllWindows();
  26. return 0;
  27. }

图像剪切

示例代码

  1. #include <iostream>
  2. #include <opencv2/opencv.hpp>
  3. using namespace std;
  4. using namespace cv;
  5. int main(){
  6. Mat img = imread("../assets/itheima.jpg",IMREAD_COLOR);
  7. // 定义要截取的矩形框
  8. Rect rect(100,50,200,200);
  9. // 这样即可完成截取
  10. Mat roi = img(rect);
  11. imshow("src",img);
  12. imshow("roi",roi);
  13. waitKey(0);
  14. destroyAllWindows();
  15. return 0;
  16. }

发表评论

表情:
评论列表 (有 0 条评论,413人围观)

还没有评论,来说两句吧...

相关阅读