ros加载编译opencv-3.4.9

ros中配置opencv

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

cmake_minimum_required(VERSION 3.0.2)
project(visualOrientation)## Compile as C++11, supported in ROS Kinetic and neweradd_compile_options(-std=c++11)
#set(OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/build)
# 配置依赖目录及程序输出目录
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_DIR}/bin" CACHE PATH "Runtime directory" FORCE)
#set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib" CACHE PATH "Library directory" FORCE)
#set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${OUTPUT_DIR}/lib" CACHE PATH "Archive directory" FORCE)
## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
#set(CMAKE_PREFIX_PATH ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty)
#set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
#set(CMAKE_MODULE_PATH /home/iimt/3rdparty/OpenCV-3.4.9)#set(OpenCV_DIR /home/iimt/3rdparty/OpenCV-3.4.9)find_package(catkin REQUIRED COMPONENTSroscpprosmsgrospysensor_msgscv_bridgeimage_transporttf
)
#cv_bridge
find_package(OpenCV REQUIRED)## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()################################################
## Declare ROS messages, services and actions ##
################################################## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
##   your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
##   * add a build_depend tag for "message_generation"
##   * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET
##   * If MSG_DEP_SET isn't empty the following dependency has been pulled in
##     but can be declared for certainty nonetheless:
##     * add a exec_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
##   * add "message_generation" and every package in MSG_DEP_SET to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * add "message_runtime" and every package in MSG_DEP_SET to
##     catkin_package(CATKIN_DEPENDS ...)
##   * uncomment the add_*_files sections below as needed
##     and list every .msg/.srv/.action file to be processed
##   * uncomment the generate_messages entry below
##   * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)## Generate messages in the 'msg' folder
# add_message_files(
#   FILES
#   Message1.msg
#   Message2.msg
# )## Generate services in the 'srv' folder
# add_service_files(
#   FILES
#   Service1.srv
#   Service2.srv
# )## Generate actions in the 'action' folder
# add_action_files(
#   FILES
#   Action1.action
#   Action2.action
# )## Generate added messages and services with any dependencies listed here
# generate_messages(
#   DEPENDENCIES
#   std_msgs  # Or other packages containing msgs
# )################################################
## Declare ROS dynamic reconfigure parameters ##
################################################## To declare and build dynamic reconfigure parameters within this
## package, follow these steps:
## * In the file package.xml:
##   * add a build_depend and a exec_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
##   * add "dynamic_reconfigure" to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * uncomment the "generate_dynamic_reconfigure_options" section below
##     and list every .cfg file to be processed## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
#   cfg/DynReconf1.cfg
#   cfg/DynReconf2.cfg
# )###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES visualOrientation
#  CATKIN_DEPENDS roscpp rosmsg rospy
#  DEPENDS system_lib
)###########
## Build ##
############# Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
# include${catkin_INCLUDE_DIRS}
)
include_directories(/usr/include/eigen3)
#include_directories(${OpenCV_INCLUDE_DIRS})
## Declare a C++ library
# add_library(${PROJECT_NAME}
#   src/${PROJECT_NAME}/visualOrientation.cpp
# )## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
add_executable(main_node src/main.cpp)
add_executable(CameraIntrinsicFromFiles_node src/CameraIntrinsicFromFiles.cpp)
add_executable(QRcodeOrlentationCalibration_node src/QRcodeOrlentationCalibration.cpp)
add_executable(saveImgeAndCarPose src/saveImgeAndCarPose.cpp)
## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})## Specify libraries to link a library or executable target againsttarget_link_libraries(main_node${catkin_LIBRARIES}${OpenCV_LIBS})
target_link_libraries(CameraIntrinsicFromFiles_node${catkin_LIBRARIES}
)
target_link_libraries(QRcodeOrlentationCalibration_node${catkin_LIBRARIES}
)
target_link_libraries(saveImgeAndCarPose${catkin_LIBRARIES}
)#link_directories(${OpenCV_LIBRARY_DIRS})#############
## Install ##
############## all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# catkin_install_python(PROGRAMS
#   scripts/my_python_script
#   DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )## Mark executables for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html
# install(TARGETS ${PROJECT_NAME}_node
#   RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )## Mark libraries for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html
# install(TARGETS ${PROJECT_NAME}
#   ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
# )## Mark cpp header files for installation
# install(DIRECTORY include/${PROJECT_NAME}/
#   DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
#   FILES_MATCHING PATTERN "*.h"
#   PATTERN ".svn" EXCLUDE
# )## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
#   # myfile1
#   # myfile2
#   DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )#############
## Testing ##
############### Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_visualOrientation.cpp)
# if(TARGET ${PROJECT_NAME}-test)
#   target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()## Add folders to be run by python nosetests
# catkin_add_nosetests(test)

ros中配置第三方opencv

cmake_minimum_required(VERSION 3.0.2)
project(demour)## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTSroscpprosmsgrospydiagnostic_msgs)find_package(OpenCV REQUIRED)set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)find_package(Qt5 COMPONENTS Core Gui Widgets PrintSupport Network)## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()################################################
## Declare ROS messages, services and actions ##
################################################## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
##   your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
##   * add a build_depend tag for "message_generation"
##   * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET
##   * If MSG_DEP_SET isn't empty the following dependency has been pulled in
##     but can be declared for certainty nonetheless:
##     * add a exec_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
##   * add "message_generation" and every package in MSG_DEP_SET to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * add "message_runtime" and every package in MSG_DEP_SET to
##     catkin_package(CATKIN_DEPENDS ...)
##   * uncomment the add_*_files sections below as needed
##     and list every .msg/.srv/.action file to be processed
##   * uncomment the generate_messages entry below
##   * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)## Generate messages in the 'msg' folder
# add_message_files(
#   FILES
#   Message1.msg
#   Message2.msg
# )## Generate services in the 'srv' folder
# add_service_files(
#   FILES
#   Service1.srv
#   Service2.srv
# )## Generate actions in the 'action' folder
# add_action_files(
#   FILES
#   Action1.action
#   Action2.action
# )## Generate added messages and services with any dependencies listed here
# generate_messages(
#   DEPENDENCIES
#   std_msgs  # Or other packages containing msgs
# )################################################
## Declare ROS dynamic reconfigure parameters ##
################################################## To declare and build dynamic reconfigure parameters within this
## package, follow these steps:
## * In the file package.xml:
##   * add a build_depend and a exec_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
##   * add "dynamic_reconfigure" to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * uncomment the "generate_dynamic_reconfigure_options" section below
##     and list every .cfg file to be processed## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
#   cfg/DynReconf1.cfg
#   cfg/DynReconf2.cfg
# )###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(#  INCLUDE_DIRS include#  LIBRARIES demour#  CATKIN_DEPENDS roscpp rosmsg rospy#  DEPENDS system_lib
)###########
## Build ##
############# Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(# include${catkin_INCLUDE_DIRS}
)## Declare a C++ library
# add_library(${PROJECT_NAME}
#   src/${PROJECT_NAME}/demour.cpp
# )## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
add_subdirectory(src/driver)
#add_executable(ur_cpp_node src/ur_cpp.cpp src/PaintWidget.cpp src/Type.cpp src/urwWritWindow.cpp)
add_executable(ur_cpp_node src/ur_cpp.cpp)## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})## Specify libraries to link a library or executable target against#target_link_libraries(
#        ur_cpp_node
#        ${catkin_LIBRARIES}
#        ${OpenCV_LIBS}
#        driver
#)
target_link_libraries(ur_cpp_node${catkin_LIBRARIES}${OpenCV_LIBS}driver
)#############
## Install ##
############## all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# catkin_install_python(PROGRAMS
#   scripts/my_python_script
#   DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )## Mark executables for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html
# install(TARGETS ${PROJECT_NAME}_node
#   RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )## Mark libraries for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html
# install(TARGETS ${PROJECT_NAME}
#   ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
# )## Mark cpp header files for installation
# install(DIRECTORY include/${PROJECT_NAME}/
#   DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
#   FILES_MATCHING PATTERN "*.h"
#   PATTERN ".svn" EXCLUDE
# )## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
#   # myfile1
#   # myfile2
#   DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )#############
## Testing ##
############### Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_demour.cpp)
# if(TARGET ${PROJECT_NAME}-test)
#   target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()## Add folders to be run by python nosetests
# 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按第一个写

# generated from catkin/cmake/template/pkgConfig.cmake.in# append elements to a list and remove existing duplicates from the list
# copied from catkin/cmake/list_append_deduplicate.cmake to keep pkgConfig
# self contained
macro(_list_append_deduplicate listname)if(NOT "${ARGN}" STREQUAL "")if(${listname})list(REMOVE_ITEM ${listname} ${ARGN})endif()list(APPEND ${listname} ${ARGN})endif()
endmacro()# append elements to a list if they are not already in the list
# copied from catkin/cmake/list_append_unique.cmake to keep pkgConfig
# self contained
macro(_list_append_unique listname)foreach(_item ${ARGN})list(FIND ${listname} ${_item} _index)if(_index EQUAL -1)list(APPEND ${listname} ${_item})endif()endforeach()
endmacro()# pack a list of libraries with optional build configuration keywords
# copied from catkin/cmake/catkin_libraries.cmake to keep pkgConfig
# self contained
macro(_pack_libraries_with_build_configuration VAR)set(${VAR} "")set(_argn ${ARGN})list(LENGTH _argn _count)set(_index 0)while(${_index} LESS ${_count})list(GET _argn ${_index} lib)if("${lib}" MATCHES "^(debug|optimized|general)$")math(EXPR _index "${_index} + 1")if(${_index} EQUAL ${_count})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")endif()list(GET _argn ${_index} library)list(APPEND ${VAR} "${lib}${CATKIN_BUILD_CONFIGURATION_KEYWORD_SEPARATOR}${library}")else()list(APPEND ${VAR} "${lib}")endif()math(EXPR _index "${_index} + 1")endwhile()
endmacro()# unpack a list of libraries with optional build configuration keyword prefixes
# copied from catkin/cmake/catkin_libraries.cmake to keep pkgConfig
# self contained
macro(_unpack_libraries_with_build_configuration VAR)set(${VAR} "")foreach(lib ${ARGN})string(REGEX REPLACE "^(debug|optimized|general)${CATKIN_BUILD_CONFIGURATION_KEYWORD_SEPARATOR}(.+)$" "\\1;\\2" lib "${lib}")list(APPEND ${VAR} "${lib}")endforeach()
endmacro()if(cv_bridge_CONFIG_INCLUDED)return()
endif()
set(cv_bridge_CONFIG_INCLUDED TRUE)# set variables for source/devel/install prefixes
if("FALSE" STREQUAL "TRUE")set(cv_bridge_SOURCE_PREFIX /tmp/binarydeb/ros-kinetic-cv-bridge-1.12.8)set(cv_bridge_DEVEL_PREFIX /tmp/binarydeb/ros-kinetic-cv-bridge-1.12.8/obj-x86_64-linux-gnu/devel)set(cv_bridge_INSTALL_PREFIX "")set(cv_bridge_PREFIX ${cv_bridge_DEVEL_PREFIX})
else()set(cv_bridge_SOURCE_PREFIX "")set(cv_bridge_DEVEL_PREFIX "")set(cv_bridge_INSTALL_PREFIX /opt/ros/kinetic)set(cv_bridge_PREFIX ${cv_bridge_INSTALL_PREFIX})
endif()# warn when using a deprecated package
if(NOT "" STREQUAL "")set(_msg "WARNING: package 'cv_bridge' is deprecated")# append custom deprecation text if availableif(NOT "" STREQUAL "TRUE")set(_msg "${_msg} ()")endif()message("${_msg}")
endif()# flag project as catkin-based to distinguish if a find_package()-ed project is a catkin project
set(cv_bridge_FOUND_CATKIN_PROJECT TRUE)
##susususu
#if(NOT "include;/opt/ros/kinetic/include/opencv-3.3.1-dev;/opt/ros/kinetic/include/opencv-3.3.1-dev/opencv " STREQUAL " ")
if(NOT "include;/home/iimt/3rdparty/OpenCV-3.4.9/include " STREQUAL " ")set(cv_bridge_INCLUDE_DIRS "")
##susususu#set(_include_dirs "include;/opt/ros/kinetic/include/opencv-3.3.1-dev;/opt/ros/kinetic/include/opencv-3.3.1-dev/opencv")
set(_include_dirs "include;/home/iimt/3rdparty/OpenCV-3.4.9/include")if(NOT "https://github.com/ros-perception/vision_opencv/issues " STREQUAL " ")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.")elseif(NOT "http://www.ros.org/wiki/cv_bridge " STREQUAL " ")set(_report "Check the website 'http://www.ros.org/wiki/cv_bridge' for information and consider reporting the problem.")else()set(_report "Report the problem to the maintainer 'Vincent Rabaud <vincent.rabaud@gmail.com>' and request to fix the problem.")endif()foreach(idir ${_include_dirs})if(IS_ABSOLUTE ${idir} AND IS_DIRECTORY ${idir})set(include ${idir})elseif("${idir} " STREQUAL "include ")get_filename_component(include "${cv_bridge_DIR}/../../../include" ABSOLUTE)if(NOT IS_DIRECTORY ${include})message(FATAL_ERROR "Project 'cv_bridge' specifies '${idir}' as an include dir, which is not found.  It does not exist in '${include}'.  ${_report}")endif()else()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}")endif()_list_append_unique(cv_bridge_INCLUDE_DIRS ${include})endforeach()
endif()##susususu#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")
#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")
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")
#set(libraries "cv_bridge;/home/iimt/3rdparty/OpenCV-3.4.9/lib")
foreach(library ${libraries})# keep build configuration keywords, target names and absolute libraries as-isif("${library}" MATCHES "^(debug|optimized|general)$")list(APPEND cv_bridge_LIBRARIES ${library})elseif(${library} MATCHES "^-l")list(APPEND cv_bridge_LIBRARIES ${library})elseif(${library} MATCHES "^-")# This is a linker flag/option (like -pthread)# There's no standard variable for these, so create an interface library to hold itif(NOT cv_bridge_NUM_DUMMY_TARGETS)set(cv_bridge_NUM_DUMMY_TARGETS 0)endif()# Make sure the target name is uniqueset(interface_target_name "catkin::cv_bridge::wrapped-linker-option${cv_bridge_NUM_DUMMY_TARGETS}")while(TARGET "${interface_target_name}")math(EXPR cv_bridge_NUM_DUMMY_TARGETS "${cv_bridge_NUM_DUMMY_TARGETS}+1")set(interface_target_name "catkin::cv_bridge::wrapped-linker-option${cv_bridge_NUM_DUMMY_TARGETS}")endwhile()add_library("${interface_target_name}" INTERFACE IMPORTED)if("${CMAKE_VERSION}" VERSION_LESS "3.13.0")set_property(TARGET"${interface_target_name}"APPEND PROPERTYINTERFACE_LINK_LIBRARIES "${library}")else()target_link_options("${interface_target_name}" INTERFACE "${library}")endif()list(APPEND cv_bridge_LIBRARIES "${interface_target_name}")elseif(TARGET ${library})list(APPEND cv_bridge_LIBRARIES ${library})elseif(IS_ABSOLUTE ${library})list(APPEND cv_bridge_LIBRARIES ${library})else()set(lib_path "")set(lib "${library}-NOTFOUND")# since the path where the library is found is returned we have to iterate over the paths manuallyforeach(path /opt/ros/kinetic/lib;/opt/ros/kinetic/lib)find_library(lib ${library}PATHS ${path}NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)if(lib)set(lib_path ${path})break()endif()endforeach()if(lib)_list_append_unique(cv_bridge_LIBRARY_DIRS ${lib_path})list(APPEND cv_bridge_LIBRARIES ${lib})else()# as a fall back for non-catkin libraries try to search globallyfind_library(lib ${library})if(NOT lib)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?")endif()list(APPEND cv_bridge_LIBRARIES ${lib})endif()endif()
endforeach()set(cv_bridge_EXPORTED_TARGETS "")
# create dummy targets for exported code generation targets to make life of users easier
foreach(t ${cv_bridge_EXPORTED_TARGETS})if(NOT TARGET ${t})add_custom_target(${t})endif()
endforeach()set(depends "rosconsole;sensor_msgs")
foreach(depend ${depends})string(REPLACE " " ";" depend_list ${depend})# the package name of the dependency must be kept in a unique variable so that it is not overwritten in recursive callslist(GET depend_list 0 cv_bridge_dep)list(LENGTH depend_list count)if(${count} EQUAL 1)# simple dependencies must only be find_package()-ed onceif(NOT ${cv_bridge_dep}_FOUND)find_package(${cv_bridge_dep} REQUIRED NO_MODULE)endif()else()# dependencies with components must be find_package()-ed againlist(REMOVE_AT depend_list 0)find_package(${cv_bridge_dep} REQUIRED NO_MODULE ${depend_list})endif()_list_append_unique(cv_bridge_INCLUDE_DIRS ${${cv_bridge_dep}_INCLUDE_DIRS})# merge build configuration keywords with library names to correctly deduplicate_pack_libraries_with_build_configuration(cv_bridge_LIBRARIES ${cv_bridge_LIBRARIES})_pack_libraries_with_build_configuration(_libraries ${${cv_bridge_dep}_LIBRARIES})_list_append_deduplicate(cv_bridge_LIBRARIES ${_libraries})# undo build configuration keyword merging after deduplication_unpack_libraries_with_build_configuration(cv_bridge_LIBRARIES ${cv_bridge_LIBRARIES})_list_append_unique(cv_bridge_LIBRARY_DIRS ${${cv_bridge_dep}_LIBRARY_DIRS})list(APPEND cv_bridge_EXPORTED_TARGETS ${${cv_bridge_dep}_EXPORTED_TARGETS})
endforeach()set(pkg_cfg_extras "cv_bridge-extras.cmake")
foreach(extra ${pkg_cfg_extras})if(NOT IS_ABSOLUTE ${extra})set(extra ${cv_bridge_DIR}/${extra})endif()include(${extra})
endforeach()

编译opencv-3.4.9

编译安装OpenCV依赖库

编译安装OpenCV环境

准备源码

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

准备编译依赖的文件

修改hosts文件

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

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

编辑系统的hosts文件:

sudo gedit /etc/hosts

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

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的源码根目录

tar -zxvf cache.tar.gz -C opencv

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

配置&编译&安装

# 进入Opencv目录
cd opencv-3.4.9
# 创建一个build目录
mkdir build
# 进入build目录
cd build# cmake编译配置:也可以自行使用cmake-gui配置# 一定要确保以下用到的OPENCV_EXTRA_MODULES_PATH参数路径在你那里是存在且正确的!!!# 注意末尾的两个点 .. 不能少,注意最后一个参数要根据你自己的路径来
cmake -D CMAKE_BUILD_TYPE=Release \-D BUILD_opencv_python2=OFF \-D BUILD_opencv_python3=ON \-D CMAKE_INSTALL_PREFIX=/usr/local \-D OPENCV_EXTRA_MODULES_PATH=~/3rdparty/source/opencv_env/opencv_contrib-3.4.9/modules ..# 或者用这个,可以编译安装一些Python和C++案例
cmake -D CMAKE_BUILD_TYPE=Release \-D BUILD_opencv_python2=OFF \-D BUILD_opencv_python3=ON \-D CMAKE_INSTALL_PREFIX=/usr/local \-D INSTALL_PYTHON_EXAMPLES=ON \-D OPENCV_EXTRA_MODULES_PATH=~/3rdparty/source/opencv_env/opencv_contrib-3.4.9/modules \-D BUILD_EXAMPLES=ON ..# 或者指定任意输出目录,例如我把OpenCV输出到 ~/3rdparty/OpenCV-3.4.9
cmake -D CMAKE_BUILD_TYPE=Release \-D BUILD_opencv_python2=OFF \-D BUILD_opencv_python3=ON \-D CMAKE_INSTALL_PREFIX=~/3rdparty/OpenCV-3.4.9 \-D INSTALL_PYTHON_EXAMPLES=ON \-D OPENCV_EXTRA_MODULES_PATH=~/3rdparty/source/opencv_env/opencv_contrib-3.4.9/modules \-D BUILD_EXAMPLES=ON ..# 开启8个线程
make -j8# 编译成功之后, 再执行安装
# 这里会安装到刚刚CMAKE_INSTALL_PREFIX指定的路径,如果时使用的~/开头的用户目录,建议不要加sudo
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:

# 打开终端,输入
gedit ~/opencv_env/opencv/3rdparty/ippicv/ippicv.cmake #就是这个文件的路径
# 将47行的
"https://raw.githubusercontent.com/opencv/opencv_3rdparty/${IPPICV_COMMIT}ippicv/"
# 改为步骤1中手动下载的文件的本地路径(也就是将网络下载的模式改为本地文件下载的模式):"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源码根目录,执行:

mkdir -p .cache/datacp face_landmark_model.dat .cache/data/7505c44ca4eb54b4ab1e4777cb96ac05-face_landmark_model.dat
  • opencv boostdesc_bgm.i

opencv boostdesc_bgm.i: No such file or directory

查看下载失败的文件

opencv/build$ cat CMakeDownloadLog.txt

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

Clion中添加依赖参考

修改Cmake配置文件

cmake_minimum_required(VERSION 3.14)
project(study_opencv_cpp)set(CMAKE_CXX_STANDARD 11)find_package(OpenCV REQUIRED)add_executable(main main.cpp)
target_link_libraries(main ${OpenCV_LIBS})

代码测试

Mat类

数据类型定义

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

图片基本操作

#include <iostream>
#include <opencv2/opencv.hpp>using namespace std;
using namespace cv;int main(){Mat img = imread("../assets/lena.jpg",IMREAD_COLOR);cout<<"read img success!";imshow("img",img);// 获取图片的大小Size imgSize = img.size();cout<<"img size:"<<imgSize;// 获取图片的通道数量int channels = img.channels();// 获取数据类型cout<<"channels:"<<channels<<"type:"<<img.type()<<endl;// 创建一个图片对象Mat dst(400,600,CV_8UC3);// 在图片中间增加一根红色的线for(int i=0;i<600;i++){dst.at<Vec3b>(200,i) = Vec3b(0,0,255);}namedWindow("dst",WINDOW_NORMAL);imshow("dst",dst);waitKey(0);destroyAllWindows();return 0;
}

图像剪切

示例代码

#include <iostream>
#include <opencv2/opencv.hpp>using namespace std;
using namespace cv;int main(){Mat img = imread("../assets/itheima.jpg",IMREAD_COLOR);// 定义要截取的矩形框Rect rect(100,50,200,200);// 这样即可完成截取Mat roi = img(rect);imshow("src",img);imshow("roi",roi);waitKey(0);destroyAllWindows();return 0;
}

ros加载编译opencv-3.4.9,编译安装opencv-3.4.9相关推荐

  1. 【java】Eclipse错误: 找不到或无法加载主类或项目无法编译10种解决大法!

    原文地址:Eclipse错误: 找不到或无法加载主类或项目无法编译10种解决大法! 今天启动项目,又遇到找不到或无法加载主类的情况,清除项目后无法编译,class文件下没有.class文件,至少遇到3 ...

  2. 宇视摄像机网页界面登录“提示加载插件失败,点击下载安装最新插件”

    提示加载插件失败,点击下载安装最新插件: 解决方法: 更换浏览器交叉测试:使用IE7以上浏览器登录:清除浏览器缓存,在电脑控制面板卸载原有控件,下载最新控件并安装. 控件卸载: 控制面板--程序--卸 ...

  3. linux内核采取,采用动态加载模块的方式Linux内核编译

    Linux内核是一种单体内核,但是通过动态加载模块的方式,使它的开发非常灵活方便.那么,它是如何编译内核的呢?我们可以通过分析它的Makefile入手.以下是一个简单的hello内核模块的Makefi ...

  4. php拓展so,PHP扩展开发之动态加载so模块与静态重编译PHP(上)-Go语言中文社区...

    动态加载so模块:利用ext_skel工具编译生成so模块,修改php.ini文件,动态加载即可 静态编译:将编写的模块静态编译到PHP,需要重新编译PHP 假设要编写一个my_dynamic扩展,调 ...

  5. confluence创建页面加载缓慢_树莓派4B使用docker安装confluence

    说明 confluence是一个专业的企业知识管理与协同软件,可以用于构建企业wiki.通过它可以实现团队成员之间的协作和知识共享.现在大多数公司都会部署一套confluence,用作内部wiki.另 ...

  6. android加载efi分区,玩转Android-x86(安装启动、个性定制、高级运用)-8.5更新2楼分区挂载代码支持多硬盘...

    玩转Android-x86(安装启动.个性定制.高级运用) 安装篇 本文并不是一篇高大上的教程,只是本人多年来的玩机经验总结,以及在不同系统.不同机型遇到的问题解决备忘录,本着"团结.互助. ...

  7. 【从零学习OpenCV】4Ubuntu系统中安装OpenCV 4

    本文首发于"小白学视觉"微信公众号,欢迎关注公众号 本文作者为小白,版权归人民邮电出版社所有,禁止转载,侵权必究! 经过几个月的努力,小白终于完成了市面上第一本OpenCV 4入门 ...

  8. opencv利用矩形框选中某一区域_【从零学习OpenCV】4Ubuntu系统中安装OpenCV 4

    经过几个月的努力,小白终于完成了市面上第一本OpenCV 4入门书籍<从零学习OpenCV 4>.为了更让小伙伴更早的了解最新版的OpenCV 4,小白与出版社沟通,提前在公众号上连载部分 ...

  9. 【转】【OpenCV入门教程之一】 安装OpenCV:OpenCV 3.0、OpenCV 2.4.8、OpenCV 2.4.9 +VS 开发环境配置

    本系列文章由@浅墨_毛星云 出品,转载请注明出处.   文章链接: http://blog.csdn.net/poem_qianmo/article/details/19809337 作者:毛星云(浅 ...

最新文章

  1. linux 重新分区挂载,Linux:挂载磁盘分区,linux已挂载磁盘重新分区
  2. 解决启动不了VMware虚拟机以及VM升级到新的版本后出现黑屏的问题
  3. i love you 浪漫字体复制_2020高考英语全国I、II、III卷语篇来源!欢迎转发交流!...
  4. Python动态变量名定义与调用
  5. TensorFlow 2.0 快速入门指南 | iBooker·ApacheCN
  6. 实用Python之字符串长度计算
  7. 12月19日绝地求生服务器维护公告,绝地求生12月19日更新到几点 绝地求生正式服更新维护公告...
  8. 一张有转折意义的神秘地图
  9. root android手机型号,兼容支持各种型号手机的Root权限获取方法
  10. php文件苹果用什么软件打开,你知道php文件用什么软件打开吗?
  11. 西瓜视频 iOS 播放器技术重构
  12. MATLAB图像拼接算法及实现(一)
  13. 使用文氏图说明贝叶斯公式如何导出、推导朴素贝叶斯算法以及实例
  14. 数据结构与算法 知识点总结(中)---线性表,堆栈,队列
  15. OPCUA协议: 复杂服务器C语言初步实践(回调与方法)
  16. Libgdx Box2D实战---放开那小球(二:Box2D介绍)
  17. cygwin 安装 ffplay
  18. ctfshow命令执行
  19. 智慧服务型政务平台规划方案(ppt)
  20. 国产数据库产品介绍以及实践

热门文章

  1. pthread库进行多线程编程 - 组件工厂 - C++博客
  2. 浅谈java中的接口
  3. CakePHP中文手册【翻译】-Cake Blog创建指南
  4. 配置Https 和 HSTS
  5. Oracle中的SAVEPOINT
  6. 【NOIP校内模拟】T2 字胡串(分治)
  7. 自制操作系统(五) 保护模式寻址原理、字符鼠标指针显示
  8. java动手动脑 6
  9. 系统安装-黑苹果之路
  10. E: Sub-process /usr/bin/dpkg returned an error code (1)