ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Including Package "image_transport" in ROS2

asked 2022-01-24 14:15:07 -0500

SJeya gravatar image

I have a problem to include the package "image_transport" correctly. This is my CMakeList:


cmake_minimum_required(VERSION 3.5) project(camera_pkg)

Default to C++14

if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 14) endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif()

find_package(ament_cmake REQUIRED COMPONENTS cv_bridge image_transport rclcpp sensor_msgs std_msgs )

find_package(ament_cmake REQUIRED) find_package(rclcpp REQUIRED) find_package(std_msgs REQUIRED) find_package(OpenCV REQUIRED) find_package(sensor_msgs REQUIRED) find_package(cv_bridge REQUIRED)

add_executable(camera camera_pkg.cpp) ament_target_dependencies(camera rclcpp std_msgs OpenCV cv_bridge)

install(TARGETS camera DESTINATION lib/${PROJECT_NAME} )

include_directories( ${OPENCV_INCLUDE_DIRS} ${ament_cmake_INCLUDE_DIRS} )

target_link_libraries(camera ${OPENCV_LIBRARIES})

target_link_libraries(camera ${OPENCV_LIBRARIES} ${ament_cmake_LIBRARIES})

target_link_libraries(camera ${rclcpp_LIBRARIES})

target_link_libraries(camera ${rclcpp_LIBRARIES} ${ament_cmake_LIBRARIES})

target_link_libraries(camera ${sensor_msgs_LIBRARIES})

target_link_libraries(camera ${sensor_msgs_LIBRARIES} ${ament_cmake_LIBRARIES})

target_link_libraries(camera PUBLIC ${EXTRA_LIBS})

if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) ament_lint_auto_find_test_dependencies() endif()

ament_package()


My package.xml looks like this:


<package format="2"> <name>camera_pkg</name> <version>0.13.0</version> <description>Examples of minimal publisher nodes</description> <maintainer <a="" href="mailto:email="sloretz@openrobotics.org"&gt;Shane">email="sloretz@openrobotics.org">Shane Loretz</maintainer> <maintainer <a="" href="mailto:email="aditya.pande@openrobotics.org"&gt;Aditya">email="aditya.pande@openrobotics.org"... Pande</maintainer> <license>Apache License 2.0</license> <author>Mikael Arguedas</author> <author>Morgan Quigley</author> <author <a="" href="mailto:email="jacob@openrobotics.org"&gt;Jacob">email="jacob@openrobotics.org">Jacob Perron</author></package>

<buildtool_depend>ament_cmake</buildtool_depend>

<build_depend>rclcpp</build_depend> <build_depend>std_msgs</build_depend> <build_depend>sensor_msgs</build_depend> <build_depend>OpenCV2</build_depend> <build_depend>image_transport</build_depend> <build_depend>cv_bridge</build_depend>

<exec_depend>rclcpp</exec_depend> <exec_depend>std_msgs</exec_depend> <exec_depend>sensor_msgs</exec_depend> <exec_depend>OpenCV2</exec_depend> <exec_depend>image_transport</exec_depend> <exec_depend>cv_bridge</exec_depend>

<test_depend>ament_lint_auto</test_depend> <test_depend>ament_lint_common</test_depend>

<export> <build_type>ament_cmake</build_type> </export> </package>


When I compile my code with the "colcon build" command I get this error:

undefined reference to `image_transport::create_publisher(rclcpp::Node*, std::__cxx11::basic_string<char, std::char_traits<char="">, std::allocator<char> > const&, rmw_qos_profile_t)'

undefined reference to `image_transport::Publisher::publish(std::shared_ptr<sensor_msgs::msg::image_<std::allocator<void> > const> const&) const'

Can anyone help me what else needs to be added in the CMakeList and in the package.xml ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-02-04 16:09:37 -0500

ChuiV gravatar image

You'll need to add a

find_package(image_transport REQUIRED)

and add a

ament_target_dependencies(camera
    rclcpp
    sensor_msgs
    image_transport)

Note that it's recommended to use the ament_target_dependencies(...) for ros2 packages vs using target_link_libraries(...)

edit flag offensive delete link more

Comments

I have added these lines. But I get a different error now:

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

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

image_transportConfig.cmake
image_transport-config.cmake

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

Do you know where the problem could be ?

SJeya gravatar image SJeya  ( 2022-02-05 07:17:19 -0500 )edit

Is the image transport package installed?

ChuiV gravatar image ChuiV  ( 2022-02-05 07:20:51 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2022-01-24 14:15:07 -0500

Seen: 484 times

Last updated: Feb 04 '22