0
$\begingroup$

Rosanswers logo

I run a simple program to continuously publish image to ROS server. I cannot get rid of below error, anyone know the solution please help.

#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <opencv2/highgui/highgui.hpp>
#include <cv_bridge/cv_bridge.h>

int main(int argc, char** argv)
{
  ros::init(argc, argv, "image_publisher");
  ros::NodeHandle nh;

  image_transport::ImageTransport it(nh);
  image_transport::Publisher pub = it.advertise("camera/image", 1);
  cv::Mat image = cv::imread(argv[1], cv::IMREAD_COLOR);
  cv::waitKey(30);
  sensor_msgs::ImagePtr msg = cv_bridge::CvImage(std_msgs::Header(), "bgr8", image).toImageMsg();

 ros::Rate loop_rate(5);
  while (nh.ok()) {
    pub.publish(msg);
    ros::spinOnce();
    loop_rate.sleep();
  }
}

Error:

[ 97%] Built target vtd2ros_generate_messages_lisp
[ 97%] Built target vtd2ros_generate_messages
/usr/bin/ld: cannot find -lopencv_xphoto}
collect2: error: ld returned 1 exit status
make[2]: *** [vtd2ros/CMakeFiles/camera.dir/build.make:207: `/home/robotest/RoboTest/Vu_2/vtd2ros/devel/lib/vtd2ros/camera] Error 1`
make[1]: *** [CMakeFiles/Makefile2:685: vtd2ros/CMakeFiles/camera.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
Invoking "make -j16 -l16" failed

The content of CMakelist.txt

find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs genmsg message_generation cv_bridge image_transport)
find_package( OpenCV REQUIRED )

include_directories(${catkin_INCLUDE_DIRS}
                    ${OpenCV_INCLUDE_DIRS}
                    )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable(camera src/camera.cpp )
add_dependencies(camera ${camera_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
target_link_libraries(camera
   ${catkin_LIBRARIES}
   ${OpenCV_LIBRARIES}}
 )

package.xml

 <buildtool_depend>catkin</buildtool_depend>
  <build_depend>message_generation</build_depend>
  <build_depend>OpenCV</build_depend>
  <build_depend>roscpp</build_depend>
  <exec_depend>message_runtime</exec_depend>
  <exec_depend>OpenCV</exec_depend>
  <exec_depend>roscpp</exec_depend>

OpenCV version 4.2.0

I also install sudo apt-get install ros-noetic-vision-opencv


Originally posted by sgttrieu on ROS Answers with karma: 16 on 2021-06-24

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

The problem is solved. I did not pay attention that I leave a " } " in the target_link_libraries configuration.


Originally posted by sgttrieu with karma: 16 on 2021-06-25

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.