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

53 篇文章 0 订阅
3 篇文章 0 订阅

                                                        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 newer
 add_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 COMPONENTS
  roscpp
  rosmsg
  rospy
        sensor_msgs
        cv_bridge
        image_transport
        tf
)
#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 against
 target_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 COMPONENTS
        roscpp
        rosmsg
        rospy
        diagnostic_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 available
  if(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-is
  if("${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 it
    if(NOT cv_bridge_NUM_DUMMY_TARGETS)
      set(cv_bridge_NUM_DUMMY_TARGETS 0)
    endif()
    # Make sure the target name is unique
    set(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 PROPERTY
        INTERFACE_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 manually
    foreach(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 globally
      find_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 calls
  list(GET depend_list 0 cv_bridge_dep)
  list(LENGTH depend_list count)
  if(${count} EQUAL 1)
    # simple dependencies must only be find_package()-ed once
    if(NOT ${cv_bridge_dep}_FOUND)
      find_package(${cv_bridge_dep} REQUIRED NO_MODULE)
    endif()
  else()
    # dependencies with components must be find_package()-ed again
    list(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-dev

sudo 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

image-20201118151707815

编辑系统的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/data

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

查看下载失败的文件

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;
}

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_无往而不胜_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值