Ubuntu 18.04에서 ROS-melodic 버전이 설치된 환경을 기준으로 opencv 3.4.4를 source에서 빌드하는 방법을 정리하였다.

참조1: https://j-remind.tistory.com/57

참조1: https://www.pyimagesearch.com/2018/05/28/ubuntu-18-04-how-to-install-opencv/

기존에 apt 로 설치한 opencv 3.2 버전을 삭제하기 위해 다음을 수행

sudo apt-get remove libopencv*
sudo apt-get autoremove
sudo find /usr/local/ -name "*opencv*" -exec rm {} \\;

삭제되는 opencv 의존성 ROS 패키지들 목록 (나중에 catkin_ws에서 소스에서 빌드해야한다)

ros-melodic-actionlib-tutorials ros-melodic-bond-core ros-melodic-bondpy
ros-melodic-cmake-modules ros-melodic-common-msgs
ros-melodic-common-tutorials ros-melodic-control-msgs
ros-melodic-control-toolbox ros-melodic-controller-interface
ros-melodic-controller-manager ros-melodic-controller-manager-msgs
ros-melodic-diagnostic-aggregator ros-melodic-diagnostic-analysis
ros-melodic-diagnostic-common-diagnostics ros-melodic-diagnostics
ros-melodic-diff-drive-controller ros-melodic-eigen-conversions
ros-melodic-executive-smach ros-melodic-filters
ros-melodic-forward-command-controller ros-melodic-gazebo-dev
ros-melodic-gazebo-msgs ros-melodic-gazebo-ros
ros-melodic-gazebo-ros-control ros-melodic-geometry
ros-melodic-geometry-tutorials ros-melodic-gl-dependency
ros-melodic-hardware-interface ros-melodic-image-common
ros-melodic-interactive-marker-tutorials ros-melodic-joint-limits-interface
ros-melodic-joint-state-controller ros-melodic-joint-state-publisher
ros-melodic-kdl-conversions ros-melodic-kdl-parser
ros-melodic-kdl-parser-py ros-melodic-laser-assembler
ros-melodic-laser-filters ros-melodic-laser-pipeline
ros-melodic-librviz-tutorial ros-melodic-media-export ros-melodic-mk
ros-melodic-nodelet-core ros-melodic-nodelet-topic-tools
ros-melodic-nodelet-tutorial-math ros-melodic-pcl-conversions
ros-melodic-pcl-msgs ros-melodic-pcl-ros ros-melodic-perception-pcl
ros-melodic-pluginlib-tutorials ros-melodic-polled-camera
ros-melodic-position-controllers ros-melodic-qt-dotgraph
ros-melodic-qt-gui-cpp ros-melodic-qt-gui-py-common
ros-melodic-qwt-dependency ros-melodic-realtime-tools
ros-melodic-resource-retriever ros-melodic-robot
ros-melodic-robot-state-publisher ros-melodic-ros ros-melodic-ros-base
ros-melodic-ros-comm ros-melodic-ros-core ros-melodic-ros-tutorials
ros-melodic-rosbag-migration-rule ros-melodic-rosboost-cfg
ros-melodic-roscpp-core ros-melodic-roscpp-tutorials ros-melodic-roscreate
ros-melodic-roslang ros-melodic-roslint ros-melodic-roslisp
ros-melodic-rosmake ros-melodic-rospy-tutorials ros-melodic-rqt-action
ros-melodic-rqt-bag ros-melodic-rqt-bag-plugins ros-melodic-rqt-console
ros-melodic-rqt-dep ros-melodic-rqt-graph ros-melodic-rqt-gui
ros-melodic-rqt-gui-cpp ros-melodic-rqt-gui-py ros-melodic-rqt-launch
ros-melodic-rqt-logger-level ros-melodic-rqt-moveit ros-melodic-rqt-msg
ros-melodic-rqt-nav-view ros-melodic-rqt-plot ros-melodic-rqt-pose-view
ros-melodic-rqt-publisher ros-melodic-rqt-py-common
ros-melodic-rqt-py-console ros-melodic-rqt-reconfigure
ros-melodic-rqt-robot-dashboard ros-melodic-rqt-robot-monitor
ros-melodic-rqt-robot-plugins ros-melodic-rqt-robot-steering
ros-melodic-rqt-runtime-monitor ros-melodic-rqt-rviz
ros-melodic-rqt-service-caller ros-melodic-rqt-shell ros-melodic-rqt-srv
ros-melodic-rqt-tf-tree ros-melodic-rqt-top ros-melodic-rqt-topic
ros-melodic-rqt-web ros-melodic-rviz ros-melodic-rviz-plugin-tutorials
ros-melodic-rviz-python-tutorial ros-melodic-self-test
ros-melodic-shape-msgs ros-melodic-smach ros-melodic-smach-msgs
ros-melodic-smach-ros ros-melodic-stage ros-melodic-stage-ros
ros-melodic-stereo-msgs ros-melodic-tf-conversions ros-melodic-tf2-eigen
ros-melodic-tf2-kdl ros-melodic-trajectory-msgs
ros-melodic-transmission-interface ros-melodic-turtle-actionlib
ros-melodic-turtle-tf ros-melodic-turtle-tf2 ros-melodic-turtlesim
ros-melodic-urdf-parser-plugin ros-melodic-urdf-sim-tutorial
ros-melodic-urdf-tutorial ros-melodic-urdfdom-py
ros-melodic-visualization-marker-tutorials
ros-melodic-visualization-tutorials ros-melodic-webkit-dependency ruby

catkin_ws 에서 재설치할 ROS 패키지 목록 및 git 주소와 branch 표시

~/catkin_ws/src$ tree -L 1 -d . ├── cmake_modules ├── common_msgs ├── control_msgs ├── control_toolbox ├── gazebo_ros_pkgs ├── geometry2 ├── image_common ├── image_transport_plugins ├── joint_state_publisher ├── kdl_parser ├── object_follower ├── qt_gui_core ├── realtime_tools ├── resource_retriever ├── robot_state_publisher ├── ros_control ├── rqt ├── rqt_image_view ├── rviz └── vision_opencv

$ sudo apt-get install libhdf5-dev $ sudo apt install libprotobuf-dev

cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D WITH_CUDA=OFF \ -D INSTALL_PYTHON_EXAMPLES=ON \ -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.4.4/modules \ -D OPENCV_ENABLE_NONFREE=ON \ -D BUILD_opencv_cudacodec=OFF \ -D BUILD_EXAMPLES=ON ..

core수 확인

$ cat /proc/cpuinfo | grep processor | wc -l