ROS opencv image publisher
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