0.功能作用
(1)绘制简单形状--线,椭圆,圆,多边形,矩形
(2)移动图像窗口
(3)可改写为功能包,给其他程序用
1.构建工作空间
mkdir -p opencv_ws1/src
cd opencv_ws1/src
catkin_create_pkg basic_drawing roscpp rospy cv_bridge std_msgs
2.添加文件并编译运行
(1)官网下载opencv的source版本,这里选择了opencv4.5.3,解压,进入到下述文件夹找到下述文件.
opencv-4.5.3/samples/cpp/tutorial_code/ImgProc/basic_drawing/Drawing_1.cpp
复制文件到"1"中创建工作空间的
/xx/opencv_ws1/src/basic_drawing/src
文件夹下,并改写文件名为:basic_draw_node.cpp
(2)编写CMakeLists.txt文件
找到basic_drawing包的CMakeLists.txt文件,在下述文件夹中
/xx/opencv_ws1/src/basic_drawing
改写如下,其中OpenCV部分为改写的部分,用"##"标记了.
cmake_minimum_required(VERSION 3.0.2)
project(basic_drawing)
find_package(catkin REQUIRED COMPONENTS
cv_bridge
roscpp
rospy
std_msgs
)
find_package(OpenCV REQUIRED)##
catkin_package()
include_directories(
# include
${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS}
)##
add_executable(basic_draw_node src/basic_draw_node.cpp)
target_link_libraries(basic_draw_node
${catkin_LIBRARIES} ${OpenCV_LIBS}
)##
(3)运行
终端回到工作空间文件夹下opencv_ws1,输入下述命令.
catkin_make
source devel/setup.zsh
#####或者source devel/setup.bash
rosrun basic_drawing basic_draw_node
得结果如图:
@meng