使用ROS-melodic自带的opencv3.2.0 (C++)

Install ROS-melodic

# Setup your sources.list
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

# Set up your keys
sudo apt install curl 
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | sudo apt-key add -

# Installation
sudo apt update
sudo apt install ros-melodic-desktop-full

# Environment setup
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc

# Dependencies for building packages
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
sudo apt install python-rosdep
sudo rosdep init
rosdep update

ROS安装(博主github):
https://github.com/TwilightZrui/Linux-Ubuntu/blob/main/ROS-Melodic.md

查看opencv的安装

opencv查看已有安装

pkg-config --modversion opencv

查找opencv的安装路径

sudo find / -iname "*opencv*"

C++测试代码

#include "opencv2/core.hpp"
#include "iostream"

using namespace cv;
using namespace std;

int main()
{
    cout << "Opencv" << CV_VERSION << endl;
    return 0;
}

CMakeLists:

# cmake needs this line
cmake_minimum_required(VERSION 2.8)
 
# Define project name
project(cv_hw)
 
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
find_package(OpenCV REQUIRED)  
include_directories(${OpenCV_INCLUDE_DIRS}) 
 
# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
 
# Declare the executable target built from your sources
add_executable(cv_hw1 cv_hw1.cpp) 
# Link your application with OpenCV libraries
target_link_libraries(cv_hw1 ${OpenCV_LIBS})

一个报错:

(CVclass) twilight@pc: ~/project/class/cv2021/cv_hw1$ cmake .
CMake Deprecation Warning at CMakeLists.txt:2 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


CMake Error at CMakeLists.txt:10 (find_package):
  By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "OpenCV", but
  CMake did not find one.

  Could not find a package configuration file provided by "OpenCV" with any
  of the following names:

    OpenCVConfig.cmake
    opencv-config.cmake

  Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
  "OpenCV_DIR" to a directory containing one of the above files.  If "OpenCV"
  provides a separate development package or SDK, be sure it has been
  installed.


-- Configuring incomplete, errors occurred!
See also "/home/twilight/project/class/cv2021/cv_hw1/CMakeFiles/CMakeOutput.log".

问题定位:
Cmakelists中没有添加

include_directories(${OpenCV_INCLUDE_DIRS}) 

因此系统找不到OpenCV路径。
当然,前提是在bashrc中添加ROS路径,以证明是使用ROS中自带的opencv3.2.0

source /opt/ros/melodic/setup.bash
  • 1
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值