栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

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

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用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  value or use a ... 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
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/656509.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号